diff --git a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp index d223e1ac5..7f78b1702 100644 --- a/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp +++ b/radio/src/thirdparty/libopenui/src/bitmapbuffer.cpp @@ -444,12 +444,12 @@ coord_t BitmapBuffer::drawSizedText(coord_t x, coord_t y, const char * s, uint8_ c = uint8_t(*s) + ((c & 0x01) << 8) - 1; if (c >= 0x101) c -= 1; - c += 187; - uint8_t width = drawChar(x-1, y, font, fontspecs, c, flags); + c += CJK_FIRST_LETTER_INDEX; + uint8_t width = drawChar(x, y, font, fontspecs, c, flags); INCREMENT_POS(width); } - else if (c >= 0x20) { - uint8_t width = drawChar(x-1, y, font, fontspecs, getMappedChar(c), flags); + else if (c > 0x20) { + uint8_t width = drawChar(x, y, font, fontspecs, getMappedChar(c), flags); INCREMENT_POS(width); } else if (c == '\n') { diff --git a/radio/src/thirdparty/libopenui/src/button.cpp b/radio/src/thirdparty/libopenui/src/button.cpp index ff5caef45..d9b97bead 100644 --- a/radio/src/thirdparty/libopenui/src/button.cpp +++ b/radio/src/thirdparty/libopenui/src/button.cpp @@ -25,8 +25,8 @@ void Button::onPress() { bool check = (pressHandler && pressHandler()); - if (check != bool(flags & BUTTON_CHECKED)) { - flags ^= BUTTON_CHECKED; + if (check != bool(windowFlags & BUTTON_CHECKED)) { + windowFlags ^= BUTTON_CHECKED; invalidate(); } } @@ -83,7 +83,7 @@ void TextButton::paint(BitmapBuffer * dc) textColor = FOCUS_COLOR; } else { - if (flags & BUTTON_BACKGROUND) { + if (windowFlags & BUTTON_BACKGROUND) { if (hasFocus()) { dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR); dc->drawSolidFilledRect(2, 2, rect.w - 4, rect.h - 4, DISABLE_COLOR); @@ -102,7 +102,7 @@ void TextButton::paint(BitmapBuffer * dc) } } - dc->drawText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2, text.c_str(), CENTERED | textColor); + dc->drawText(rect.w / 2, (rect.h - getFontHeight(textFlags)) / 2, text.c_str(), CENTERED | textColor); } void IconButton::paint(BitmapBuffer * dc) diff --git a/radio/src/thirdparty/libopenui/src/button.h b/radio/src/thirdparty/libopenui/src/button.h index 8b160c6ca..075eb2f59 100644 --- a/radio/src/thirdparty/libopenui/src/button.h +++ b/radio/src/thirdparty/libopenui/src/button.h @@ -23,20 +23,17 @@ #include "form.h" #include -enum ButtonFlags { - BUTTON_BACKGROUND = 1, - BUTTON_CHECKED = 2, - BUTTON_NOFOCUS = 4, - BUTTON_CHECKED_ON_FOCUS = 8, - BUTTON_DISABLED = 16, -}; +constexpr WindowFlags BUTTON_BACKGROUND = FORM_FLAGS_LAST << 1; +constexpr WindowFlags BUTTON_CHECKED = FORM_FLAGS_LAST << 2; +constexpr WindowFlags BUTTON_NOFOCUS = FORM_FLAGS_LAST << 3; +constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 4; +constexpr WindowFlags BUTTON_DISABLED = FORM_FLAGS_LAST << 5; class Button : public FormField { public: - Button(Window * parent, const rect_t & rect, std::function pressHandler=nullptr, uint8_t flags=0): - FormField(parent, rect), - pressHandler(pressHandler), - flags(flags) + Button(FormGroup * parent, const rect_t & rect, std::function pressHandler = nullptr, WindowFlags windowFlags = 0): + FormField(parent, rect, windowFlags), + pressHandler(pressHandler) { } @@ -49,8 +46,8 @@ class Button : public FormField { void enable(bool enabled=true) { - if (!enabled != bool(flags & BUTTON_DISABLED)) { - flags ^= BUTTON_DISABLED; + if (!enabled != bool(windowFlags & BUTTON_DISABLED)) { + windowFlags ^= BUTTON_DISABLED; invalidate(); } } @@ -62,23 +59,23 @@ class Button : public FormField { void check(bool checked=true) { - if (checked != bool(flags & BUTTON_CHECKED)) { - flags ^= BUTTON_CHECKED; + if (checked != bool(windowFlags & BUTTON_CHECKED)) { + windowFlags ^= BUTTON_CHECKED; invalidate(); } } bool enabled() { - return !(flags & BUTTON_DISABLED); + return !(windowFlags & BUTTON_DISABLED); } bool checked() { - if (flags & BUTTON_CHECKED_ON_FOCUS) + if (windowFlags & BUTTON_CHECKED_ON_FOCUS) return hasFocus(); else - return flags & BUTTON_CHECKED; + return windowFlags & BUTTON_CHECKED; } void setPressHandler(std::function handler) @@ -104,18 +101,16 @@ class Button : public FormField { protected: std::function pressHandler; std::function checkHandler; - uint8_t flags; void onPress(); }; class TextButton : public Button { public: - TextButton(Window * parent, const rect_t & rect, std::string text, std::function pressHandler = nullptr, uint8_t flags = BUTTON_BACKGROUND): - Button(parent, rect, pressHandler, flags), + TextButton(FormGroup * parent, const rect_t & rect, std::string text, std::function pressHandler = nullptr, WindowFlags windowFlags = BUTTON_BACKGROUND): + Button(parent, rect, pressHandler, windowFlags | OPAQUE), text(std::move(text)) { - windowFlags = OPAQUE; } #if defined(DEBUG_WINDOWS) @@ -141,7 +136,7 @@ class TextButton : public Button { class IconButton: public Button { public: - IconButton(Window * parent, const rect_t & rect, uint8_t icon, std::function pressHandler, uint8_t flags = 0): + IconButton(FormGroup * parent, const rect_t & rect, uint8_t icon, std::function pressHandler, WindowFlags flags = 0): Button(parent, rect, pressHandler, flags), icon(icon) { diff --git a/radio/src/thirdparty/libopenui/src/choice.cpp b/radio/src/thirdparty/libopenui/src/choice.cpp index 9f5d3a5a9..9185653f7 100644 --- a/radio/src/thirdparty/libopenui/src/choice.cpp +++ b/radio/src/thirdparty/libopenui/src/choice.cpp @@ -21,15 +21,14 @@ #include "menu.h" #include "theme.h" -Choice::Choice(Window * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax, - std::function getValue, std::function setValue, LcdFlags flags) : +Choice::Choice(FormGroup * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax, + std::function getValue, std::function setValue) : ChoiceBase(parent, rect), values(values), vmin(vmin), vmax(vmax), getValue(std::move(getValue)), - setValue(std::move(setValue)), - flags(flags) + setValue(std::move(setValue)) { } diff --git a/radio/src/thirdparty/libopenui/src/choice.h b/radio/src/thirdparty/libopenui/src/choice.h index ea12c55a2..6930f8192 100644 --- a/radio/src/thirdparty/libopenui/src/choice.h +++ b/radio/src/thirdparty/libopenui/src/choice.h @@ -29,9 +29,9 @@ enum ChoiceType { class ChoiceBase : public FormField { public: - ChoiceBase(Window * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN): - FormField(parent, rect), - type(type) + ChoiceBase(FormGroup * parent, const rect_t & rect, ChoiceType type = CHOICE_TYPE_DROPOWN): + FormField(parent, rect), + type(type) { } @@ -46,7 +46,7 @@ class ChoiceBase : public FormField { class Choice : public ChoiceBase { public: - Choice(Window * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax, std::function getValue, std::function setValue = nullptr, LcdFlags flags = 0); + Choice(FormGroup * parent, const rect_t & rect, const char * values, int16_t vmin, int16_t vmax, std::function getValue, std::function setValue = nullptr); #if defined(DEBUG_WINDOWS) std::string getName() override @@ -88,7 +88,6 @@ class Choice : public ChoiceBase { std::function setValue; std::function isValueAvailable; std::function textHandler; - LcdFlags flags = 0; virtual void openMenu(); }; diff --git a/radio/src/thirdparty/libopenui/src/dialog.cpp b/radio/src/thirdparty/libopenui/src/dialog.cpp index 955417da9..26b540477 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.cpp +++ b/radio/src/thirdparty/libopenui/src/dialog.cpp @@ -19,15 +19,13 @@ #include "dialog.h" #include "mainwindow.h" -#include "form.h" Dialog::Dialog(std::string title, const rect_t rect): - Window(&mainWindow, rect, OPAQUE), + FormGroup(&mainWindow, rect, OPAQUE), title(std::move(title)), previousFocus(focusWindow) { bringToTop(); - FormField::clearCurrentField(); setFocus(); } diff --git a/radio/src/thirdparty/libopenui/src/dialog.h b/radio/src/thirdparty/libopenui/src/dialog.h index 5ec3bf8aa..6807705a4 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.h +++ b/radio/src/thirdparty/libopenui/src/dialog.h @@ -20,9 +20,9 @@ #ifndef _DIALOG_H_ #define _DIALOG_H_ -#include "window.h" +#include "form.h" -class Dialog: public Window { +class Dialog: public FormGroup { public: Dialog(std::string title, const rect_t rect); diff --git a/radio/src/thirdparty/libopenui/src/filechoice.cpp b/radio/src/thirdparty/libopenui/src/filechoice.cpp index 49b0723e1..ddca3da82 100644 --- a/radio/src/thirdparty/libopenui/src/filechoice.cpp +++ b/radio/src/thirdparty/libopenui/src/filechoice.cpp @@ -29,7 +29,7 @@ bool compare_nocase(const std::string &first, const std::string &second) return strcasecmp(first.c_str(), second.c_str()) < 0; } -FileChoice::FileChoice(Window * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function getValue, std::function setValue): +FileChoice::FileChoice(FormGroup * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function getValue, std::function setValue): ChoiceBase(parent, rect, CHOICE_TYPE_FOLDER), folder(std::move(folder)), extension(extension), diff --git a/radio/src/thirdparty/libopenui/src/filechoice.h b/radio/src/thirdparty/libopenui/src/filechoice.h index 2a28ea3a9..ebed4d8d4 100644 --- a/radio/src/thirdparty/libopenui/src/filechoice.h +++ b/radio/src/thirdparty/libopenui/src/filechoice.h @@ -25,7 +25,7 @@ class FileChoice: public ChoiceBase { public: - FileChoice(Window * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function getValue, std::function setValue); + FileChoice(FormGroup * parent, const rect_t & rect, std::string folder, const char * extension, int maxlen, std::function getValue, std::function setValue); #if defined(DEBUG_WINDOWS) std::string getName() override diff --git a/radio/src/thirdparty/libopenui/src/form.cpp b/radio/src/thirdparty/libopenui/src/form.cpp index 7fa8dd593..77f195603 100644 --- a/radio/src/thirdparty/libopenui/src/form.cpp +++ b/radio/src/thirdparty/libopenui/src/form.cpp @@ -21,33 +21,12 @@ #include "bitmapbuffer.h" #include "libopenui_config.h" -FormField * FormField::current = nullptr; - -FormField::FormField(Window *parent, const rect_t &rect, uint8_t flags) : - Window(parent, rect, flags) +FormField::FormField(Window *parent, const rect_t & rect, WindowFlags windowFlags) : + Window(parent, rect, windowFlags) { - if (current) { - setPreviousField(current); - current->setNextField(this); - } - - FormWindow * form = dynamic_cast(parent); - if (form && !form->getFirstField()) - form->setFirstField(this); - - current = this; -} - -#if defined(HARDWARE_KEYS) -void FormWindow::onEvent(event_t event) -{ - TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); - - if (event == EVT_KEY_BREAK(KEY_EXIT) && first && getFocus() != first) { - first->setFocus(); - } - else { - Window::onEvent(event); + FormGroup * form = dynamic_cast(parent); + if (form) { + form->addField(this); } } @@ -57,12 +36,12 @@ void FormField::onEvent(event_t event) if (event == EVT_ROTARY_RIGHT/*EVT_KEY_BREAK(KEY_DOWN)*/) { if (next) { - next->setFocus(); + next->setFocus(SET_FOCUS_FORWARD); } } else if (event == EVT_ROTARY_LEFT/*EVT_KEY_BREAK(KEY_UP)*/) { if (previous) { - previous->setFocus(); + previous->setFocus(SET_FOCUS_BACKWARD); } } else if (event == EVT_KEY_BREAK(KEY_ENTER)) { @@ -78,24 +57,6 @@ void FormField::onEvent(event_t event) } } -void FormGroup::onEvent(event_t event) -{ - TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); - - if (event == EVT_KEY_BREAK(KEY_ENTER)) { - editMode = true; - first->setFocus(); - } - else if (event == EVT_KEY_BREAK(KEY_EXIT) && editMode) { - editMode = false; - setFocus(); - } - else { - FormField::onEvent(event); - } -} -#endif - void FormField::paint(BitmapBuffer * dc) { if (editMode) { @@ -109,12 +70,96 @@ void FormField::paint(BitmapBuffer * dc) } } -void FormGroup::paint(BitmapBuffer * dc) +void FormGroup::addField(FormField * field) { - if (!editMode && hasFocus()) { - dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR); + if (field->getWindowFlags() & FORM_DETACHED) + return; + + if (!first) { + first = field; + if (windowFlags & FORM_FORWARD_FOCUS) + link(previous, field); } - else if (!(windowFlags & BORDER_FOCUS_ONLY)) { - dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR); + if (last) + link(last, field); + last = field; + if (!(windowFlags & FORM_FORWARD_FOCUS)) + link(field, first); + else + field->setNextField(this); + if (!focusWindow && !(field->getWindowFlags() & FORM_FORWARD_FOCUS)) + field->setFocus(); +} + +void FormGroup::setFocus(uint8_t flag) +{ + if (windowFlags & FORM_FORWARD_FOCUS) { + switch (flag) { + case SET_FOCUS_FIRST: + first->setFocus(SET_FOCUS_FIRST); + break; + case SET_FOCUS_BACKWARD: + if (focusWindow == first) + previous->setFocus(SET_FOCUS_BACKWARD); + else + last->setFocus(SET_FOCUS_BACKWARD); + break; + default: + if (focusWindow == previous) + first->setFocus(); + else + next->setFocus(); + break; + } + } + else { + FormField::setFocus(); } } + +#if defined(HARDWARE_KEYS) +void FormGroup::onEvent(event_t event) +{ + TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); + + if (event == EVT_KEY_BREAK(KEY_ENTER)) { + editMode = true; + first->setFocus(); + } + else if (event == EVT_KEY_BREAK(KEY_EXIT) && editMode) { + editMode = false; + setFocus(SET_FOCUS_DEFAULT); + } + else { + FormField::onEvent(event); + } +} +#endif + +void FormGroup::paint(BitmapBuffer * dc) +{ + if (!(windowFlags & FORM_FORWARD_FOCUS)) { + if (!editMode && hasFocus()) { + dc->drawSolidRect(0, 0, rect.w, rect.h, 2, FOCUS_BGCOLOR); + } + else if (!(windowFlags & BORDER_FOCUS_ONLY)) { + dc->drawSolidRect(0, 0, rect.w, rect.h, 1, DISABLE_COLOR); + } + } +} + +#if defined(HARDWARE_KEYS) +void FormWindow::onEvent(event_t event) +{ + TRACE_WINDOWS("%s received event 0x%X", getWindowDebugString().c_str(), event); + + if (event == EVT_KEY_BREAK(KEY_EXIT) && first) { + Window * currentFocus = getFocus(); + first->setFocus(SET_FOCUS_FIRST); + if (getFocus() != currentFocus) + return; + } + + Window::onEvent(event); +} +#endif diff --git a/radio/src/thirdparty/libopenui/src/form.h b/radio/src/thirdparty/libopenui/src/form.h index bb6898834..cd9397252 100644 --- a/radio/src/thirdparty/libopenui/src/form.h +++ b/radio/src/thirdparty/libopenui/src/form.h @@ -22,11 +22,13 @@ #include "window.h" -class FormField: public Window { - friend class FormWindow; +constexpr WindowFlags FORM_FORWARD_FOCUS = WINDOW_FLAGS_LAST << 1; +constexpr WindowFlags FORM_DETACHED = WINDOW_FLAGS_LAST << 2; +constexpr WindowFlags FORM_FLAGS_LAST = FORM_DETACHED; +class FormField: public Window { public: - FormField(Window * parent, const rect_t & rect, uint8_t flags=0); + FormField(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0); inline void setNextField(FormField *field) { @@ -38,27 +40,12 @@ class FormField: public Window { previous = field; } - inline static void setCurrentField(FormField * field) - { - current = field; - } - - inline static void clearCurrentField() - { - setCurrentField(nullptr); - } - - inline static FormField * getCurrentField() - { - return current; - } - - virtual FormField * getPreviousField() + inline FormField * getPreviousField() { return previous; } - virtual FormField * getNextField() + inline FormField * getNextField() { return next; } @@ -86,7 +73,6 @@ class FormField: public Window { #endif protected: - static FormField * current; FormField * next = nullptr; FormField * previous = nullptr; bool editMode = false; @@ -94,13 +80,12 @@ class FormField: public Window { class FormGroup: public FormField { public: - FormGroup(Window * parent, const rect_t & rect, uint8_t flags=0) : - FormField(parent, rect, flags) + FormGroup(Window * parent, const rect_t & rect, WindowFlags windowflags = 0) : + FormField(parent, rect, windowflags) { - FormField::current = nullptr; } - ~FormGroup() + ~FormGroup() override { deleteChildren(); } @@ -116,33 +101,26 @@ class FormGroup: public FormField { { Window::clear(); first = nullptr; - FormField::current = nullptr; + last = nullptr; } - inline void setFirstField(FormField * field) - { - first = field; - } + void setFocus(uint8_t flag = SET_FOCUS_DEFAULT) override; - inline void setLastField(FormField * field = nullptr) - { - // by default the current field is the last one - if (!field) - field = getCurrentField(); + void addField(FormField * field); - FormField::link(field, first); - - // now the current field is the group, it will be linked to the next one - FormField::setCurrentField(this); - } - - FormField * getFirstField() + inline FormField * getFirstField() { return first; } + inline FormField * getLastField() + { + return last; + } + protected: FormField * first = nullptr; + FormField * last = nullptr; #if defined(HARDWARE_KEYS) void onEvent(event_t event) override; @@ -151,12 +129,11 @@ class FormGroup: public FormField { void paint(BitmapBuffer * dc) override; }; -class FormWindow: public Window { +class FormWindow: public FormGroup { public: - FormWindow(Window * parent, const rect_t & rect) : - Window(parent, rect) + FormWindow(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0) : + FormGroup(parent, rect, windowFlags) { - FormField::current = nullptr; } #if defined(DEBUG_WINDOWS) @@ -166,42 +143,14 @@ class FormWindow: public Window { } #endif - void clear() - { - first = nullptr; - Window::clear(); - } - - FormField * getFirstField() - { - return first; - } - - inline void setFirstField(FormField * field) - { - first = field; - field->setFocus(); - } - - inline void setLastField(FormField * field = nullptr) - { - if (!field) - field = FormField::getCurrentField(); - FormField::link(field, first); - } - protected: - -#if defined(HARDWARE_KEYS) - void onEvent(event_t event) override; -#endif - void paint(BitmapBuffer * dc) override { } - protected: - FormField * first = nullptr; +#if defined(HARDWARE_KEYS) + void onEvent(event_t event) override; +#endif }; #endif diff --git a/radio/src/thirdparty/libopenui/src/menutoolbar.cpp b/radio/src/thirdparty/libopenui/src/menutoolbar.cpp index 4ec0a27c1..37174cdf4 100644 --- a/radio/src/thirdparty/libopenui/src/menutoolbar.cpp +++ b/radio/src/thirdparty/libopenui/src/menutoolbar.cpp @@ -24,9 +24,9 @@ void MenuToolbarButton::paint(BitmapBuffer * dc) { if (checked()) { dc->drawSolidFilledRect(MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING, MENUS_TOOLBAR_BUTTON_WIDTH - 2 * MENUS_TOOLBAR_BUTTON_PADDING, FOCUS_BGCOLOR); - dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2 + 1, &picto, 1, CENTERED | FOCUS_COLOR); + dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(STDSIZE)) / 2 + 1, &picto, 1, CENTERED | FOCUS_COLOR); } else { - dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2 + 1, &picto, 1, CENTERED | DEFAULT_COLOR); + dc->drawSizedText(rect.w / 2, (rect.h - getFontHeight(STDSIZE)) / 2 + 1, &picto, 1, CENTERED | DEFAULT_COLOR); } } \ No newline at end of file diff --git a/radio/src/thirdparty/libopenui/src/menutoolbar.h b/radio/src/thirdparty/libopenui/src/menutoolbar.h index 3cf902dd0..81720d339 100644 --- a/radio/src/thirdparty/libopenui/src/menutoolbar.h +++ b/radio/src/thirdparty/libopenui/src/menutoolbar.h @@ -27,7 +27,7 @@ int getFirstAvailable(int min, int max, std::functionisValueAvailable class MenuToolbarButton: public Button { public: - MenuToolbarButton(Window * window, const rect_t & rect, char picto): + MenuToolbarButton(FormGroup * window, const rect_t & rect, char picto): #if defined(HARDWARE_TOUCH) Button(window, rect, nullptr, BUTTON_CHECKED_ON_FOCUS), #else @@ -66,16 +66,15 @@ class MenuToolbarButton: public Button { }; template -class MenuToolbar: public Window { +class MenuToolbar: public FormGroup { friend T; public: MenuToolbar(T * choice, Menu * menu): - Window(menu, MENUS_TOOLBAR_RECT, NO_SCROLLBAR), + FormGroup(menu, MENUS_TOOLBAR_RECT, NO_SCROLLBAR), choice(choice), menu(menu) { - FormField::clearCurrentField(); } ~MenuToolbar() override diff --git a/radio/src/thirdparty/libopenui/src/static.cpp b/radio/src/thirdparty/libopenui/src/static.cpp index 199787138..5b38a12b1 100644 --- a/radio/src/thirdparty/libopenui/src/static.cpp +++ b/radio/src/thirdparty/libopenui/src/static.cpp @@ -22,10 +22,10 @@ void StaticText::paint(BitmapBuffer * dc) { - if (flags & BUTTON_BACKGROUND) + if (windowFlags & BUTTON_BACKGROUND) dc->drawSolidFilledRect(0, 0, rect.w, rect.h, DISABLE_COLOR); - if (flags & CENTERED) - dc->drawText(rect.w / 2, (rect.h - getFontHeight(flags)) / 2, text.c_str(), CENTERED | flags); + if (textFlags & CENTERED) + dc->drawText(rect.w / 2, (rect.h - getFontHeight(textFlags)) / 2, text.c_str(), textFlags); else - dc->drawText(0, 0, text.c_str(), flags); + dc->drawText(0, 0, text.c_str(), textFlags); } diff --git a/radio/src/thirdparty/libopenui/src/static.h b/radio/src/thirdparty/libopenui/src/static.h index e824afbe4..20c843d30 100644 --- a/radio/src/thirdparty/libopenui/src/static.h +++ b/radio/src/thirdparty/libopenui/src/static.h @@ -25,10 +25,9 @@ class StaticText : public Window { public: - StaticText(Window * parent, const rect_t & rect, std::string text = "", LcdFlags flags = 0) : - Window(parent, rect), - text(std::move(text)), - flags(flags) + StaticText(Window * parent, const rect_t & rect, std::string text = "", WindowFlags windowFlags = 0, LcdFlags textFlags = 0) : + Window(parent, rect, windowFlags, textFlags), + text(std::move(text)) { } @@ -39,12 +38,6 @@ class StaticText : public Window { } #endif - void setFlags(LcdFlags flags) - { - this->flags = flags; - invalidate(); - } - void paint(BitmapBuffer * dc) override; void setText(std::string value) @@ -55,13 +48,12 @@ class StaticText : public Window { protected: std::string text; - LcdFlags flags; }; class Subtitle: public StaticText { public: Subtitle(Window * parent, const rect_t & rect, const char * text): - StaticText(parent, rect, text, BOLD) + StaticText(parent, rect, text, 0, BOLD) { } diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index c1516de7e..80896e6ad 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -22,16 +22,17 @@ Window * Window::focusWindow = nullptr; std::list Window::trash; -Window::Window(Window * parent, const rect_t & rect, uint8_t flags): +Window::Window(Window * parent, const rect_t & rect, WindowFlags windowFlags, LcdFlags textFlags): parent(parent), rect(rect), innerWidth(rect.w), innerHeight(rect.h), - windowFlags(flags) + windowFlags(windowFlags), + textFlags(textFlags) { if (parent) { parent->addChild(this); - if (!(flags & TRANSPARENT)) { + if (!(windowFlags & TRANSPARENT)) { invalidate(); } } @@ -108,7 +109,7 @@ void Window::clearFocus() } } -void Window::setFocus() +void Window::setFocus(uint8_t flag) { TRACE_WINDOWS("%s setFocus()", getWindowDebugString().c_str()); diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index e1cf2134c..75e55493a 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -31,23 +31,33 @@ #include "libopenui_helpers.h" #include "libopenui_config.h" +typedef uint32_t WindowFlags; + // OPAQUE/TRANSPARENT defined in WinGDI #ifndef OPAQUE #define OPAQUE 1 #define TRANSPARENT 2 #endif -constexpr uint8_t NO_SCROLLBAR = 4; -constexpr uint8_t FORWARD_SCROLL = 8; -constexpr uint8_t REFRESH_ALWAYS = 16; -constexpr uint8_t BORDER_FOCUS_ONLY = 32; -constexpr uint8_t PAINT_CHILDREN_FIRST = 64; +constexpr WindowFlags NO_SCROLLBAR = 4; +constexpr WindowFlags FORWARD_SCROLL = 8; +constexpr WindowFlags REFRESH_ALWAYS = 16; +constexpr WindowFlags BORDER_FOCUS_ONLY = 32; +constexpr WindowFlags PAINT_CHILDREN_FIRST = 64; +constexpr WindowFlags WINDOW_FLAGS_LAST = PAINT_CHILDREN_FIRST; + +enum SetFocusFlag { + SET_FOCUS_DEFAULT, + SET_FOCUS_FORWARD, + SET_FOCUS_BACKWARD, + SET_FOCUS_FIRST +}; class Window { friend class GridLayout; public: - Window(Window * parent, const rect_t & rect, uint8_t flags=0); + Window(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0, LcdFlags textFlags = 0); virtual ~Window(); @@ -86,16 +96,21 @@ class Window { return parent; } - uint8_t getWindowFlags() const + WindowFlags getWindowFlags() const { return windowFlags; } - void setWindowFlags(uint8_t flags) + void setWindowFlags(WindowFlags flags) { windowFlags = flags; } + void setTextFlags(LcdFlags flags) + { + textFlags = flags; + } + void setCloseHandler(std::function handler) { closeHandler = std::move(handler); @@ -126,7 +141,7 @@ class Window { static void clearFocus(); - void setFocus(); + virtual void setFocus(uint8_t flag = SET_FOCUS_DEFAULT); void setRect(rect_t rect) { @@ -292,7 +307,8 @@ class Window { coord_t innerHeight; coord_t scrollPositionX = 0; coord_t scrollPositionY = 0; - uint8_t windowFlags; + WindowFlags windowFlags; + LcdFlags textFlags; static Window * focusWindow; static std::list trash;