ModalWindow layer used in Dialog
This commit is contained in:
@@ -30,6 +30,7 @@ set(LIBOPENUI_SRC
|
||||
coloredit.cpp
|
||||
progress.cpp
|
||||
table.cpp
|
||||
modal_window.cpp
|
||||
dialog.cpp
|
||||
message_dialog.cpp
|
||||
)
|
||||
|
||||
+5
-21
@@ -21,27 +21,11 @@
|
||||
#include "mainwindow.h"
|
||||
|
||||
Dialog::Dialog(std::string title, const rect_t & rect):
|
||||
FormGroup(&mainWindow, rect, OPAQUE),
|
||||
title(std::move(title)),
|
||||
previousFocus(focusWindow)
|
||||
ModalWindow(),
|
||||
content(this, rect),
|
||||
form(&content, {0, 0, rect.w, rect.h}, FORM_NO_BORDER)
|
||||
{
|
||||
bringToTop();
|
||||
setFocus();
|
||||
}
|
||||
|
||||
void Dialog::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->drawRect(0, 0, width() - 1, height() - 1, 1, SOLID, DEFAULT_COLOR);
|
||||
dc->drawSolidFilledRect(1, 1, width() - 3, PAGE_LINE_HEIGHT, FOCUS_BGCOLOR);
|
||||
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), FOCUS_COLOR);
|
||||
dc->drawSolidFilledRect(1, PAGE_LINE_HEIGHT + 1, width() - 3, height() - PAGE_LINE_HEIGHT - 3, DEFAULT_BGCOLOR);
|
||||
}
|
||||
|
||||
void Dialog::deleteLater()
|
||||
{
|
||||
if (previousFocus) {
|
||||
previousFocus->setFocus();
|
||||
}
|
||||
|
||||
Window::deleteLater();
|
||||
content.setTitle(title);
|
||||
form.setFocus();
|
||||
}
|
||||
|
||||
+10
-7
@@ -20,19 +20,22 @@
|
||||
#ifndef _DIALOG_H_
|
||||
#define _DIALOG_H_
|
||||
|
||||
#include "modal_window.h"
|
||||
#include "form.h"
|
||||
|
||||
class Dialog: public FormGroup {
|
||||
class Dialog: public ModalWindow {
|
||||
public:
|
||||
Dialog(std::string title, const rect_t & rect);
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
void deleteLater();
|
||||
~Dialog() override
|
||||
{
|
||||
form.detach();
|
||||
content.detach();
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string title;
|
||||
Window * previousFocus;
|
||||
ModalWindowContent content;
|
||||
FormGroup form;
|
||||
};
|
||||
|
||||
#endif // _CONFIRMATION_H_
|
||||
#endif // _DIALOG_H_
|
||||
|
||||
+3
-3
@@ -69,7 +69,7 @@ void FormField::paint(BitmapBuffer * dc)
|
||||
else if (hasFocus()) {
|
||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
|
||||
}
|
||||
else if (!(windowFlags & BORDER_FOCUS_ONLY)) {
|
||||
else if (!(windowFlags & FORM_BORDER_FOCUS_ONLY)) {
|
||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR);
|
||||
}
|
||||
}
|
||||
@@ -155,11 +155,11 @@ void FormGroup::onEvent(event_t event)
|
||||
|
||||
void FormGroup::paint(BitmapBuffer * dc)
|
||||
{
|
||||
if (!(windowFlags & FORM_FORWARD_FOCUS)) {
|
||||
if (!(windowFlags & (FORM_NO_BORDER | FORM_FORWARD_FOCUS))) {
|
||||
if (!editMode && hasFocus()) {
|
||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR);
|
||||
}
|
||||
else if (!(windowFlags & BORDER_FOCUS_ONLY)) {
|
||||
else if (!(windowFlags & FORM_BORDER_FOCUS_ONLY)) {
|
||||
dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -24,7 +24,9 @@
|
||||
|
||||
constexpr WindowFlags FORM_FORWARD_FOCUS = WINDOW_FLAGS_LAST << 1;
|
||||
constexpr WindowFlags FORM_DETACHED = WINDOW_FLAGS_LAST << 2;
|
||||
constexpr WindowFlags FORM_FLAGS_LAST = FORM_DETACHED;
|
||||
constexpr WindowFlags FORM_BORDER_FOCUS_ONLY = WINDOW_FLAGS_LAST << 3;
|
||||
constexpr WindowFlags FORM_NO_BORDER = WINDOW_FLAGS_LAST << 4;
|
||||
constexpr WindowFlags FORM_FLAGS_LAST = FORM_NO_BORDER;
|
||||
|
||||
class FormField: public Window {
|
||||
public:
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ class FormGridLayout: public GridLayout {
|
||||
protected:
|
||||
coord_t labelWidth = PAGE_LABEL_WIDTH;
|
||||
coord_t lineMarginLeft = PAGE_PADDING;
|
||||
coord_t lineMarginRight = 10;
|
||||
coord_t lineMarginRight = PAGE_PADDING;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+20
-20
@@ -21,13 +21,6 @@
|
||||
#include "font.h"
|
||||
#include "theme.h"
|
||||
|
||||
MenuWindow::MenuWindow(Menu * parent):
|
||||
Window(parent, {(LCD_W - MENUS_WIDTH) / 2, (LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}, OPAQUE),
|
||||
body(this, {0, 0, width(), height()})
|
||||
{
|
||||
body.setFocus();
|
||||
}
|
||||
|
||||
void MenuBody::select(int index)
|
||||
{
|
||||
selectedIndex = index;
|
||||
@@ -95,7 +88,14 @@ void MenuBody::paint(BitmapBuffer * dc)
|
||||
}
|
||||
}
|
||||
|
||||
void MenuWindow::paint(BitmapBuffer * dc)
|
||||
MenuWindowContent::MenuWindowContent(Menu * parent):
|
||||
ModalWindowContent(parent, {(LCD_W - MENUS_WIDTH) / 2, (LCD_H - MENUS_WIDTH) / 2, MENUS_WIDTH, 0}),
|
||||
body(this, {0, 0, width(), height()})
|
||||
{
|
||||
body.setFocus();
|
||||
}
|
||||
|
||||
void MenuWindowContent::paint(BitmapBuffer * dc)
|
||||
{
|
||||
// the background
|
||||
dc->clear(MENU_BGCOLOR);
|
||||
@@ -109,7 +109,7 @@ void MenuWindow::paint(BitmapBuffer * dc)
|
||||
|
||||
Menu::Menu():
|
||||
ModalWindow(),
|
||||
menuWindow(createMenuWindow(this))
|
||||
content(createMenuWindow(this))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -117,37 +117,37 @@ void Menu::updatePosition()
|
||||
{
|
||||
if (!toolbar) {
|
||||
// there is no navigation bar at the left, we may center the window on screen
|
||||
auto headerHeight = menuWindow->title.empty() ? 0 : MENUS_HEADER_HEIGHT;
|
||||
auto bodyHeight = limit<coord_t>(MENUS_MIN_HEIGHT, menuWindow->body.lines.size() * MENUS_LINE_HEIGHT - 1, MENUS_MAX_HEIGHT);
|
||||
menuWindow->setTop((LCD_H - headerHeight - bodyHeight) / 2 + MENUS_OFFSET_TOP);
|
||||
menuWindow->setHeight(headerHeight + bodyHeight);
|
||||
menuWindow->body.setTop(headerHeight);
|
||||
menuWindow->body.setHeight(bodyHeight);
|
||||
auto headerHeight = content->title.empty() ? 0 : MENUS_HEADER_HEIGHT;
|
||||
auto bodyHeight = limit<coord_t>(MENUS_MIN_HEIGHT, content->body.lines.size() * MENUS_LINE_HEIGHT - 1, MENUS_MAX_HEIGHT);
|
||||
content->setTop((LCD_H - headerHeight - bodyHeight) / 2 + MENUS_OFFSET_TOP);
|
||||
content->setHeight(headerHeight + bodyHeight);
|
||||
content->body.setTop(headerHeight);
|
||||
content->body.setHeight(bodyHeight);
|
||||
}
|
||||
menuWindow->body.setInnerHeight(menuWindow->body.lines.size() * MENUS_LINE_HEIGHT - 1);
|
||||
content->body.setInnerHeight(content->body.lines.size() * MENUS_LINE_HEIGHT - 1);
|
||||
}
|
||||
|
||||
void Menu::setTitle(const std::string text)
|
||||
{
|
||||
menuWindow->setTitle(text);
|
||||
content->setTitle(text);
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Menu::addLine(const std::string & text, std::function<void()> onPress)
|
||||
{
|
||||
menuWindow->body.addLine(text, std::move(onPress));
|
||||
content->body.addLine(text, std::move(onPress));
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Menu::addCustomLine(std::function<void(BitmapBuffer * dc, coord_t x, coord_t y, LcdFlags flags)> drawLine, std::function<void()> onPress)
|
||||
{
|
||||
menuWindow->body.addCustomLine(drawLine, std::move(onPress));
|
||||
content->body.addCustomLine(drawLine, std::move(onPress));
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
void Menu::removeLines()
|
||||
{
|
||||
menuWindow->body.removeLines();
|
||||
content->body.removeLines();
|
||||
updatePosition();
|
||||
}
|
||||
|
||||
|
||||
+12
-18
@@ -26,10 +26,10 @@
|
||||
#include "modal_window.h"
|
||||
|
||||
class Menu;
|
||||
class MenuWindow;
|
||||
class MenuWindowContent;
|
||||
|
||||
class MenuBody: public Window {
|
||||
friend class MenuWindow;
|
||||
friend class MenuWindowContent;
|
||||
friend class Menu;
|
||||
|
||||
class MenuLine {
|
||||
@@ -110,13 +110,13 @@ class MenuBody: public Window {
|
||||
std::function<void()> onCancel;
|
||||
};
|
||||
|
||||
class MenuWindow: public Window {
|
||||
class MenuWindowContent: public ModalWindowContent {
|
||||
friend class Menu;
|
||||
|
||||
public:
|
||||
explicit MenuWindow(Menu * parent);
|
||||
explicit MenuWindowContent(Menu * parent);
|
||||
|
||||
~MenuWindow() override
|
||||
~MenuWindowContent() override
|
||||
{
|
||||
body.detach();
|
||||
}
|
||||
@@ -124,20 +124,14 @@ class MenuWindow: public Window {
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "MenuWindow";
|
||||
return "MenuWindow::";
|
||||
}
|
||||
#endif
|
||||
|
||||
void setTitle(const std::string text)
|
||||
{
|
||||
title = std::move(text);
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
protected:
|
||||
MenuBody body;
|
||||
std::string title;
|
||||
};
|
||||
|
||||
class Menu: public ModalWindow {
|
||||
@@ -146,7 +140,7 @@ class Menu: public ModalWindow {
|
||||
|
||||
void setCancelHandler(std::function<void()> handler)
|
||||
{
|
||||
menuWindow->body.setCancelHandler(handler);
|
||||
content->body.setCancelHandler(handler);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
@@ -159,9 +153,9 @@ class Menu: public ModalWindow {
|
||||
void setToolbar(Window * window)
|
||||
{
|
||||
toolbar = window;
|
||||
menuWindow->setLeft(toolbar->right());
|
||||
menuWindow->setTop(toolbar->top());
|
||||
menuWindow->setHeight(toolbar->height());
|
||||
content->setLeft(toolbar->right());
|
||||
content->setTop(toolbar->top());
|
||||
content->setHeight(toolbar->height());
|
||||
}
|
||||
|
||||
void setTitle(const std::string text);
|
||||
@@ -174,7 +168,7 @@ class Menu: public ModalWindow {
|
||||
|
||||
inline void select(int index)
|
||||
{
|
||||
menuWindow->body.select(index);
|
||||
content->body.select(index);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_KEYS)
|
||||
@@ -182,7 +176,7 @@ class Menu: public ModalWindow {
|
||||
#endif
|
||||
|
||||
protected:
|
||||
MenuWindow * menuWindow;
|
||||
MenuWindowContent * content;
|
||||
Window * toolbar = nullptr;
|
||||
void updatePosition();
|
||||
};
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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 "modal_window.h"
|
||||
#include "mainwindow.h"
|
||||
#include "font.h"
|
||||
|
||||
ModalWindow::ModalWindow():
|
||||
Window(&mainWindow, {0, 0, LCD_W, LCD_H})
|
||||
#if !defined(HARDWARE_TOUCH)
|
||||
, previousFocus(focusWindow)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
void ModalWindow::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->drawFilledRect(0, 0, width(), height(), SOLID, OVERLAY_COLOR | OPACITY(5));
|
||||
}
|
||||
|
||||
void ModalWindowContent::paint(BitmapBuffer * dc)
|
||||
{
|
||||
dc->drawSolidFilledRect(0, 0, width(), PAGE_LINE_HEIGHT, FOCUS_BGCOLOR);
|
||||
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), FOCUS_COLOR);
|
||||
dc->drawSolidFilledRect(0, PAGE_LINE_HEIGHT, width(), height() - PAGE_LINE_HEIGHT, DEFAULT_BGCOLOR);
|
||||
|
||||
/*
|
||||
// the background
|
||||
dc->clear(MENU_BGCOLOR);
|
||||
|
||||
// the title
|
||||
if (!title.empty()) {
|
||||
dc->drawText(MENUS_WIDTH / 2, (MENUS_HEADER_HEIGHT - getFontHeight(MENU_HEADER_FONT)) / 2, title.c_str(), CENTERED | MENU_HEADER_FONT);
|
||||
dc->drawSolidHorizontalLine(0, MENUS_HEADER_HEIGHT - 1, MENUS_WIDTH, MENU_LINE_COLOR);
|
||||
}*/
|
||||
}
|
||||
+30
-15
@@ -20,21 +20,12 @@
|
||||
#ifndef _MODAL_WINDOW_H_
|
||||
#define _MODAL_WINDOW_H_
|
||||
|
||||
#include <vector>
|
||||
#include <functional>
|
||||
#include <utility>
|
||||
#include "mainwindow.h"
|
||||
#include "window.h"
|
||||
|
||||
class ModalWindow: public Window
|
||||
{
|
||||
public:
|
||||
ModalWindow():
|
||||
Window(&mainWindow, {0, 0, LCD_W, LCD_H})
|
||||
#if !defined(HARDWARE_TOUCH)
|
||||
, previousFocus(focusWindow)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
ModalWindow();
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
@@ -53,10 +44,7 @@ class ModalWindow: public Window
|
||||
Window::deleteLater();
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override
|
||||
{
|
||||
dc->drawFilledRect(0, 0, width(), height(), SOLID, OVERLAY_COLOR | OPACITY(5));
|
||||
}
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
#if defined(HARDWARE_TOUCH)
|
||||
bool onTouchStart(coord_t x, coord_t y) override
|
||||
@@ -80,7 +68,34 @@ class ModalWindow: public Window
|
||||
#endif
|
||||
|
||||
protected:
|
||||
#if !defined(HARDWARE_TOUCH)
|
||||
Window * previousFocus = nullptr;
|
||||
#endif
|
||||
};
|
||||
|
||||
class ModalWindowContent: public Window {
|
||||
public:
|
||||
explicit ModalWindowContent(ModalWindow * parent, const rect_t & rect):
|
||||
Window(parent, rect, OPAQUE)
|
||||
{
|
||||
}
|
||||
|
||||
#if defined(DEBUG_WINDOWS)
|
||||
std::string getName() override
|
||||
{
|
||||
return "ModalWindowContent";
|
||||
}
|
||||
#endif
|
||||
|
||||
void setTitle(std::string text)
|
||||
{
|
||||
title = std::move(text);
|
||||
}
|
||||
|
||||
void paint(BitmapBuffer * dc) override;
|
||||
|
||||
protected:
|
||||
std::string title;
|
||||
};
|
||||
|
||||
#endif // _MODAL_WINDOW_H_
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@
|
||||
#include "checkbox.h"
|
||||
|
||||
class Menu;
|
||||
class MenuWindow;
|
||||
class MenuWindowContent;
|
||||
class ChoiceBase;
|
||||
|
||||
enum IconState {
|
||||
@@ -52,6 +52,6 @@ class Theme {
|
||||
|
||||
extern Theme * theme;
|
||||
|
||||
MenuWindow * createMenuWindow(Menu * menu);
|
||||
MenuWindowContent * createMenuWindow(Menu * menu);
|
||||
|
||||
#endif // _THEME_H_
|
||||
|
||||
+7
-8
@@ -38,14 +38,13 @@ typedef uint32_t WindowFlags;
|
||||
#undef TRANSPARENT
|
||||
#endif
|
||||
|
||||
constexpr WindowFlags OPAQUE = 1 << 0;
|
||||
constexpr WindowFlags TRANSPARENT = 1 << 1;
|
||||
constexpr WindowFlags NO_SCROLLBAR = 1 << 2;
|
||||
constexpr WindowFlags NO_FOCUS = 1 << 3;
|
||||
constexpr WindowFlags FORWARD_SCROLL = 1 << 4;
|
||||
constexpr WindowFlags REFRESH_ALWAYS = 1 << 5;
|
||||
constexpr WindowFlags BORDER_FOCUS_ONLY = 1 << 6;
|
||||
constexpr WindowFlags PAINT_CHILDREN_FIRST = 1 << 7;
|
||||
constexpr WindowFlags OPAQUE = 1u << 0;
|
||||
constexpr WindowFlags TRANSPARENT = 1u << 1;
|
||||
constexpr WindowFlags NO_SCROLLBAR = 1u << 2;
|
||||
constexpr WindowFlags NO_FOCUS = 1u << 3;
|
||||
constexpr WindowFlags FORWARD_SCROLL = 1u << 4;
|
||||
constexpr WindowFlags REFRESH_ALWAYS = 1u << 5;
|
||||
constexpr WindowFlags PAINT_CHILDREN_FIRST = 1u << 6;
|
||||
constexpr WindowFlags WINDOW_FLAGS_LAST = PAINT_CHILDREN_FIRST;
|
||||
|
||||
enum SetFocusFlag {
|
||||
|
||||
Reference in New Issue
Block a user