Skip to content

Commit

Permalink
Call widget 'update' function is layout has changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Mitchell committed Jan 25, 2023
1 parent bbef86d commit 60b7393
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
9 changes: 4 additions & 5 deletions radio/src/gui/colorlcd/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,6 @@ void Widget::onCancel()

void Widget::update()
{
auto container = dynamic_cast<WidgetsContainer*>(parent);
if (container) {
container->updateZones();
}
}

void Widget::setFullscreen(bool enable)
Expand All @@ -113,7 +109,10 @@ void Widget::setFullscreen(bool enable)
if (!enable) {

// Reset all zones in container
Widget::update();
auto container = dynamic_cast<WidgetsContainer*>(parent);
if (container)
container->updateZones();

setWindowFlags(getWindowFlags() & ~OPAQUE);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_0, LV_PART_MAIN);

Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/widgets/widgets_container_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class WidgetsContainerImpl : public WidgetsContainer
for (int i = 0; i < N; i++) {
if (widgets[i]) {
auto zone = getZone(i);
widgets[i]->updateZoneRect(zone);
widgets[i]->setRect(zone);
widgets[i]->updateZoneRect(zone);
}
}
}
Expand Down
42 changes: 34 additions & 8 deletions radio/src/lua/lua_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,31 @@ void LuaWidget::update()
}
}

// Update table on top of Lua stack - set entry with name 'idx' to value 'val'
// Return true if value has changed
bool LuaWidget::updateTable(const char* idx, int val)
{
bool update = false;

// Check existing value (or invalid value)
lua_getfield(lsWidgets, -1, idx);
if (lua_isnumber(lsWidgets, -1)) {
int v = lua_tointeger(lsWidgets, -1);
update = (v != val);
} else {
// Force table update
update = true;
}
lua_pop(lsWidgets, 1);

if (update) {
lua_pushinteger(lsWidgets, val);
lua_setfield(lsWidgets, -2, idx);
}

return update;
}

void LuaWidget::updateZoneRect(rect_t rect)
{
if (lsWidgets)
Expand All @@ -299,16 +324,17 @@ void LuaWidget::updateZoneRect(rect_t rect)

lua_rawgeti(lsWidgets, LUA_REGISTRYINDEX, zoneRectDataRef);

lua_pushinteger(lsWidgets, rect.w);
lua_setfield(lsWidgets, -2, "w");
lua_pushinteger(lsWidgets, rect.h);
lua_setfield(lsWidgets, -2, "h");
lua_pushinteger(lsWidgets, rect.x);
lua_setfield(lsWidgets, -2, "xabs");
lua_pushinteger(lsWidgets, rect.y);
lua_setfield(lsWidgets, -2, "yabs");
bool changed = false;

if (updateTable("w", rect.w)) changed = true;
if (updateTable("h", rect.h)) changed = true;
if (updateTable("xabs", rect.x)) changed = true;
if (updateTable("yabs", rect.y)) changed = true;

lua_pop(lsWidgets, 1);

if (changed)
update();
}
}

Expand Down
1 change: 1 addition & 0 deletions radio/src/lua/lua_widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class LuaWidget : public Widget, public LuaEventHandler

// Update 'zone' data
void updateZoneRect(rect_t rect) override;
bool updateTable(const char* idx, int val);

public:
LuaWidget(const WidgetFactory* factory, Window* parent, const rect_t& rect,
Expand Down

0 comments on commit 60b7393

Please sign in to comment.