Singleton ViewMain

This requires https://github.com/opentx/libopenui/pull/10
This commit is contained in:
Raphael Coeffic
2021-04-06 10:20:49 +02:00
parent df86daa867
commit 1335bcf8db
5 changed files with 39 additions and 35 deletions
+2 -2
View File
@@ -78,7 +78,7 @@ void loadDefaultLayout()
strcpy(screenData.layoutName, defaultLayout->getName()); strcpy(screenData.layoutName, defaultLayout->getName());
screen = defaultLayout->create(&screenData.layoutData); screen = defaultLayout->create(&screenData.layoutData);
if (screen) { if (screen) {
screen->attach(ViewMain::instance); screen->attach(ViewMain::instance());
} }
} }
} }
@@ -92,7 +92,7 @@ void loadCustomScreens()
&g_model.screenData[i].layoutData); &g_model.screenData[i].layoutData);
if (screen) { if (screen) {
screen->attach(ViewMain::instance); screen->attach(ViewMain::instance());
} }
} }
} }
+2 -2
View File
@@ -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, back(this, { 0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH }, ICON_BACK,
[=]() -> uint8_t { [=]() -> uint8_t {
parent->deleteLater(); parent->deleteLater();
ViewMain::instance->setFocus((SET_FOCUS_DEFAULT)); ViewMain::instance()->setFocus((SET_FOCUS_DEFAULT));
return 1; return 1;
}, NO_FOCUS), }, NO_FOCUS),
#endif #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)) { else if (event == EVT_KEY_LONG(KEY_EXIT) || event == EVT_KEY_BREAK(KEY_EXIT)) {
killEvents(event); killEvents(event);
ViewMain::instance->setFocus(SET_FOCUS_DEFAULT); ViewMain::instance()->setFocus(SET_FOCUS_DEFAULT);
deleteLater(); deleteLater();
} }
else if (parent) { else if (parent) {
+19 -22
View File
@@ -56,38 +56,35 @@ int getMainViewsCount()
return MAX_CUSTOM_SCREENS; 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 }) FormWindow(MainWindow::instance(), { 0, 0, LCD_W, LCD_H })
{ {
instance = this;
#if defined(HARDWARE_TOUCH) && !defined(HARDWARE_KEYS) #if defined(HARDWARE_TOUCH) && !defined(HARDWARE_KEYS)
if (icons) { new FabButton(this, 50, 100, ICON_MODEL,
new FabButton(this, 50, 100, ICON_MODEL, [=]() -> uint8_t {
[=]() -> uint8_t { new ModelMenu();
new ModelMenu(); return 0;
return 0; });
});
new FabButton(this, LCD_W / 2, 100, ICON_RADIO, new FabButton(this, LCD_W / 2, 100, ICON_RADIO,
[=]() -> uint8_t { [=]() -> uint8_t {
new RadioMenu(); new RadioMenu();
return 0; return 0;
}); });
new FabButton(this, LCD_W - 50, 100, ICON_THEME, new FabButton(this, LCD_W - 50, 100, ICON_THEME,
[=]() -> uint8_t { [=]() -> uint8_t {
new ScreenMenu(); new ScreenMenu();
return 0; return 0;
}); });
}
new IconButton(this, {0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH}, ICON_BACK, new IconButton(this, {0, 0, MENU_HEADER_BUTTON_WIDTH, MENU_HEADER_BUTTON_WIDTH}, ICON_BACK,
[=]() -> uint8_t { [=]() -> uint8_t {
openMenu(); openMenu();
return 0; return 0;
}, NO_FOCUS); }, NO_FOCUS);
#endif #endif
+15 -5
View File
@@ -23,12 +23,22 @@
#include "form.h" #include "form.h"
class ViewMain: public FormWindow { class ViewMain: public FormWindow
public: {
explicit ViewMain(bool icons = true); // singleton
explicit ViewMain();
public:
~ViewMain() override; ~ViewMain() override;
static ViewMain * instance()
{
if (!_instance)
_instance = new ViewMain();
return _instance;
}
#if defined(DEBUG_WINDOWS) #if defined(DEBUG_WINDOWS)
std::string getName() const override std::string getName() const override
{ {
@@ -36,9 +46,9 @@ class ViewMain: public FormWindow {
} }
#endif #endif
static ViewMain * instance;
protected: protected:
static ViewMain * _instance;
#if defined(HARDWARE_KEYS) #if defined(HARDWARE_KEYS)
void onEvent(event_t event) override; void onEvent(event_t event) override;
#endif #endif
+1 -4
View File
@@ -1896,10 +1896,7 @@ void opentxInit()
{ {
TRACE("opentxInit"); TRACE("opentxInit");
#if defined(LIBOPENUI) #if defined(GUI) && !defined(LIBOPENUI)
new MainWindow();
new ViewMain();
#elif defined(GUI)
// TODO add a function for this (duplicated) // TODO add a function for this (duplicated)
menuHandlers[0] = menuMainView; menuHandlers[0] = menuMainView;
#if MENUS_LOCK != 2/*no menus*/ #if MENUS_LOCK != 2/*no menus*/