Added Layer function (get rid of previous focus functions)
This commit is contained in:
@@ -15,6 +15,7 @@ set(LIBOPENUI_SRC
|
||||
libopenui_file.cpp
|
||||
bitmapbuffer.cpp
|
||||
window.cpp
|
||||
layer.cpp
|
||||
form.cpp
|
||||
button.cpp
|
||||
static.cpp
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "layer.h"
|
||||
|
||||
std::list<Layer> Layer::stack;
|
||||
+65
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Source:
|
||||
* https://github.com/opentx/libopenui
|
||||
*
|
||||
* This file is a part of libopenui library.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "window.h"
|
||||
|
||||
class Layer
|
||||
{
|
||||
public:
|
||||
explicit Layer(Window * main):
|
||||
main(main)
|
||||
{
|
||||
}
|
||||
|
||||
Window * main;
|
||||
Window * focus = nullptr;
|
||||
|
||||
static std::list<Layer> stack;
|
||||
|
||||
static void push(Window * window)
|
||||
{
|
||||
if (!stack.empty()) {
|
||||
Layer &parentLayer = stack.back();
|
||||
parentLayer.focus = Window::getFocus();
|
||||
}
|
||||
stack.emplace_back(Layer(window));
|
||||
}
|
||||
|
||||
static void pop(Window * window)
|
||||
{
|
||||
if (stack.back().main == window) {
|
||||
stack.pop_back();
|
||||
const auto & back = stack.back();
|
||||
if (back.focus) {
|
||||
back.focus->setFocus(SET_FOCUS_DEFAULT);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO it would be better to do it in reverse order
|
||||
for (auto it = stack.begin(); it != stack.end(); it++) {
|
||||
if (it->main == window) {
|
||||
stack.erase(it);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
+4
-2
@@ -20,15 +20,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <utility>
|
||||
#include "window.h"
|
||||
#include "layer.h"
|
||||
#include "bitmapbuffer.h"
|
||||
|
||||
class MainWindow: public Window {
|
||||
class MainWindow: public Window
|
||||
{
|
||||
public:
|
||||
MainWindow():
|
||||
Window(nullptr, {0, 0, LCD_W, LCD_H}),
|
||||
invalidatedRect(rect)
|
||||
{
|
||||
Layer::push(this);
|
||||
}
|
||||
|
||||
~MainWindow() override
|
||||
|
||||
-2
@@ -55,7 +55,6 @@ void MenuBody::onEvent(event_t event)
|
||||
menu->invalidate();
|
||||
}
|
||||
else {
|
||||
menu->revertPreviousFocus();
|
||||
lines[selectedIndex].onPress();
|
||||
menu->deleteLater();
|
||||
}
|
||||
@@ -87,7 +86,6 @@ bool MenuBody::onTouchEnd(coord_t /*x*/, coord_t y)
|
||||
menu->invalidate();
|
||||
}
|
||||
else {
|
||||
menu->revertPreviousFocus();
|
||||
lines[index].onPress();
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -20,11 +20,22 @@
|
||||
|
||||
#include "modal_window.h"
|
||||
#include "font.h"
|
||||
#include "layer.h"
|
||||
|
||||
ModalWindow::ModalWindow(Window * parent):
|
||||
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H}),
|
||||
previousFocus(focusWindow)
|
||||
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H})
|
||||
{
|
||||
Layer::push(this);
|
||||
}
|
||||
|
||||
void ModalWindow::deleteLater(bool detach)
|
||||
{
|
||||
if (_deleted)
|
||||
return;
|
||||
|
||||
Layer::pop(this);
|
||||
|
||||
Window::deleteLater(detach);
|
||||
}
|
||||
|
||||
void ModalWindow::paint(BitmapBuffer * dc)
|
||||
|
||||
+1
-25
@@ -33,17 +33,7 @@ class ModalWindow: public Window
|
||||
}
|
||||
#endif
|
||||
|
||||
void deleteLater(bool detach=true) override
|
||||
{
|
||||
if (_deleted)
|
||||
return;
|
||||
|
||||
if (previousFocus && (!focusWindow || focusWindow->isChild(this))) {
|
||||
previousFocus->setFocus(SET_FOCUS_DEFAULT);
|
||||
}
|
||||
|
||||
Window::deleteLater(detach);
|
||||
}
|
||||
void deleteLater(bool detach=true) override;
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
@@ -73,21 +63,7 @@ class ModalWindow: public Window
|
||||
closeAllowed = value;
|
||||
}
|
||||
|
||||
void forgetPreviousFocus()
|
||||
{
|
||||
previousFocus = nullptr;
|
||||
}
|
||||
|
||||
void revertPreviousFocus()
|
||||
{
|
||||
if (previousFocus) {
|
||||
previousFocus->setFocus(SET_FOCUS_DEFAULT);
|
||||
previousFocus = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Window * previousFocus;
|
||||
bool closeAllowed = true;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user