Skip to content

Commit

Permalink
fix(color): screen / widget setup
Browse files Browse the repository at this point in the history
This fixes the issue introduced in #2509 which would cause the main view to be hidden while configuring widgets.
  • Loading branch information
raphaelcoeffic committed Oct 12, 2022
1 parent 6f494e1 commit b1a2392
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
19 changes: 15 additions & 4 deletions radio/src/gui/colorlcd/menu_screen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
#include "view_main.h"
#include "storage/storage.h"

ScreenMenu::ScreenMenu():
ScreenMenu::ScreenMenu(int8_t screenIdx):
TabsGroup(ICON_THEME)
{
updateTabs();
updateTabs(screenIdx);

setCloseHandler([]{
ViewMain::instance()->updateTopbarVisibility();
storageDirty(EE_MODEL);
});
}

void ScreenMenu::updateTabs()
void ScreenMenu::updateTabs(int8_t screenIdx)
{
removeAllTabs();

Expand All @@ -59,7 +59,18 @@ void ScreenMenu::updateTabs()
}

// set the active tab to the currently shown screen on the MainView
auto view = ViewMain::instance()->getCurrentMainView();
auto viewMain = ViewMain::instance();
auto view = viewMain->getCurrentMainView();

if (screenIdx >= 0) {
auto views = viewMain->getMainViewsCount();
if (screenIdx < views) {
view = screenIdx;
} else {
view = views - 1;
}
}

if (view + 1 < getTabs())
setCurrentTab(view + 1);
}
10 changes: 5 additions & 5 deletions radio/src/gui/colorlcd/menu_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@

#include "tabsgroup.h"

class ScreenMenu: public TabsGroup {

public:
ScreenMenu();
void updateTabs();
class ScreenMenu : public TabsGroup
{
public:
ScreenMenu(int8_t screenIdx = -1);
void updateTabs(int8_t screenIdx);
};

#endif // _MENU_SCREEN_H_
14 changes: 4 additions & 10 deletions radio/src/gui/colorlcd/screen_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ static std::function<uint8_t()> startWidgetsSetup(ScreenMenu* menu,
uint8_t screen_idx)
{
return [=]() -> uint8_t {
new SetupWidgetsPage(menu, screen_idx);
menu->deleteLater();
new SetupWidgetsPage(screen_idx);
return 0;
};
}
Expand All @@ -190,17 +191,9 @@ static std::function<uint8_t()> removeScreen(ScreenMenu* menu,

// ... and reload
loadCustomScreens();
menu->updateTabs();

// Let's try to stay on the same page
// (first tab is "User interface")
auto pageIdx = screen_idx + 1;

// Subtract one more as the last one is "New main screen"
if (pageIdx > menu->getTabs() - 2) {
pageIdx = menu->getTabs() - 2;
}
menu->setCurrentTab(pageIdx);
menu->updateTabs(screen_idx);
return 0;
};
}
Expand Down Expand Up @@ -283,6 +276,7 @@ void ScreenSetupPage::build(FormWindow * form)
lv_obj_set_style_min_height(obj, LV_DPI_DEF / 3, LV_PART_MAIN);
lv_obj_set_style_pad_all(obj, 8, LV_PART_MAIN);
lv_obj_set_style_radius(obj, 8, LV_PART_MAIN);
lv_group_focus_obj(obj);

form->updateSize();
}
Expand Down
8 changes: 3 additions & 5 deletions radio/src/gui/colorlcd/widgets_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ void SetupWidgetsPageSlot::paint(BitmapBuffer* dc)
}
}

SetupWidgetsPage::SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx) :
SetupWidgetsPage::SetupWidgetsPage(uint8_t customScreenIdx) :
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS),
menu(menu),
customScreenIdx(customScreenIdx)
{
Layer::push(this);
Expand All @@ -88,13 +87,12 @@ SetupWidgetsPage::SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx) :
auto viewMain = ViewMain::instance();
savedView = viewMain->getCurrentMainView();
viewMain->setCurrentMainView(customScreenIdx);
viewMain->bringToTop();
}

for (unsigned i = 0; i < screen->getZonesCount(); i++) {
auto rect = screen->getZone(i);
auto widget_container = customScreens[customScreenIdx];
auto widget = new SetupWidgetsPageSlot(this, rect, widget_container, i);
new SetupWidgetsPageSlot(this, rect, widget_container, i);
}

#if defined(HARDWARE_TOUCH)
Expand Down Expand Up @@ -123,7 +121,6 @@ void SetupWidgetsPage::onCancel()
void SetupWidgetsPage::deleteLater(bool detach, bool trash)
{
// restore screen setting tab on top
menu->bringToTop();
Layer::pop(this);

// and continue async deletion...
Expand All @@ -133,6 +130,7 @@ void SetupWidgetsPage::deleteLater(bool detach, bool trash)
viewMain->setCurrentMainView(savedView);
}
FormWindow::deleteLater(detach, trash);
new ScreenMenu(customScreenIdx);

storageDirty(EE_MODEL);
}
3 changes: 1 addition & 2 deletions radio/src/gui/colorlcd/widgets_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WidgetsContainer;
class SetupWidgetsPage : public FormWindow
{
public:
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx);
SetupWidgetsPage(uint8_t customScreenIdx);

#if defined(DEBUG_WINDOWS)
std::string getName() const override
Expand All @@ -44,7 +44,6 @@ class SetupWidgetsPage : public FormWindow
void deleteLater(bool detach = true, bool trash = true) override;

protected:
ScreenMenu* menu;
uint8_t customScreenIdx;
unsigned savedView = 0;
};
Expand Down

0 comments on commit b1a2392

Please sign in to comment.