Skip to content

Commit

Permalink
fix(color): view screen layout may not update correctly after changin…
Browse files Browse the repository at this point in the history
…g screen setup (EdgeTX#5910)
  • Loading branch information
philmoz authored Feb 15, 2025
1 parent 71c4f7b commit cad12ca
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 53 deletions.
5 changes: 3 additions & 2 deletions radio/src/gui/colorlcd/mainview/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ WidgetsContainer* LayoutFactory::loadLayout(
//
// Detaches and deletes all custom screens
//
void LayoutFactory::deleteCustomScreens()
void LayoutFactory::deleteCustomScreens(bool clearTopBar)
{
for (auto& screen : customScreens) {
if (screen) {
Expand All @@ -67,7 +67,8 @@ void LayoutFactory::deleteCustomScreens()
}
}

ViewMain::instance()->getTopbar()->removeAllWidgets();
if (clearTopBar)
ViewMain::instance()->getTopbar()->removeAllWidgets();
}

void LayoutFactory::loadDefaultLayout()
Expand Down
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/mainview/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class LayoutFactory
static void disposeCustomScreen(unsigned idx);

// delete all custom screens from memory
static void deleteCustomScreens();
static void deleteCustomScreens(bool clearTopBar = false);

// intended for existing models
static void loadCustomScreens();
Expand Down
22 changes: 1 addition & 21 deletions radio/src/gui/colorlcd/mainview/layout_factory_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Layout::Layout(Window* parent, const LayoutFactory* factory,
zoneCount(zoneCount),
zoneMap(zoneMap)
{
adjustLayout();
}

void Layout::setTrimsVisible(bool visible)
Expand All @@ -52,24 +51,6 @@ void Layout::setFlightModeVisible(bool 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)
{
// Set visible decoration
Expand All @@ -86,8 +67,7 @@ void Layout::show(bool visible)
rect_t Layout::getMainZone() const
{
rect_t zone = decoration->getMainZone();
if (decorationSettings &
(DECORATION_SLIDERS | DECORATION_TRIMS | DECORATION_FLIGHTMODE)) {
if (hasSliders() || hasTrims() || hasFlightMode()) {
// some decoration activated
zone.x += MAIN_ZONE_BORDER;
zone.y += MAIN_ZONE_BORDER;
Expand Down
14 changes: 0 additions & 14 deletions radio/src/gui/colorlcd/mainview/layout_factory_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ class Layout: public LayoutBase
void setFlightModeVisible(bool visible);

// Updates settings for trims, sliders, pots, etc...
void adjustLayout() override;
void show(bool visible = true) override;

bool isLayout() override { return true; }
Expand All @@ -119,19 +118,6 @@ class Layout: public LayoutBase
uint8_t zoneCount;
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
uint32_t lastRefresh = 0;

Expand Down
1 change: 0 additions & 1 deletion radio/src/gui/colorlcd/mainview/screen_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,6 @@ void ScreenSetupPage::buildLayoutOptions()
GET_DEFAULT(value->boolValue),
[=](int newValue) {
value->boolValue = newValue;
customScreens[customScreenIndex]->show();
SET_DIRTY();
});
break;
Expand Down
13 changes: 5 additions & 8 deletions radio/src/gui/colorlcd/mainview/view_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
user_data);

view->adjustLayout();
view->show();
}

Expand Down Expand Up @@ -193,7 +192,6 @@ void ViewMain::updateTopbarVisibility()
int view = scrollPos / pageWidth;
setTopbarVisible(hasTopbar(view));
setEdgeTxButtonVisible(hasTopbar(view) || isAppMode(view));
if (customScreens[view]) customScreens[view]->adjustLayout();
} else {
int leftIdx = scrollPos / pageWidth;
bool leftTopbar = hasTopbar(leftIdx);
Expand Down Expand Up @@ -233,9 +231,6 @@ void ViewMain::updateTopbarVisibility()
}

setEdgeTxButtonVisible(ratio);

customScreens[leftIdx]->adjustLayout();
customScreens[leftIdx + 1]->adjustLayout();
}
}

Expand Down Expand Up @@ -377,9 +372,11 @@ void ViewMain::show(bool visible)
int view = getCurrentMainView();
setTopbarVisible(visible && hasTopbar(view));
setEdgeTxButtonVisible(visible && (hasTopbar(view) || isAppMode()));
if (customScreens[view]) {
customScreens[view]->show(visible);
customScreens[view]->showWidgets(visible);
for (int i = 0; i < MAX_CUSTOM_SCREENS; i += 1) {
if (customScreens[i]) {
customScreens[i]->show(visible);
customScreens[i]->showWidgets(visible);
}
}
}

Expand Down
1 change: 0 additions & 1 deletion radio/src/gui/colorlcd/mainview/widgets_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class WidgetsContainer: public Window
virtual Widget * createWidget(unsigned int index, const WidgetFactory * factory) = 0;
virtual Widget * getWidget(unsigned int index) = 0;
virtual void removeWidget(unsigned int index) = 0;
virtual void adjustLayout() = 0;
virtual void updateZones() = 0;
virtual void showWidgets(bool visible = true) = 0;
virtual void hideWidgets() { showWidgets(false); }
Expand Down
3 changes: 0 additions & 3 deletions radio/src/gui/colorlcd/mainview/widgets_container_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class WidgetsContainerImpl : public WidgetsContainer

void updateZones() override
{
adjustLayout();
for (int i = 0; i < N; i++) {
if (widgets[i]) {
auto zone = getZone(i);
Expand All @@ -151,8 +150,6 @@ class WidgetsContainerImpl : public WidgetsContainer
}
}

void adjustLayout() override {}

void runBackground() override
{
for (int i = 0; i < N; i++) {
Expand Down
2 changes: 1 addition & 1 deletion radio/src/storage/sdcard_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ const char * createModel()
storageCheck(true);
#if defined(COLORLCD)
// Default layout loaded when setting model defaults - neeed to remove it.
LayoutFactory::deleteCustomScreens();
LayoutFactory::deleteCustomScreens(true);
#endif
}
postModelLoad(false);
Expand Down
2 changes: 1 addition & 1 deletion radio/src/storage/storage_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ void preModelLoad()

stopTrainer();
#if defined(COLORLCD)
LayoutFactory::deleteCustomScreens();
LayoutFactory::deleteCustomScreens(true);
#endif

if (needDelay)
Expand Down

0 comments on commit cad12ca

Please sign in to comment.