fix(color): view screen layout may not update correctly after changing screen setup (#5910)

This commit is contained in:
philmoz
2025-02-15 13:49:26 +10:00
committed by GitHub
parent 71c4f7bbf4
commit cad12ca9be
10 changed files with 12 additions and 53 deletions
+3 -2
View File
@@ -58,7 +58,7 @@ WidgetsContainer* LayoutFactory::loadLayout(
// //
// Detaches and deletes all custom screens // Detaches and deletes all custom screens
// //
void LayoutFactory::deleteCustomScreens() void LayoutFactory::deleteCustomScreens(bool clearTopBar)
{ {
for (auto& screen : customScreens) { for (auto& screen : customScreens) {
if (screen) { if (screen) {
@@ -67,7 +67,8 @@ void LayoutFactory::deleteCustomScreens()
} }
} }
ViewMain::instance()->getTopbar()->removeAllWidgets(); if (clearTopBar)
ViewMain::instance()->getTopbar()->removeAllWidgets();
} }
void LayoutFactory::loadDefaultLayout() void LayoutFactory::loadDefaultLayout()
+1 -1
View File
@@ -64,7 +64,7 @@ class LayoutFactory
static void disposeCustomScreen(unsigned idx); static void disposeCustomScreen(unsigned idx);
// delete all custom screens from memory // delete all custom screens from memory
static void deleteCustomScreens(); static void deleteCustomScreens(bool clearTopBar = false);
// intended for existing models // intended for existing models
static void loadCustomScreens(); static void loadCustomScreens();
@@ -34,7 +34,6 @@ Layout::Layout(Window* parent, const LayoutFactory* factory,
zoneCount(zoneCount), zoneCount(zoneCount),
zoneMap(zoneMap) zoneMap(zoneMap)
{ {
adjustLayout();
} }
void Layout::setTrimsVisible(bool visible) void Layout::setTrimsVisible(bool visible)
@@ -52,24 +51,6 @@ void Layout::setFlightModeVisible(bool visible)
decoration->setFlightModeVisible(visible); decoration->setFlightModeVisible(visible);
} }
void Layout::adjustLayout()
{
// Check if deco setting are still up-to-date
uint8_t checkSettings = (hasTopbar() ? DECORATION_TOPBAR : 0) |
(hasSliders() ? DECORATION_SLIDERS : 0) |
(hasTrims() ? DECORATION_TRIMS : 0) |
(hasFlightMode() ? DECORATION_FLIGHTMODE : 0) |
(isMirrored() ? DECORATION_MIRRORED : 0);
if (checkSettings == decorationSettings) {
// everything ok, exit!
return;
}
// Save settings
decorationSettings = checkSettings;
}
void Layout::show(bool visible) void Layout::show(bool visible)
{ {
// Set visible decoration // Set visible decoration
@@ -86,8 +67,7 @@ void Layout::show(bool visible)
rect_t Layout::getMainZone() const rect_t Layout::getMainZone() const
{ {
rect_t zone = decoration->getMainZone(); rect_t zone = decoration->getMainZone();
if (decorationSettings & if (hasSliders() || hasTrims() || hasFlightMode()) {
(DECORATION_SLIDERS | DECORATION_TRIMS | DECORATION_FLIGHTMODE)) {
// some decoration activated // some decoration activated
zone.x += MAIN_ZONE_BORDER; zone.x += MAIN_ZONE_BORDER;
zone.y += MAIN_ZONE_BORDER; zone.y += MAIN_ZONE_BORDER;
@@ -106,7 +106,6 @@ class Layout: public LayoutBase
void setFlightModeVisible(bool visible); void setFlightModeVisible(bool visible);
// Updates settings for trims, sliders, pots, etc... // Updates settings for trims, sliders, pots, etc...
void adjustLayout() override;
void show(bool visible = true) override; void show(bool visible = true) override;
bool isLayout() override { return true; } bool isLayout() override { return true; }
@@ -119,19 +118,6 @@ class Layout: public LayoutBase
uint8_t zoneCount; uint8_t zoneCount;
uint8_t* zoneMap = nullptr; uint8_t* zoneMap = nullptr;
enum DecorationSettings {
DECORATION_NONE = 0x00,
DECORATION_TOPBAR = 0x01,
DECORATION_SLIDERS = 0x02,
DECORATION_TRIMS = 0x04,
DECORATION_FLIGHTMODE = 0x08,
DECORATION_MIRRORED = 0x10,
DECORATION_UNKNOWN = 0xFF
};
// Decoration settings bitmask to detect updates
uint8_t decorationSettings = DECORATION_UNKNOWN;
// Last time we refreshed the window // Last time we refreshed the window
uint32_t lastRefresh = 0; uint32_t lastRefresh = 0;
@@ -342,7 +342,6 @@ void ScreenSetupPage::buildLayoutOptions()
GET_DEFAULT(value->boolValue), GET_DEFAULT(value->boolValue),
[=](int newValue) { [=](int newValue) {
value->boolValue = newValue; value->boolValue = newValue;
customScreens[customScreenIndex]->show();
SET_DIRTY(); SET_DIRTY();
}); });
break; break;
@@ -111,7 +111,6 @@ void ViewMain::addMainView(WidgetsContainer* view, uint32_t viewId)
lv_obj_add_event_cb(tile, tile_view_deleted_cb, LV_EVENT_CHILD_DELETED, lv_obj_add_event_cb(tile, tile_view_deleted_cb, LV_EVENT_CHILD_DELETED,
user_data); user_data);
view->adjustLayout();
view->show(); view->show();
} }
@@ -193,7 +192,6 @@ void ViewMain::updateTopbarVisibility()
int view = scrollPos / pageWidth; int view = scrollPos / pageWidth;
setTopbarVisible(hasTopbar(view)); setTopbarVisible(hasTopbar(view));
setEdgeTxButtonVisible(hasTopbar(view) || isAppMode(view)); setEdgeTxButtonVisible(hasTopbar(view) || isAppMode(view));
if (customScreens[view]) customScreens[view]->adjustLayout();
} else { } else {
int leftIdx = scrollPos / pageWidth; int leftIdx = scrollPos / pageWidth;
bool leftTopbar = hasTopbar(leftIdx); bool leftTopbar = hasTopbar(leftIdx);
@@ -233,9 +231,6 @@ void ViewMain::updateTopbarVisibility()
} }
setEdgeTxButtonVisible(ratio); setEdgeTxButtonVisible(ratio);
customScreens[leftIdx]->adjustLayout();
customScreens[leftIdx + 1]->adjustLayout();
} }
} }
@@ -377,9 +372,11 @@ void ViewMain::show(bool visible)
int view = getCurrentMainView(); int view = getCurrentMainView();
setTopbarVisible(visible && hasTopbar(view)); setTopbarVisible(visible && hasTopbar(view));
setEdgeTxButtonVisible(visible && (hasTopbar(view) || isAppMode())); setEdgeTxButtonVisible(visible && (hasTopbar(view) || isAppMode()));
if (customScreens[view]) { for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
customScreens[view]->show(visible); if (customScreens[i]) {
customScreens[view]->showWidgets(visible); customScreens[i]->show(visible);
customScreens[i]->showWidgets(visible);
}
} }
} }
@@ -79,7 +79,6 @@ class WidgetsContainer: public Window
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0; virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
virtual Widget * getWidget(unsigned int index) = 0; virtual Widget * getWidget(unsigned int index) = 0;
virtual void removeWidget(unsigned int index) = 0; virtual void removeWidget(unsigned int index) = 0;
virtual void adjustLayout() = 0;
virtual void updateZones() = 0; virtual void updateZones() = 0;
virtual void showWidgets(bool visible = true) = 0; virtual void showWidgets(bool visible = true) = 0;
virtual void hideWidgets() { showWidgets(false); } virtual void hideWidgets() { showWidgets(false); }
@@ -132,7 +132,6 @@ class WidgetsContainerImpl : public WidgetsContainer
void updateZones() override void updateZones() override
{ {
adjustLayout();
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
if (widgets[i]) { if (widgets[i]) {
auto zone = getZone(i); auto zone = getZone(i);
@@ -151,8 +150,6 @@ class WidgetsContainerImpl : public WidgetsContainer
} }
} }
void adjustLayout() override {}
void runBackground() override void runBackground() override
{ {
for (int i = 0; i < N; i++) { for (int i = 0; i < N; i++) {
+1 -1
View File
@@ -132,7 +132,7 @@ const char * createModel()
storageCheck(true); storageCheck(true);
#if defined(COLORLCD) #if defined(COLORLCD)
// Default layout loaded when setting model defaults - neeed to remove it. // Default layout loaded when setting model defaults - neeed to remove it.
LayoutFactory::deleteCustomScreens(); LayoutFactory::deleteCustomScreens(true);
#endif #endif
} }
postModelLoad(false); postModelLoad(false);
+1 -1
View File
@@ -73,7 +73,7 @@ void preModelLoad()
stopTrainer(); stopTrainer();
#if defined(COLORLCD) #if defined(COLORLCD)
LayoutFactory::deleteCustomScreens(); LayoutFactory::deleteCustomScreens(true);
#endif #endif
if (needDelay) if (needDelay)