Allow ModalWindows not to be closed when touching outside

This commit is contained in:
Bertrand Songis
2021-03-10 09:41:37 +01:00
parent 549f4da051
commit 8a196f5982
5 changed files with 12 additions and 11 deletions
+1 -1
View File
@@ -45,7 +45,7 @@ class ChoiceBase : public FormField
ChoiceType type;
};
class Choice : public ChoiceBase {
class Choice: public ChoiceBase {
public:
Choice(FormGroup * parent, const rect_t & rect, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = 0);
Choice(FormGroup * parent, const rect_t & rect, std::vector<std::string> values, int vmin, int vmax, std::function<int()> getValue, std::function<void(int)> setValue = nullptr, WindowFlags windowFlags = 0);
+1 -1
View File
@@ -154,7 +154,7 @@ void MenuWindowContent::paint(BitmapBuffer * dc)
}
Menu::Menu(Window * parent, bool multiple):
ModalWindow(parent),
ModalWindow(parent, true),
content(createMenuWindow(this)),
multiple(multiple)
{
+2 -2
View File
@@ -27,13 +27,13 @@
class Menu;
class MenuWindowContent;
class MenuBody : public Window
class MenuBody: public Window
{
friend class MenuWindowContent;
friend class Menu;
class MenuLine {
friend class MenuBody;
friend class MenuBody;
public:
MenuLine(std::string text, std::function<void()> onPress, std::function<bool()> isChecked):
+3 -2
View File
@@ -22,8 +22,9 @@
#include "font.h"
#include "layer.h"
ModalWindow::ModalWindow(Window * parent):
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H})
ModalWindow::ModalWindow(Window * parent, bool closeWhenClickOutside):
Window(parent->getFullScreenWindow(), {0, 0, LCD_W, LCD_H}),
closeWhenClickOutside(closeWhenClickOutside)
{
Layer::push(this);
}
+5 -5
View File
@@ -24,7 +24,7 @@
class ModalWindow: public Window
{
public:
explicit ModalWindow(Window * parent);
explicit ModalWindow(Window * parent, bool closeWhenClickOutside = false);
#if defined(DEBUG_WINDOWS)
std::string getName() const override
@@ -45,7 +45,7 @@ class ModalWindow: public Window
bool onTouchEnd(coord_t x, coord_t y) override
{
if (!Window::onTouchEnd(x, y) && closeAllowed) {
if (!Window::onTouchEnd(x, y) && closeWhenClickOutside) {
onKeyPress();
deleteLater();
}
@@ -59,13 +59,13 @@ class ModalWindow: public Window
}
#endif
void setCloseAllowed(bool value = true)
void setCloseWhenClickOutside(bool value = true)
{
closeAllowed = value;
closeWhenClickOutside = value;
}
protected:
bool closeAllowed = true;
bool closeWhenClickOutside;
};
class ModalWindowContent: public Window