Dialog now themeable

This commit is contained in:
Bertrand Songis
2019-11-29 17:58:32 +01:00
parent 72229f40c3
commit ce725d09f4
6 changed files with 24 additions and 14 deletions
+4 -3
View File
@@ -19,13 +19,14 @@
#include "dialog.h" #include "dialog.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "theme.h"
Dialog::Dialog(std::string title, const rect_t & rect): Dialog::Dialog(std::string title, const rect_t & rect):
ModalWindow(), ModalWindow(),
content(this, rect), content(createDialogWindow(this, rect)),
form(&content, {0, 0, rect.w, rect.h}, FORM_NO_BORDER) form(content, {0, POPUP_HEADER_HEIGHT, rect.w, coord_t(rect.h - POPUP_HEADER_HEIGHT)}, FORM_NO_BORDER)
{ {
bringToTop(); bringToTop();
content.setTitle(title); content->setTitle(title);
form.setFocus(); form.setFocus();
} }
+8 -2
View File
@@ -30,11 +30,17 @@ class Dialog: public ModalWindow {
~Dialog() override ~Dialog() override
{ {
form.detach(); form.detach();
content.detach();
} }
#if defined(DEBUG_WINDOWS)
std::string getName() override
{
return "Dialog";
}
#endif
protected: protected:
ModalWindowContent content; ModalWindowContent * content;
FormGroup form; FormGroup form;
}; };
+3 -3
View File
@@ -102,8 +102,8 @@ void MenuWindowContent::paint(BitmapBuffer * dc)
// the title // the title
if (!title.empty()) { if (!title.empty()) {
dc->drawText(MENUS_WIDTH / 2, (MENUS_HEADER_HEIGHT - getFontHeight(MENU_HEADER_FONT)) / 2, title.c_str(), CENTERED | MENU_HEADER_FONT); dc->drawText(MENUS_WIDTH / 2, (POPUP_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); dc->drawSolidHorizontalLine(0, POPUP_HEADER_HEIGHT - 1, MENUS_WIDTH, MENU_LINE_COLOR);
} }
} }
@@ -117,7 +117,7 @@ void Menu::updatePosition()
{ {
if (!toolbar) { if (!toolbar) {
// there is no navigation bar at the left, we may center the window on screen // there is no navigation bar at the left, we may center the window on screen
auto headerHeight = content->title.empty() ? 0 : MENUS_HEADER_HEIGHT; auto headerHeight = content->title.empty() ? 0 : POPUP_HEADER_HEIGHT;
auto bodyHeight = limit<coord_t>(MENUS_MIN_HEIGHT, content->body.lines.size() * MENUS_LINE_HEIGHT - 1, MENUS_MAX_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->setTop((LCD_H - headerHeight - bodyHeight) / 2 + MENUS_OFFSET_TOP);
content->setHeight(headerHeight + bodyHeight); content->setHeight(headerHeight + bodyHeight);
+1 -1
View File
@@ -181,4 +181,4 @@ class Menu: public ModalWindow {
void updatePosition(); void updatePosition();
}; };
#endif #endif // _MENU_H_
+5 -5
View File
@@ -37,9 +37,9 @@ void ModalWindow::paint(BitmapBuffer * dc)
void ModalWindowContent::paint(BitmapBuffer * dc) void ModalWindowContent::paint(BitmapBuffer * dc)
{ {
dc->drawSolidFilledRect(0, 0, width(), PAGE_LINE_HEIGHT, FOCUS_BGCOLOR); dc->drawSolidFilledRect(0, 0, width(), POPUP_HEADER_HEIGHT, FOCUS_BGCOLOR);
dc->drawText(FIELD_PADDING_LEFT, FIELD_PADDING_TOP, title.c_str(), FOCUS_COLOR); dc->drawText(FIELD_PADDING_LEFT, (POPUP_HEADER_HEIGHT - getFontHeight(FONT(STD))) / 2, title.c_str(), FOCUS_COLOR);
dc->drawSolidFilledRect(0, PAGE_LINE_HEIGHT, width(), height() - PAGE_LINE_HEIGHT, DEFAULT_BGCOLOR); dc->drawSolidFilledRect(0, POPUP_HEADER_HEIGHT, width(), height() - POPUP_HEADER_HEIGHT, DEFAULT_BGCOLOR);
/* /*
// the background // the background
@@ -47,7 +47,7 @@ void ModalWindowContent::paint(BitmapBuffer * dc)
// the title // the title
if (!title.empty()) { if (!title.empty()) {
dc->drawText(MENUS_WIDTH / 2, (MENUS_HEADER_HEIGHT - getFontHeight(MENU_HEADER_FONT)) / 2, title.c_str(), CENTERED | MENU_HEADER_FONT); dc->drawText(MENUS_WIDTH / 2, (POPUP_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); dc->drawSolidHorizontalLine(0, POPUP_HEADER_HEIGHT - 1, MENUS_WIDTH, MENU_LINE_COLOR);
}*/ }*/
} }
+3
View File
@@ -25,6 +25,8 @@
class Menu; class Menu;
class MenuWindowContent; class MenuWindowContent;
class Dialog;
class ModalWindowContent;
class ChoiceBase; class ChoiceBase;
enum IconState { enum IconState {
@@ -53,5 +55,6 @@ class Theme {
extern Theme * theme; extern Theme * theme;
MenuWindowContent * createMenuWindow(Menu * menu); MenuWindowContent * createMenuWindow(Menu * menu);
ModalWindowContent * createDialogWindow(Dialog * dialog, const rect_t & rect);
#endif // _THEME_H_ #endif // _THEME_H_