fix(lua): Store and update the 'zone' rectangle for Lua widgets. (#3060)

* Store 'zone' rectangle dat in Lua registry and update it when the screen layout changes or full screen mode changes. Allows Lua widgets to adjust to layout changes.

* Call widget 'update' function is layout has changed.
This commit is contained in:
philmoz
2023-02-20 11:46:27 +10:00
committed by GitHub
parent c3516b54c1
commit 1df8fe86a8
6 changed files with 73 additions and 9 deletions
+6 -6
View File
@@ -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)
@@ -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);
@@ -135,9 +134,10 @@ void Widget::setFullscreen(bool enable)
// Enter Fullscreen Mode
else {
// Set window opaque (inhibits redraw from windows bellow)
// Set window opaque (inhibits redraw from windows below)
setWindowFlags(getWindowFlags() | OPAQUE);
lv_obj_set_style_bg_opa(lvobj, LV_OPA_MAX, LV_PART_MAIN);
updateZoneRect(parent->getRect());
setRect(parent->getRect());
fullscreen = true;
+3
View File
@@ -106,6 +106,9 @@ class Widget : public Button
// Called at regular time interval, even if the widget cannot be seen
virtual void background() {}
// Update widget 'zone' data (for Lua widgets)
virtual void updateZoneRect(rect_t rect) {}
protected:
const WidgetFactory * factory;
PersistentData * persistentData;
@@ -136,6 +136,7 @@ class WidgetsContainerImpl : public WidgetsContainer
if (widgets[i]) {
auto zone = getZone(i);
widgets[i]->setRect(zone);
widgets[i]->updateZoneRect(zone);
}
}
}