Skip to content

Commit

Permalink
fix(color): screen / widget setup (#2532)
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 authored Oct 12, 2022
1 parent 5c55524 commit 2f88281
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 34 deletions.
21 changes: 15 additions & 6 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 tabIdx):
TabsGroup(ICON_THEME)
{
updateTabs();
updateTabs(tabIdx);

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

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

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

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

if (tabIdx >= 0) {
tab = tabIdx;
}

auto tabs = getTabs();
if (tab >= tabs - 1) {
tab = tabs - 2;
}
setCurrentTab(tab);
}
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 tabIdx = -1);
void updateTabs(int8_t tabIdx);
};

#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 + 1);
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
5 changes: 4 additions & 1 deletion radio/src/gui/colorlcd/screen_user_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "screen_user_interface.h"
#include "theme_manager.h"
#include "file_preview.h"
#include "menu_screen.h"

struct ThemeDetails : public Window {
ThemeDetails(Window* parent, ThemeFile* theme) : Window(parent, rect_t{})
Expand Down Expand Up @@ -89,6 +90,7 @@ ScreenUserInterfacePage::ScreenUserInterfacePage(ScreenMenu* menu):
menu(menu)
{
}

void ScreenUserInterfacePage::build(FormWindow* form)
{
FlexGridLayout grid(line_col_dsc, line_row_dsc);
Expand All @@ -101,7 +103,8 @@ void ScreenUserInterfacePage::build(FormWindow* form)
auto menu = this->menu;
auto setupTopbarWidgets = new TextButton(line, rect_t{}, STR_SETUP_WIDGETS);
setupTopbarWidgets->setPressHandler([menu]() -> uint8_t {
new SetupTopBarWidgetsPage(menu);
menu->deleteLater();
new SetupTopBarWidgetsPage();
return 0;
});

Expand Down
8 changes: 4 additions & 4 deletions radio/src/gui/colorlcd/topbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Topbar * TopbarFactory::create(Window * parent)
return new TopbarImpl(parent);
}

SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(ScreenMenu* menu):
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage():
FormWindow(ViewMain::instance(), rect_t{}, FORM_FORWARD_FOCUS),
menu(menu)
{
Expand All @@ -45,7 +45,6 @@ SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(ScreenMenu* menu):

// save current view & switch to 1st one
viewMain->setCurrentMainView(0);
viewMain->bringToTop();

// adopt the dimensions of the main view
setRect(viewMain->getRect());
Expand Down Expand Up @@ -79,12 +78,13 @@ void SetupTopBarWidgetsPage::onCancel()

void SetupTopBarWidgetsPage::deleteLater(bool detach, bool trash)
{
// restore screen setting tab on top
menu->bringToTop();
Layer::pop(this);

// and continue async deletion...
FormWindow::deleteLater(detach, trash);

// restore screen setting tab on top
new ScreenMenu(0);

storageDirty(EE_MODEL);
}
2 changes: 1 addition & 1 deletion radio/src/gui/colorlcd/topbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TopbarFactory
class SetupTopBarWidgetsPage : public FormWindow
{
public:
explicit SetupTopBarWidgetsPage(ScreenMenu* menu);
explicit SetupTopBarWidgetsPage();

#if defined(DEBUG_WINDOWS)
std::string getName() const override { return "SetupTopBarWidgetsPage"; }
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 + 1);

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 2f88281

Please sign in to comment.