From 2a0bb66dafe4c58339895c950b3c8c3a4268c55d Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 9 Feb 2022 12:31:22 +0100 Subject: [PATCH] WIP: default theme --- .../thirdparty/libopenui/src/basenumberedit.h | 21 +++++---- radio/src/thirdparty/libopenui/src/button.cpp | 43 ++++++++++++------- radio/src/thirdparty/libopenui/src/button.h | 17 ++++---- .../src/thirdparty/libopenui/src/checkbox.cpp | 38 ++++++++-------- radio/src/thirdparty/libopenui/src/form.cpp | 8 ++-- radio/src/thirdparty/libopenui/src/form.h | 8 ++-- radio/src/thirdparty/libopenui/src/menu.cpp | 6 +-- .../thirdparty/libopenui/src/numberedit.cpp | 3 +- radio/src/thirdparty/libopenui/src/slider.cpp | 4 +- .../src/thirdparty/libopenui/src/textedit.cpp | 3 +- radio/src/thirdparty/libopenui/src/window.cpp | 19 ++------ radio/src/thirdparty/libopenui/src/window.h | 7 ++- 12 files changed, 89 insertions(+), 88 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/basenumberedit.h b/radio/src/thirdparty/libopenui/src/basenumberedit.h index 4b9b4939b..e0911ccb1 100644 --- a/radio/src/thirdparty/libopenui/src/basenumberedit.h +++ b/radio/src/thirdparty/libopenui/src/basenumberedit.h @@ -25,15 +25,18 @@ class BaseNumberEdit: public FormField { public: - BaseNumberEdit(Window * parent, const rect_t &rect, int vmin, int vmax, - std::function getValue, std::function setValue = nullptr, WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr): - FormField(parent, rect, windowFlags, textFlags, factory), - vmin(vmin), - vmax(vmax), - _getValue(std::move(getValue)), - _setValue(std::move(setValue)) - { - } + BaseNumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, + std::function getValue, + std::function setValue = nullptr, + WindowFlags windowFlags = 0, LcdFlags textFlags = 0, + LvglCreate objConstruct = nullptr) : + FormField(parent, rect, windowFlags, textFlags, objConstruct), + vmin(vmin), + vmax(vmax), + _getValue(std::move(getValue)), + _setValue(std::move(setValue)) + { + } void setMin(int value) { diff --git a/radio/src/thirdparty/libopenui/src/button.cpp b/radio/src/thirdparty/libopenui/src/button.cpp index 8d8bf6239..e40fbabd2 100644 --- a/radio/src/thirdparty/libopenui/src/button.cpp +++ b/radio/src/thirdparty/libopenui/src/button.cpp @@ -81,13 +81,12 @@ void Button::checkEvents() } lv_style_t style_btn; -LvglWidgetFactory textButtonFactory = {lv_btn_create, nullptr}; TextButton::TextButton(FormGroup* parent, const rect_t& rect, std::string text, - std::function pressHandler, - WindowFlags windowFlags, - LcdFlags textFlags) : - Button(parent, rect, std::move(pressHandler), windowFlags, textFlags, &textButtonFactory), + std::function pressHandler, + WindowFlags windowFlags, LcdFlags textFlags) : + Button(parent, rect, std::move(pressHandler), windowFlags, textFlags, + lv_btn_create), text(std::move(text)) { setTextFlags(textFlags | COLOR_THEME_PRIMARY1); @@ -97,25 +96,37 @@ TextButton::TextButton(FormGroup* parent, const rect_t& rect, std::string text, lv_style_init(&style_btn); lv_style_set_radius(&style_btn, 0); - lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), LV_PART_MAIN); - lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE), LV_PART_MAIN | LV_STATE_CHECKED); - lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE), LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED); - lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_MAIN | LV_STATE_FOCUSED); + + //TODO: use 'style_btn' instead of local style + lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), + LV_PART_MAIN); + lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE), + LV_PART_MAIN | LV_STATE_CHECKED); + lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_ACTIVE), + LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED); + lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), + LV_PART_MAIN | LV_STATE_FOCUSED); lv_obj_set_style_bg_opa(lvobj, LV_OPA_100, LV_PART_MAIN); lv_obj_set_style_border_width(lvobj, 0, LV_PART_MAIN); - - lv_obj_set_style_border_width(lvobj, 1, LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED); - lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED); - lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_MAIN | LV_STATE_FOCUSED); + lv_obj_set_style_border_width( + lvobj, 1, LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED); + lv_obj_set_style_border_color( + lvobj, makeLvColor(COLOR_THEME_FOCUS), + LV_PART_MAIN | LV_STATE_CHECKED | LV_STATE_FOCUSED); - lv_obj_add_style(lvobj, &style_btn,0); + lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), + LV_PART_MAIN | LV_STATE_FOCUSED); + + lv_obj_add_style(lvobj, &style_btn, 0); label = lv_label_create(lvobj); lv_label_set_text(label, this->text.c_str()); lv_obj_center(label); - lv_obj_set_style_text_color(label, makeLvColor(this->getTextFlags()), LV_PART_MAIN); - lv_obj_set_style_text_color(label, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_MAIN | LV_STATE_FOCUSED); + lv_obj_set_style_text_color(label, makeLvColor(this->getTextFlags()), + LV_PART_MAIN); + lv_obj_set_style_text_color(label, makeLvColor(COLOR_THEME_PRIMARY2), + LV_PART_MAIN | LV_STATE_FOCUSED); } void IconButton::paint(BitmapBuffer * dc) diff --git a/radio/src/thirdparty/libopenui/src/button.h b/radio/src/thirdparty/libopenui/src/button.h index cc2ab19cf..695ccf30e 100644 --- a/radio/src/thirdparty/libopenui/src/button.h +++ b/radio/src/thirdparty/libopenui/src/button.h @@ -28,14 +28,15 @@ constexpr WindowFlags BUTTON_CHECKED_ON_FOCUS = FORM_FLAGS_LAST << 3u; class Button: public FormField { public: - Button(FormGroup* parent, const rect_t& rect, - std::function pressHandler = nullptr, - WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr) : - FormField(parent, rect, windowFlags, textFlags, factory), - pressHandler(std::move(pressHandler)) - { - lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN); - } + Button(FormGroup* parent, const rect_t& rect, + std::function pressHandler = nullptr, + WindowFlags windowFlags = 0, LcdFlags textFlags = 0, + LvglCreate objConstruct = nullptr) : + FormField(parent, rect, windowFlags, textFlags, objConstruct), + pressHandler(std::move(pressHandler)) + { + lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN); + } #if defined(DEBUG_WINDOWS) std::string getName() const override diff --git a/radio/src/thirdparty/libopenui/src/checkbox.cpp b/radio/src/thirdparty/libopenui/src/checkbox.cpp index 43ed81df0..2e914fe79 100644 --- a/radio/src/thirdparty/libopenui/src/checkbox.cpp +++ b/radio/src/thirdparty/libopenui/src/checkbox.cpp @@ -20,25 +20,22 @@ #include "checkbox.h" #include "theme.h" -LvglWidgetFactory checkBoxFactory = { lv_checkbox_create, nullptr }; lv_style_t style_indicator; lv_style_t style_edit; - -static void checkbox_event_handler(lv_event_t * e) +static void checkbox_event_handler(lv_event_t* e) { - lv_obj_t * target = lv_event_get_target(e); - CheckBox* cb = (CheckBox *)lv_obj_get_user_data(target); - + lv_obj_t* target = lv_event_get_target(e); + CheckBox* cb = (CheckBox*)lv_obj_get_user_data(target); + onKeyPress(); - if (cb) - cb->setValue(lv_obj_get_state(target) & LV_STATE_CHECKED); + if (cb) cb->setValue(lv_obj_get_state(target) & LV_STATE_CHECKED); } CheckBox::CheckBox(Window* parent, const rect_t& rect, std::function getValue, std::function setValue, WindowFlags flags) : - FormField(parent, rect, flags, 0, &checkBoxFactory), + FormField(parent, rect, flags, 0, lv_checkbox_create), _getValue(std::move(getValue)), _setValue(std::move(setValue)) { @@ -46,23 +43,30 @@ CheckBox::CheckBox(Window* parent, const rect_t& rect, setWidth(size); setHeight(size); + //TODO: migrate to default theme + // BORDER - lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), LV_PART_INDICATOR); + lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY2), + LV_PART_INDICATOR); lv_obj_set_style_border_width(lvobj, 1, LV_PART_INDICATOR); - lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), LV_PART_INDICATOR | LV_STATE_FOCUSED); + lv_obj_set_style_border_color(lvobj, makeLvColor(COLOR_THEME_FOCUS), + LV_PART_INDICATOR | LV_STATE_FOCUSED); lv_obj_set_style_border_width(lvobj, 2, LV_PART_INDICATOR | LV_STATE_FOCUSED); // UNCHECKED BACKGROUND - lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_INDICATOR); - lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), LV_PART_INDICATOR | LV_STATE_CHECKED); + lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), + LV_PART_INDICATOR); + lv_obj_set_style_bg_color(lvobj, makeLvColor(COLOR_THEME_PRIMARY2), + LV_PART_INDICATOR | LV_STATE_CHECKED); - lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1), LV_PART_INDICATOR | LV_STATE_CHECKED); + lv_obj_set_style_text_color(lvobj, makeLvColor(COLOR_THEME_SECONDARY1), + LV_PART_INDICATOR | LV_STATE_CHECKED); - if (_getValue()) - lv_obj_add_state(lvobj, LV_STATE_CHECKED); + if (_getValue()) lv_obj_add_state(lvobj, LV_STATE_CHECKED); - lv_obj_add_event_cb(lvobj, checkbox_event_handler, LV_EVENT_VALUE_CHANGED, this); + lv_obj_add_event_cb(lvobj, checkbox_event_handler, LV_EVENT_VALUE_CHANGED, + this); } #if defined(HARDWARE_KEYS) diff --git a/radio/src/thirdparty/libopenui/src/form.cpp b/radio/src/thirdparty/libopenui/src/form.cpp index a09a1005d..f26f3a608 100644 --- a/radio/src/thirdparty/libopenui/src/form.cpp +++ b/radio/src/thirdparty/libopenui/src/form.cpp @@ -27,8 +27,8 @@ static lv_style_t edit_style; FormField::FormField(Window* parent, const rect_t& rect, WindowFlags windowFlags, LcdFlags textFlags, - LvglWidgetFactory* factory) : - Window(parent, rect, windowFlags, textFlags, factory) + LvglCreate objConstruct) : + Window(parent, rect, windowFlags, textFlags, objConstruct) { if (!(windowFlags & NO_FOCUS)) { auto* form = dynamic_cast(parent); @@ -113,8 +113,8 @@ static lv_style_t border_style; static lv_style_t focus_border_style; FormGroup::FormGroup(Window* parent, const rect_t& rect, - WindowFlags windowflags, LvglWidgetFactory* factory) : - FormField(parent, rect, windowflags) + WindowFlags windowflags, LvglCreate objConstruct) : + FormField(parent, rect, windowflags, 0, objConstruct) { lv_obj_set_style_bg_opa(lvobj, LV_OPA_TRANSP, LV_PART_MAIN); diff --git a/radio/src/thirdparty/libopenui/src/form.h b/radio/src/thirdparty/libopenui/src/form.h index 10aab8d6e..0bdb95855 100644 --- a/radio/src/thirdparty/libopenui/src/form.h +++ b/radio/src/thirdparty/libopenui/src/form.h @@ -31,7 +31,7 @@ class FormField : public Window { public: FormField(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0, - LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr); + LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr); virtual void changeEnd(bool forceChanged = false) { @@ -118,7 +118,7 @@ class FormGroup : public FormField { public: FormGroup(Window *parent, const rect_t &rect, WindowFlags windowflags = 0, - LvglWidgetFactory *factory = nullptr); + LvglCreate objConstruct = nullptr); #if defined(DEBUG_WINDOWS) std::string getName() const override { return "FormGroup"; } @@ -180,8 +180,8 @@ class FormWindow : public FormGroup { public: FormWindow(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0, - LvglWidgetFactory *factory = nullptr) : - FormGroup(parent, rect, windowFlags, factory) + LvglCreate objConstruct = nullptr) : + FormGroup(parent, rect, windowFlags, objConstruct) { } diff --git a/radio/src/thirdparty/libopenui/src/menu.cpp b/radio/src/thirdparty/libopenui/src/menu.cpp index 5f0f75d2d..0e17c8a62 100644 --- a/radio/src/thirdparty/libopenui/src/menu.cpp +++ b/radio/src/thirdparty/libopenui/src/menu.cpp @@ -21,10 +21,6 @@ #include "font.h" #include "theme.h" -LvglWidgetFactory menuBodyWidgetFactory = { [] (lv_obj_t *parent) { - return lv_list_create(parent); -}, nullptr}; - void menuBodyEventCallback(lv_event_t *e) { auto code = lv_event_get_code(e); @@ -53,7 +49,7 @@ void menuBodyEventCallback(lv_event_t *e) } MenuBody::MenuBody(Window * parent, const rect_t & rect): - Window(parent, rect, OPAQUE, 0, &menuBodyWidgetFactory) + Window(parent, rect, OPAQUE, 0, lv_list_create) { setPageHeight(MENUS_LINE_HEIGHT); } diff --git a/radio/src/thirdparty/libopenui/src/numberedit.cpp b/radio/src/thirdparty/libopenui/src/numberedit.cpp index 419bccd39..8ac861805 100644 --- a/radio/src/thirdparty/libopenui/src/numberedit.cpp +++ b/radio/src/thirdparty/libopenui/src/numberedit.cpp @@ -24,7 +24,6 @@ #endif -static LvglWidgetFactory numberEditFactory = { lv_textarea_create, nullptr }; static lv_style_t style_main; static lv_style_t style_edit; @@ -64,7 +63,7 @@ NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, WindowFlags windowFlags, LcdFlags textFlags) : BaseNumberEdit(parent, rect, vmin, vmax, std::move(getValue), std::move(setValue), windowFlags, textFlags, - &numberEditFactory) + lv_textarea_create) { // properties lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF); diff --git a/radio/src/thirdparty/libopenui/src/slider.cpp b/radio/src/thirdparty/libopenui/src/slider.cpp index 26a5feac9..34807c0a4 100644 --- a/radio/src/thirdparty/libopenui/src/slider.cpp +++ b/radio/src/thirdparty/libopenui/src/slider.cpp @@ -44,8 +44,6 @@ static lv_style_t style_knob; static lv_style_t style_focused; static lv_style_t style_edit; -static LvglWidgetFactory sliderFactory = { lv_slider_create, nullptr }; - constexpr coord_t SLIDER_PADDING = 6; Slider::Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax, @@ -54,7 +52,7 @@ Slider::Slider(Window* parent, const rect_t& rect, int32_t vmin, int32_t vmax, FormField(parent, {rect.x + SLIDER_PADDING, rect.y + SLIDER_PADDING, rect.w - 2 * SLIDER_PADDING, rect.h - 2 * SLIDER_PADDING}, - 0, 0, &sliderFactory), + 0, 0, lv_slider_create), vmin(vmin), vmax(vmax), _getValue(std::move(getValue)), diff --git a/radio/src/thirdparty/libopenui/src/textedit.cpp b/radio/src/thirdparty/libopenui/src/textedit.cpp index 58c73aa84..9b4f67aaf 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.cpp +++ b/radio/src/thirdparty/libopenui/src/textedit.cpp @@ -44,13 +44,12 @@ static lv_style_t style_main; static lv_style_t style_edit; -static LvglWidgetFactory textEditFactory = { lv_textarea_create, nullptr }; TextEdit::TextEdit(Window *parent, const rect_t &rect, char *value, uint8_t length, LcdFlags windowFlags, const char *_extra_chars) : FormField(parent, {rect.x, rect.y, rect.w, rect.h - 2}, windowFlags, 0, - &textEditFactory), + lv_textarea_create), value(value), length(length) { diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 260a38448..0849526b4 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -137,19 +137,8 @@ static void window_event_cb(lv_event_t * e) } } -LvglWidgetFactory windowFactory = LvglWidgetFactory( - [] (lv_obj_t *parent) { - return lv_obj_create(parent); - }, - [] (LvglWidgetFactory *factory) { - lv_style_set_pad_all(&factory->style, 0); - lv_style_set_bg_opa(&factory->style, LV_OPA_TRANSP); - lv_style_set_border_width(&factory->style, 0); - lv_style_set_radius(&factory->style, 0); - }); - Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags, - LcdFlags textFlags, LvglWidgetFactory *factory) : + LcdFlags textFlags, LvglCreate objConstruct) : parent(parent), rect(rect), innerWidth(rect.w), @@ -158,11 +147,9 @@ Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags, textFlags(textFlags) { lv_obj_t *lvParent = parent != nullptr ? parent->lvobj : nullptr; - lvobj = (factory == nullptr) ? - windowFactory.construct(lvParent) : - factory->construct(lvParent); + lvobj = (objConstruct == nullptr) ? lv_obj_create(lvParent) + : objConstruct(lvParent); - lv_obj_add_style(lvobj, &windowFactory.style, LV_PART_MAIN); lv_obj_set_pos(lvobj, rect.x, rect.y); lv_obj_set_size(lvobj, rect.w, rect.h); lv_obj_set_user_data(lvobj, this); diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index 78e5c148b..3d66933a9 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -59,14 +59,17 @@ enum SetFocusFlag SET_FOCUS_FIRST }; +typedef lv_obj_t *(*LvglCreate)(lv_obj_t *); + class Window { friend class GridLayout; public: - Window(Window * parent, const rect_t & rect, WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglWidgetFactory *factory = nullptr); + Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0, + LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr); - virtual ~Window(); + virtual ~Window(); #if defined(DEBUG_WINDOWS) virtual std::string getName() const