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 "view_main.h"
|
||||||
#include "storage/storage.h"
|
#include "storage/storage.h"
|
||||||
|
|
||||||
ScreenMenu::ScreenMenu():
|
ScreenMenu::ScreenMenu(int8_t tabIdx):
|
||||||
TabsGroup(ICON_THEME)
|
TabsGroup(ICON_THEME)
|
||||||
{
|
{
|
||||||
updateTabs();
|
updateTabs(tabIdx);
|
||||||
|
|
||||||
setCloseHandler([]{
|
setCloseHandler([]{
|
||||||
ViewMain::instance()->updateTopbarVisibility();
|
ViewMain::instance()->updateTopbarVisibility();
|
||||||
@@ -36,7 +36,7 @@ ScreenMenu::ScreenMenu():
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenMenu::updateTabs()
|
void ScreenMenu::updateTabs(int8_t tabIdx)
|
||||||
{
|
{
|
||||||
removeAllTabs();
|
removeAllTabs();
|
||||||
|
|
||||||
@@ -59,7 +59,16 @@ void ScreenMenu::updateTabs()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set the active tab to the currently shown screen on the MainView
|
// set the active tab to the currently shown screen on the MainView
|
||||||
auto view = ViewMain::instance()->getCurrentMainView();
|
auto viewMain = ViewMain::instance();
|
||||||
if (view + 1 < getTabs())
|
auto tab = viewMain->getCurrentMainView() + 1;
|
||||||
setCurrentTab(view + 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"
|
#include "tabsgroup.h"
|
||||||
|
|
||||||
class ScreenMenu: public TabsGroup {
|
class ScreenMenu : public TabsGroup
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
ScreenMenu();
|
ScreenMenu(int8_t tabIdx = -1);
|
||||||
void updateTabs();
|
void updateTabs(int8_t tabIdx);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _MENU_SCREEN_H_
|
#endif // _MENU_SCREEN_H_
|
||||||
|
|||||||
@@ -170,7 +170,8 @@ static std::function<uint8_t()> startWidgetsSetup(ScreenMenu* menu,
|
|||||||
uint8_t screen_idx)
|
uint8_t screen_idx)
|
||||||
{
|
{
|
||||||
return [=]() -> uint8_t {
|
return [=]() -> uint8_t {
|
||||||
new SetupWidgetsPage(menu, screen_idx);
|
menu->deleteLater();
|
||||||
|
new SetupWidgetsPage(screen_idx);
|
||||||
return 0;
|
return 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -190,17 +191,9 @@ static std::function<uint8_t()> removeScreen(ScreenMenu* menu,
|
|||||||
|
|
||||||
// ... and reload
|
// ... and reload
|
||||||
loadCustomScreens();
|
loadCustomScreens();
|
||||||
menu->updateTabs();
|
|
||||||
|
|
||||||
// Let's try to stay on the same page
|
// Let's try to stay on the same page
|
||||||
// (first tab is "User interface")
|
menu->updateTabs(screen_idx + 1);
|
||||||
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);
|
|
||||||
return 0;
|
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_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_pad_all(obj, 8, LV_PART_MAIN);
|
||||||
lv_obj_set_style_radius(obj, 8, LV_PART_MAIN);
|
lv_obj_set_style_radius(obj, 8, LV_PART_MAIN);
|
||||||
|
lv_group_focus_obj(obj);
|
||||||
|
|
||||||
form->updateSize();
|
form->updateSize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "screen_user_interface.h"
|
#include "screen_user_interface.h"
|
||||||
#include "theme_manager.h"
|
#include "theme_manager.h"
|
||||||
#include "file_preview.h"
|
#include "file_preview.h"
|
||||||
|
#include "menu_screen.h"
|
||||||
|
|
||||||
struct ThemeDetails : public Window {
|
struct ThemeDetails : public Window {
|
||||||
ThemeDetails(Window* parent, ThemeFile* theme) : Window(parent, rect_t{})
|
ThemeDetails(Window* parent, ThemeFile* theme) : Window(parent, rect_t{})
|
||||||
@@ -89,6 +90,7 @@ ScreenUserInterfacePage::ScreenUserInterfacePage(ScreenMenu* menu):
|
|||||||
menu(menu)
|
menu(menu)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenUserInterfacePage::build(FormWindow* form)
|
void ScreenUserInterfacePage::build(FormWindow* form)
|
||||||
{
|
{
|
||||||
FlexGridLayout grid(line_col_dsc, line_row_dsc);
|
FlexGridLayout grid(line_col_dsc, line_row_dsc);
|
||||||
@@ -101,7 +103,8 @@ void ScreenUserInterfacePage::build(FormWindow* form)
|
|||||||
auto menu = this->menu;
|
auto menu = this->menu;
|
||||||
auto setupTopbarWidgets = new TextButton(line, rect_t{}, STR_SETUP_WIDGETS);
|
auto setupTopbarWidgets = new TextButton(line, rect_t{}, STR_SETUP_WIDGETS);
|
||||||
setupTopbarWidgets->setPressHandler([menu]() -> uint8_t {
|
setupTopbarWidgets->setPressHandler([menu]() -> uint8_t {
|
||||||
new SetupTopBarWidgetsPage(menu);
|
menu->deleteLater();
|
||||||
|
new SetupTopBarWidgetsPage();
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ Topbar * TopbarFactory::create(Window * parent)
|
|||||||
return new TopbarImpl(parent);
|
return new TopbarImpl(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(ScreenMenu* menu):
|
SetupTopBarWidgetsPage::SetupTopBarWidgetsPage():
|
||||||
FormWindow(ViewMain::instance(), rect_t{}, FORM_FORWARD_FOCUS),
|
FormWindow(ViewMain::instance(), rect_t{}, FORM_FORWARD_FOCUS),
|
||||||
menu(menu)
|
menu(menu)
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,6 @@ SetupTopBarWidgetsPage::SetupTopBarWidgetsPage(ScreenMenu* menu):
|
|||||||
|
|
||||||
// save current view & switch to 1st one
|
// save current view & switch to 1st one
|
||||||
viewMain->setCurrentMainView(0);
|
viewMain->setCurrentMainView(0);
|
||||||
viewMain->bringToTop();
|
|
||||||
|
|
||||||
// adopt the dimensions of the main view
|
// adopt the dimensions of the main view
|
||||||
setRect(viewMain->getRect());
|
setRect(viewMain->getRect());
|
||||||
@@ -79,12 +78,13 @@ void SetupTopBarWidgetsPage::onCancel()
|
|||||||
|
|
||||||
void SetupTopBarWidgetsPage::deleteLater(bool detach, bool trash)
|
void SetupTopBarWidgetsPage::deleteLater(bool detach, bool trash)
|
||||||
{
|
{
|
||||||
// restore screen setting tab on top
|
|
||||||
menu->bringToTop();
|
|
||||||
Layer::pop(this);
|
Layer::pop(this);
|
||||||
|
|
||||||
// and continue async deletion...
|
// and continue async deletion...
|
||||||
FormWindow::deleteLater(detach, trash);
|
FormWindow::deleteLater(detach, trash);
|
||||||
|
|
||||||
|
// restore screen setting tab on top
|
||||||
|
new ScreenMenu(0);
|
||||||
|
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ class TopbarFactory
|
|||||||
class SetupTopBarWidgetsPage : public FormWindow
|
class SetupTopBarWidgetsPage : public FormWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit SetupTopBarWidgetsPage(ScreenMenu* menu);
|
explicit SetupTopBarWidgetsPage();
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override { return "SetupTopBarWidgetsPage"; }
|
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),
|
FormWindow(ViewMain::instance(), {0, 0, 0, 0}, FORM_FORWARD_FOCUS),
|
||||||
menu(menu),
|
|
||||||
customScreenIdx(customScreenIdx)
|
customScreenIdx(customScreenIdx)
|
||||||
{
|
{
|
||||||
Layer::push(this);
|
Layer::push(this);
|
||||||
@@ -88,13 +87,12 @@ SetupWidgetsPage::SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx) :
|
|||||||
auto viewMain = ViewMain::instance();
|
auto viewMain = ViewMain::instance();
|
||||||
savedView = viewMain->getCurrentMainView();
|
savedView = viewMain->getCurrentMainView();
|
||||||
viewMain->setCurrentMainView(customScreenIdx);
|
viewMain->setCurrentMainView(customScreenIdx);
|
||||||
viewMain->bringToTop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
|
for (unsigned i = 0; i < screen->getZonesCount(); i++) {
|
||||||
auto rect = screen->getZone(i);
|
auto rect = screen->getZone(i);
|
||||||
auto widget_container = customScreens[customScreenIdx];
|
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)
|
#if defined(HARDWARE_TOUCH)
|
||||||
@@ -123,7 +121,6 @@ void SetupWidgetsPage::onCancel()
|
|||||||
void SetupWidgetsPage::deleteLater(bool detach, bool trash)
|
void SetupWidgetsPage::deleteLater(bool detach, bool trash)
|
||||||
{
|
{
|
||||||
// restore screen setting tab on top
|
// restore screen setting tab on top
|
||||||
menu->bringToTop();
|
|
||||||
Layer::pop(this);
|
Layer::pop(this);
|
||||||
|
|
||||||
// and continue async deletion...
|
// and continue async deletion...
|
||||||
@@ -133,6 +130,7 @@ void SetupWidgetsPage::deleteLater(bool detach, bool trash)
|
|||||||
viewMain->setCurrentMainView(savedView);
|
viewMain->setCurrentMainView(savedView);
|
||||||
}
|
}
|
||||||
FormWindow::deleteLater(detach, trash);
|
FormWindow::deleteLater(detach, trash);
|
||||||
|
new ScreenMenu(customScreenIdx + 1);
|
||||||
|
|
||||||
storageDirty(EE_MODEL);
|
storageDirty(EE_MODEL);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ class WidgetsContainer;
|
|||||||
class SetupWidgetsPage : public FormWindow
|
class SetupWidgetsPage : public FormWindow
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SetupWidgetsPage(ScreenMenu* menu, uint8_t customScreenIdx);
|
SetupWidgetsPage(uint8_t customScreenIdx);
|
||||||
|
|
||||||
#if defined(DEBUG_WINDOWS)
|
#if defined(DEBUG_WINDOWS)
|
||||||
std::string getName() const override
|
std::string getName() const override
|
||||||
@@ -44,7 +44,6 @@ class SetupWidgetsPage : public FormWindow
|
|||||||
void deleteLater(bool detach = true, bool trash = true) override;
|
void deleteLater(bool detach = true, bool trash = true) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ScreenMenu* menu;
|
|
||||||
uint8_t customScreenIdx;
|
uint8_t customScreenIdx;
|
||||||
unsigned savedView = 0;
|
unsigned savedView = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user