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());
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());
}
}
}
+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,
[=]() -> 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) {
+19 -22
View File
@@ -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
+15 -5
View File
@@ -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
+1 -4
View File
@@ -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*/