From d9a0e6957eb8894d2c5e5fbb4a81e4cc423430d2 Mon Sep 17 00:00:00 2001 From: Paul Dempsey Date: Fri, 15 Sep 2023 07:40:34 -0700 Subject: [PATCH] fix TextLabel issues --- src/colors.hpp | 2 +- src/preset_widget.hpp | 2 +- src/text.hpp | 30 +++++++++++++++--------------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/colors.hpp b/src/colors.hpp index 4536d03..36d2edd 100644 --- a/src/colors.hpp +++ b/src/colors.hpp @@ -89,7 +89,7 @@ extern const NVGcolor no_light; extern const NVGcolor preset_name_color; #define IS_SAME_COLOR(p,q) (((p).r == (q).r) && ((p).g == (q).g) && ((p).b == (q).b) && ((p).a == (q).a)) -inline NVGcolor Overlay(NVGcolor color) { return nvgTransRGBAf(color, 0.2f); } +inline NVGcolor Overlay(NVGcolor color, float trans = 0.2f) { return nvgTransRGBAf(color, trans); } inline NVGcolor Gray(float L) { NVGcolor color; color.r = color.b = color.g = L; diff --git a/src/preset_widget.hpp b/src/preset_widget.hpp index 8176aa2..5d28cfd 100644 --- a/src/preset_widget.hpp +++ b/src/preset_widget.hpp @@ -28,7 +28,7 @@ struct PresetWidget : TipWidget addChild(symbol); text_label = createStaticTextLabel(Vec(2.5f, 1.5f), box.size.x - 4.f, "", TextAlignment::Left, 12.f, false); addChild(text_label); - text_code = createStaticTextLabel(Vec(box.size.x - 20, box.size.y - 14.f), 16.f, "", TextAlignment::Right, 9.f, false, GetStockColor(StockColor::pachde_blue_light)); + text_code = createStaticTextLabel(Vec(box.size.x - 20, box.size.y - 12.f), 16.f, "", TextAlignment::Right, 9.f, false, GetStockColor(StockColor::pachde_blue_light)); addChild(text_code); } diff --git a/src/text.hpp b/src/text.hpp index 61669f1..b8d2e2a 100644 --- a/src/text.hpp +++ b/src/text.hpp @@ -52,7 +52,9 @@ struct BasicTextLabel: Widget _bold(true) { } + std::string getText() { return _text; } void setPos(Vec pos) { box.pos = pos; } + void setSize(Vec size) { box.size = size; } void text(std::string text) { _text = text; } void text_height(float height) { _text_height = height; box.size.y = height; } void style(float height, bool bold = true, TextAlignment alignment = TextAlignment::Left) @@ -62,7 +64,6 @@ struct BasicTextLabel: Widget _align = alignment; } void color(const NVGcolor &new_color) { _color = new_color; } - void render(const DrawArgs& args) { if (_text.empty()) return; @@ -103,6 +104,8 @@ struct DynamicTextLabel : BasicTextLabel bool _lazy = false; bool _dirt = false; + void bright(bool lit = true) { _bright = lit; } + std::function _getText; void setFetch(std::function get) { @@ -111,9 +114,6 @@ struct DynamicTextLabel : BasicTextLabel void setLazy() { _dirt = _lazy = true; } - - void bright(bool lit = true) { _bright = lit; } - void modified(bool changed = true) { _dirt = changed; @@ -121,8 +121,8 @@ struct DynamicTextLabel : BasicTextLabel void setText(std::string text) { BasicTextLabel::text(text); + _dirt = true; } - void refresh() { if (_getText) { @@ -132,7 +132,6 @@ struct DynamicTextLabel : BasicTextLabel } } } - void drawLayer(const DrawArgs& args, int layer) override { Widget::drawLayer(args, layer); @@ -140,7 +139,6 @@ struct DynamicTextLabel : BasicTextLabel refresh(); BasicTextLabel::render(args); } - void draw(const DrawArgs& args) override { Widget::draw(args); @@ -181,12 +179,10 @@ struct StaticTextLabel: Widget FramebufferWidget* _fb = nullptr; BasicTextLabel* _label = nullptr; - StaticTextLabel() { + StaticTextLabel() + { _label = new BasicTextLabel(); - box.size.y = _label->box.size.y; _fb = new widget::FramebufferWidget; - _fb->box.pos = Vec(); - _fb->box.size = Vec(150.f, _label->box.size.y); _fb->addChild(_label); addChild(_fb); dirty(); @@ -195,9 +191,10 @@ struct StaticTextLabel: Widget return _label ? _label->_text : ""; } void setPos(Vec pos) { - _fb->box.pos = pos; + box.pos = pos; } void setSize(Vec size) { + box.size = size; _fb->box.size = size; _label->box.size = size; } @@ -225,6 +222,9 @@ struct StaticTextLabel: Widget void draw(const DrawArgs& args) override { Widget::draw(args); +#if defined VISIBLE_STATICTEXTLABEL_BOUNDS + FillRect(args.vg, _fb->box.pos.x, _fb->box.pos.y, _fb->box.size.x, _fb->box.size.y, Overlay(GetStockColor(StockColor::Yellow), .20f)); +#endif } }; @@ -252,7 +252,7 @@ template TWidget* createStaticTextLabel( math::Vec pos, float width, - const char * text, + std::string text, TextAlignment alignment = TextAlignment::Center, float text_height = 12.f, bool bold = true, @@ -262,9 +262,9 @@ TWidget* createStaticTextLabel( TWidget* w = createWidget(pos); w->setSize(Vec(width, text_height)); if (alignment == TextAlignment::Center) { - w->setPos(Vec(w->box.pos.x -= width *.5f, w->box.pos.y)); + w->setPos(Vec(w->box.pos.x - width*.5f, w->box.pos.y)); } - w->text(std::string(text)); + w->text(text); w->style(text_height, bold, alignment); w->color(color); return w;