fix(color): screen / widget setup (#2532)
This fixes the issue introduced in #2509 which would cause the main view to be hidden while configuring widgets.
This commit is contained in:
@@ -25,10 +25,10 @@
|
||||
#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();
|
||||
@@ -36,7 +36,7 @@ ScreenMenu::ScreenMenu():
|
||||
});
|
||||
}
|
||||
|
||||
void ScreenMenu::updateTabs()
|
||||
void ScreenMenu::updateTabs(int8_t tabIdx)
|
||||
{
|
||||
removeAllTabs();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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_
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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{})
|
||||
@@ -89,6 +90,7 @@ ScreenUserInterfacePage::ScreenUserInterfacePage(ScreenMenu* menu):
|
||||
menu(menu)
|
||||
{
|
||||
}
|
||||
|
||||
void ScreenUserInterfacePage::build(FormWindow* form)
|
||||
{
|
||||
FlexGridLayout grid(line_col_dsc, line_row_dsc);
|
||||
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -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());
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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"; }
|
||||
|
||||
@@ -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);
|
||||
@@ -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)
|
||||
@@ -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...
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user