diff --git a/radio/src/gui/colorlcd/libui/choice.cpp b/radio/src/gui/colorlcd/libui/choice.cpp index 5cf3d1df5..9566b0687 100644 --- a/radio/src/gui/colorlcd/libui/choice.cpp +++ b/radio/src/gui/colorlcd/libui/choice.cpp @@ -150,6 +150,7 @@ void Choice::addValue(const char* value) void Choice::setValues(std::vector values) { + this->values.clear(); this->values = std::move(values); currentValue = INT_MAX; // Force update update(); diff --git a/radio/src/lua/lua_lvgl_widget.cpp b/radio/src/lua/lua_lvgl_widget.cpp index 27364e71f..a2445af28 100644 --- a/radio/src/lua/lua_lvgl_widget.cpp +++ b/radio/src/lua/lua_lvgl_widget.cpp @@ -243,6 +243,7 @@ bool LvglThicknessParam::parseThicknessParam(lua_State *L, const char *key) bool LvglValuesParam::parseValuesParam(lua_State *L, const char *key) { if (!strcmp(key, "values")) { + values.clear(); luaL_checktype(L, -1, LUA_TTABLE); for (lua_pushnil(L); lua_next(L, -2); lua_pop(L, 1)) { values.push_back(lua_tostring(L, -1)); @@ -1579,6 +1580,24 @@ void LvglWidgetSetting::parseParam(lua_State *L, const char *key) LvglWidgetObject::parseParam(L, key); } +void LvglWidgetSetting::setTitle(const char* s) +{ + if (label && title.changedText(s)) + lv_label_set_text(label, title.txt.c_str()); +} + +bool LvglWidgetSetting::callRefs(lua_State *L) +{ + if (!LvglWidgetObject::callRefs(L)) return false; + + if (isVisible()) { + if (!pcallUpdateStringVal(L, title.function, [=](const char* s) { setTitle(s); })) + return false; + } + + return true; +} + void LvglWidgetSetting::clearRefs(lua_State *L) { clearTitleRefs(L); @@ -1590,10 +1609,10 @@ void LvglWidgetSetting::build(lua_State *L) window = new Window(lvglManager->getCurrentParent(), {x, y, w, h}, lv_obj_create); window->padAll(PAD_OUTLINE); - auto lbl = etx_label_create(window->getLvObj()); - lv_obj_align(lbl, LV_ALIGN_LEFT_MID, 0, 0); - etx_txt_color(lbl, COLOR_THEME_PRIMARY1_INDEX); - lv_label_set_text(lbl, title.txt.c_str()); + label = etx_label_create(window->getLvObj()); + lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); + etx_txt_color(label, COLOR_THEME_PRIMARY1_INDEX); + lv_label_set_text(label, title.txt.c_str()); } //----------------------------------------------------------------------------- @@ -2694,7 +2713,7 @@ void LvglWidgetChoice::clearRefs(lua_State *L) void LvglWidgetChoice::build(lua_State *L) { - if (h == LV_SIZE_CONTENT) h = 0; + if (h == LV_SIZE_CONTENT) h = EdgeTxStyles::UI_ELEMENT_HEIGHT; auto c = new Choice( lvglManager->getCurrentParent(), {x, y, w, h}, values, 0, values.size() - 1, [=]() { return pcallGetIntVal(L, getFunction) - 1; }, @@ -2726,6 +2745,14 @@ void LvglWidgetChoice::build(lua_State *L) window = c; } +void LvglWidgetChoice::refresh() +{ + LvglWidgetPicker::refresh(); + Choice* c = (Choice*)window; + c->setValues(values); + c->setMax(values.size() - 1); +} + //----------------------------------------------------------------------------- void LvglWidgetMenu::parseParam(lua_State *L, const char *key) diff --git a/radio/src/lua/lua_lvgl_widget.h b/radio/src/lua/lua_lvgl_widget.h index 370daab67..0d2958cf0 100644 --- a/radio/src/lua/lua_lvgl_widget.h +++ b/radio/src/lua/lua_lvgl_widget.h @@ -532,9 +532,13 @@ class LvglWidgetSetting : public LvglWidgetObject, public LvglTitleParam public: LvglWidgetSetting() : LvglWidgetObject() {} + void setTitle(const char* s); + + bool callRefs(lua_State *L) override; void clearRefs(lua_State *L) override; protected: + lv_obj_t* label = nullptr; void build(lua_State *L) override; void parseParam(lua_State *L, const char *key) override; @@ -973,6 +977,7 @@ class LvglWidgetChoice : public LvglWidgetPicker, public LvglTitleParam, public void build(lua_State *L) override; void parseParam(lua_State *L, const char *key) override; + void refresh() override; }; //-----------------------------------------------------------------------------