| @@ -16,6 +16,7 @@ struct Label : widget::Widget { | |||||
| std::string text; | std::string text; | ||||
| float fontSize; | float fontSize; | ||||
| float lineHeight; | |||||
| NVGcolor color; | NVGcolor color; | ||||
| Alignment alignment = LEFT_ALIGNMENT; | Alignment alignment = LEFT_ALIGNMENT; | ||||
| @@ -8,6 +8,7 @@ namespace ui { | |||||
| Label::Label() { | Label::Label() { | ||||
| box.size.y = BND_WIDGET_HEIGHT; | box.size.y = BND_WIDGET_HEIGHT; | ||||
| fontSize = 13; | fontSize = 13; | ||||
| lineHeight = 1.2; | |||||
| color = bndGetTheme()->regularTheme.textColor; | color = bndGetTheme()->regularTheme.textColor; | ||||
| } | } | ||||
| @@ -28,6 +29,7 @@ void Label::draw(const DrawArgs& args) { | |||||
| } break; | } 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); | bndIconLabelValue(args.vg, x, 0.0, box.size.x, box.size.y, -1, color, BND_LEFT, fontSize, text.c_str(), NULL); | ||||
| } | } | ||||
| @@ -68,7 +68,9 @@ void TextField::draw(const DrawArgs& args) { | |||||
| int begin = std::min(cursor, selection); | int begin = std::min(cursor, selection); | ||||
| int end = std::max(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); | 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 | // Draw placeholder text | ||||
| if (text.empty()) { | 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); | 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); | ||||
| @@ -9,6 +9,8 @@ namespace ui { | |||||
| void Tooltip::step() { | void Tooltip::step() { | ||||
| // Wrap size to contents | // 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.x = bndLabelWidth(APP->window->vg, -1, text.c_str()) + 10.0; | ||||
| box.size.y = bndLabelHeight(APP->window->vg, -1, text.c_str(), INFINITY); | 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. | // Position near cursor. This assumes that `this` is added to the root widget. | ||||
| @@ -16,12 +18,14 @@ void Tooltip::step() { | |||||
| // Fit inside parent | // Fit inside parent | ||||
| assert(parent); | assert(parent); | ||||
| box = box.nudge(parent->box.zeroPos()); | box = box.nudge(parent->box.zeroPos()); | ||||
| nvgRestore(APP->window->vg); | |||||
| Widget::step(); | Widget::step(); | ||||
| } | } | ||||
| void Tooltip::draw(const DrawArgs& args) { | void Tooltip::draw(const DrawArgs& args) { | ||||
| bndTooltipBackground(args.vg, 0.0, 0.0, box.size.x, box.size.y); | 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()); | bndMenuLabel(args.vg, 0.0, 0.0, box.size.x, box.size.y, -1, text.c_str()); | ||||
| Widget::draw(args); | Widget::draw(args); | ||||
| } | } | ||||
| @@ -385,8 +385,9 @@ void Window::step() { | |||||
| // DEBUG("%.2lf Hz", 1.0 / internal->lastFrameDuration); | // DEBUG("%.2lf Hz", 1.0 / internal->lastFrameDuration); | ||||
| internal->lastFrameTime = frameTime; | 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); | nvgReset(vg); | ||||
| bndSetFont(uiFont->handle); | bndSetFont(uiFont->handle); | ||||
| // Poll events | // Poll events | ||||