diff --git a/radio/src/gui/colorlcd/layout.cpp b/radio/src/gui/colorlcd/layout.cpp index f48d025eb..c0acde330 100644 --- a/radio/src/gui/colorlcd/layout.cpp +++ b/radio/src/gui/colorlcd/layout.cpp @@ -78,7 +78,7 @@ void loadDefaultLayout() strcpy(screenData.layoutName, defaultLayout->getName()); screen = defaultLayout->create(&screenData.layoutData); if (screen) { - screen->attach(ViewMain::instance); + screen->attach(ViewMain::instance()); } } } @@ -92,7 +92,7 @@ void loadCustomScreens() &g_model.screenData[i].layoutData); if (screen) { - screen->attach(ViewMain::instance); + screen->attach(ViewMain::instance()); } } } diff --git a/radio/src/gui/colorlcd/tabsgroup.cpp b/radio/src/gui/colorlcd/tabsgroup.cpp index 98134ca32..e4e29e7ea 100644 --- a/radio/src/gui/colorlcd/tabsgroup.cpp +++ b/radio/src/gui/colorlcd/tabsgroup.cpp @@ -33,7 +33,7 @@ TabsGroupHeader::TabsGroupHeader(TabsGroup * parent, uint8_t icon): back(this, { 0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH }, ICON_BACK, [=]() -> uint8_t { parent->deleteLater(); - ViewMain::instance->setFocus((SET_FOCUS_DEFAULT)); + ViewMain::instance()->setFocus((SET_FOCUS_DEFAULT)); return 1; }, NO_FOCUS), #endif @@ -160,7 +160,7 @@ void TabsGroup::onEvent(event_t event) } else if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) { killEvents(event); - ViewMain::instance->setFocus(SET_FOCUS_DEFAULT); + ViewMain::instance()->setFocus(SET_FOCUS_DEFAULT); deleteLater(); } else if (parent) { diff --git a/radio/src/gui/colorlcd/view_main.cpp b/radio/src/gui/colorlcd/view_main.cpp index eae31b07d..a8c817951 100644 --- a/radio/src/gui/colorlcd/view_main.cpp +++ b/radio/src/gui/colorlcd/view_main.cpp @@ -56,38 +56,35 @@ int getMainViewsCount() return MAX_CUSTOM_SCREENS; } -ViewMain * ViewMain::instance = nullptr; +ViewMain * ViewMain::_instance = nullptr; -ViewMain::ViewMain(bool icons): +ViewMain::ViewMain(): FormWindow(MainWindow::instance(), { 0, 0, LCD_W, LCD_H }) { - instance = this; #if defined(HARDWARE_TOUCH) && !defined(HARDWARE_KEYS) - if (icons) { - new FabButton(this, 50, 100, ICON_MODEL, - [=]() -> uint8_t { - new ModelMenu(); - return 0; - }); + new FabButton(this, 50, 100, ICON_MODEL, + [=]() -> uint8_t { + new ModelMenu(); + return 0; + }); - new FabButton(this, LCD_W / 2, 100, ICON_RADIO, - [=]() -> uint8_t { - new RadioMenu(); - return 0; - }); + new FabButton(this, LCD_W / 2, 100, ICON_RADIO, + [=]() -> uint8_t { + new RadioMenu(); + return 0; + }); - new FabButton(this, LCD_W - 50, 100, ICON_THEME, - [=]() -> uint8_t { - new ScreenMenu(); - return 0; - }); - } + new FabButton(this, LCD_W - 50, 100, ICON_THEME, + [=]() -> uint8_t { + new ScreenMenu(); + return 0; + }); new IconButton(this, {0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH}, ICON_BACK, [=]() -> uint8_t { - openMenu(); - return 0; + openMenu(); + return 0; }, NO_FOCUS); #endif diff --git a/radio/src/gui/colorlcd/view_main.h b/radio/src/gui/colorlcd/view_main.h index 90a55afe0..69243fa48 100644 --- a/radio/src/gui/colorlcd/view_main.h +++ b/radio/src/gui/colorlcd/view_main.h @@ -23,12 +23,22 @@ #include "form.h" -class ViewMain: public FormWindow { - public: - explicit ViewMain(bool icons = true); +class ViewMain: public FormWindow +{ + // singleton + explicit ViewMain(); + public: ~ViewMain() override; + static ViewMain * instance() + { + if (!_instance) + _instance = new ViewMain(); + + return _instance; + } + #if defined(DEBUG_WINDOWS) std::string getName() const override { @@ -36,9 +46,9 @@ class ViewMain: public FormWindow { } #endif - static ViewMain * instance; - protected: + static ViewMain * _instance; + #if defined(HARDWARE_KEYS) void onEvent(event_t event) override; #endif diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 93ff1d391..c7baa0e61 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1896,10 +1896,7 @@ void opentxInit() { TRACE("opentxInit"); -#if defined(LIBOPENUI) - new MainWindow(); - new ViewMain(); -#elif defined(GUI) +#if defined(GUI) && !defined(LIBOPENUI) // TODO add a function for this (duplicated) menuHandlers[0] = menuMainView; #if MENUS_LOCK != 2/*no menus*/ diff --git a/radio/src/thirdparty/libopenui b/radio/src/thirdparty/libopenui index 2d57320ce..bf5632d53 160000 --- a/radio/src/thirdparty/libopenui +++ b/radio/src/thirdparty/libopenui @@ -1 +1 @@ -Subproject commit 2d57320ce37e1e749357baa278300db776132d41 +Subproject commit bf5632d53b93b9d4cf103a0e5339c0c5486d7392