Layers are only meant to backup the focus window

This commit is contained in:
Raphael Coeffic
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 684a004f9e
commit 4fc2fc8ae6
3 changed files with 12 additions and 28 deletions
-13
View File
@@ -37,20 +37,12 @@ class Layer
static void push(Window * window) static void push(Window * window)
{ {
if (window->getLvObj()->parent != nullptr) {
TRACE("Layers must have lvgl parent to be null");
}
if (!stack.empty()) { if (!stack.empty()) {
Layer & parentLayer = stack.back(); Layer & parentLayer = stack.back();
parentLayer.focus = Window::getFocus(); parentLayer.focus = Window::getFocus();
} }
// layers are screens in lvgl
lv_obj_set_parent(canvas, window->getLvObj());
lv_obj_move_background(canvas);
lv_scr_load(window->getLvObj());
lv_obj_invalidate(canvas);
stack.emplace_back(Layer(window)); stack.emplace_back(Layer(window));
@@ -67,9 +59,6 @@ class Layer
if (stack.back().main == window) { if (stack.back().main == window) {
stack.pop_back(); stack.pop_back();
const auto & back = stack.back(); const auto & back = stack.back();
lv_obj_set_parent(canvas, back.main->getLvObj());
lv_obj_move_background(canvas);
lv_scr_load(back.main->getLvObj()); // load the screen.
if (back.focus) { if (back.focus) {
back.focus->setFocus(SET_FOCUS_DEFAULT); back.focus->setFocus(SET_FOCUS_DEFAULT);
} }
@@ -78,8 +67,6 @@ class Layer
// TODO it would be better to do it in reverse order // TODO it would be better to do it in reverse order
for (auto it = stack.begin(); it != stack.end(); it++) { for (auto it = stack.begin(); it != stack.end(); it++) {
if (it->main == window) { if (it->main == window) {
lv_obj_set_parent(canvas, it->main->getLvObj());
lv_scr_load(it->main->getLvObj());
stack.erase(it); stack.erase(it);
break; break;
} }
+11 -7
View File
@@ -24,17 +24,21 @@
#include "touch.h" #include "touch.h"
#endif #endif
MainWindow * MainWindow::_instance = nullptr;
LvglWidgetFactory mainWindowFactory = LvglWidgetFactory([] (lv_obj_t *parent) {
return lv_obj_create(nullptr);
});
#if defined(HARDWARE_TOUCH) #if defined(HARDWARE_TOUCH)
TouchState touchState; TouchState touchState;
#endif #endif
static LvglWidgetFactory mainWindowFactory = { lv_obj_create, nullptr };
MainWindow * MainWindow::_instance = nullptr;
MainWindow::MainWindow() :
Window(nullptr, {0, 0, LCD_W, LCD_H}, 0, 0, &mainWindowFactory),
invalidatedRect(rect)
{
Layer::push(this);
}
void MainWindow::emptyTrash() void MainWindow::emptyTrash()
{ {
for (auto window: trash) { for (auto window: trash) {
+1 -8
View File
@@ -23,18 +23,11 @@
#include "layer.h" #include "layer.h"
#include "bitmapbuffer.h" #include "bitmapbuffer.h"
extern LvglWidgetFactory mainWindowFactory;
class MainWindow: public Window class MainWindow: public Window
{ {
protected: protected:
// singleton // singleton
MainWindow(): MainWindow();
Window(nullptr, {0, 0, LCD_W, LCD_H}, 0, 0, &mainWindowFactory),
invalidatedRect(rect)
{
Layer::push(this);
}
public: public:
~MainWindow() override ~MainWindow() override