Merge pull request #10 from raphaelcoeffic/mainwindow-singleton

MainWindow is a singleton
This commit is contained in:
Bertrand Songis
2021-04-06 09:17:04 +02:00
committed by GitHub
+6 -2
View File
@@ -25,15 +25,16 @@
class MainWindow: public Window class MainWindow: public Window
{ {
public: // singleton
MainWindow(): MainWindow():
Window(nullptr, {0, 0, LCD_W, LCD_H}), Window(nullptr, {0, 0, LCD_W, LCD_H}),
invalidatedRect(rect) invalidatedRect(rect)
{ {
Layer::push(this); Layer::push(this);
_instance = this;
} }
public:
~MainWindow() override ~MainWindow() override
{ {
children.clear(); children.clear();
@@ -41,6 +42,9 @@ class MainWindow: public Window
static MainWindow * instance() static MainWindow * instance()
{ {
if (!_instance)
_instance = new MainWindow();
return _instance; return _instance;
} }