diff --git a/include/ui/Label.hpp b/include/ui/Label.hpp index 6218e458..49e99025 100644 --- a/include/ui/Label.hpp +++ b/include/ui/Label.hpp @@ -16,6 +16,7 @@ struct Label : widget::Widget { std::string text; float fontSize; + float lineHeight; NVGcolor color; Alignment alignment = LEFT_ALIGNMENT; diff --git a/src/ui/Label.cpp b/src/ui/Label.cpp index a95e1546..7b6e316d 100644 --- a/src/ui/Label.cpp +++ b/src/ui/Label.cpp @@ -8,6 +8,7 @@ namespace ui { Label::Label() { box.size.y = BND_WIDGET_HEIGHT; fontSize = 13; + lineHeight = 1.2; color = bndGetTheme()->regularTheme.textColor; } @@ -28,6 +29,7 @@ void Label::draw(const DrawArgs& args) { } break; } + nvgTextLineHeight(args.vg, lineHeight); bndIconLabelValue(args.vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL); } diff --git a/src/ui/TextField.cpp b/src/ui/TextField.cpp index 004c2ce1..c46eeb10 100644 --- a/src/ui/TextField.cpp +++ b/src/ui/TextField.cpp @@ -68,7 +68,9 @@ void TextField::draw(const DrawArgs& args) { int begin = std::min(cursor, selection); int end = std::max(cursor, selection); + bndTextField(args.vg, 0.0, 0.0, box.size.x, box.size.y, BND_CORNER_NONE, state, -1, text.c_str(), begin, end); + // Draw placeholder text if (text.empty()) { bndIconLabelCaret(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, bndGetTheme()->textFieldTheme.itemColor, 13, placeholder.c_str(), bndGetTheme()->textFieldTheme.itemColor, 0, -1); diff --git a/src/ui/Tooltip.cpp b/src/ui/Tooltip.cpp index 1c1c7500..bec613f1 100644 --- a/src/ui/Tooltip.cpp +++ b/src/ui/Tooltip.cpp @@ -9,6 +9,8 @@ namespace ui { void Tooltip::step() { // Wrap size to contents + nvgSave(APP->window->vg); + nvgTextLineHeight(APP->window->vg, 1.2); box.size.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 10.0; box.size.y = bndLabelHeight(APP->window->vg, -1, text.c_str(), INFINITY); // Position near cursor. This assumes that `this` is added to the root widget. @@ -16,12 +18,14 @@ void Tooltip::step() { // Fit inside parent assert(parent); box = box.nudge(parent->box.zeroPos()); + nvgRestore(APP->window->vg); Widget::step(); } void Tooltip::draw(const DrawArgs& args) { bndTooltipBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y); + nvgTextLineHeight(args.vg, 1.2); bndMenuLabel(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); Widget::draw(args); } diff --git a/src/window.cpp b/src/window.cpp index 65f1b075..ba5235c8 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -385,8 +385,9 @@ void Window::step() { // DEBUG("%.2lf Hz", 1.0 / internal->lastFrameDuration); internal->lastFrameTime = frameTime; - // Make event handlers and step() have a clean nanovg context + // Make event handlers and step() have a clean NanoVG context nvgReset(vg); + bndSetFont(uiFont->handle); // Poll events