diff --git a/radio/src/thirdparty/libopenui/src/form.cpp b/radio/src/thirdparty/libopenui/src/form.cpp index c1b9d8a6b5a..21e8129f551 100644 --- a/radio/src/thirdparty/libopenui/src/form.cpp +++ b/radio/src/thirdparty/libopenui/src/form.cpp @@ -21,6 +21,11 @@ #include "bitmapbuffer.h" #include "themes/etx_lv_theme.h" +FormField::FormField(const rect_t& rect, LcdFlags textFlags) : + Window(rect, textFlags) +{ +} + FormField::FormField(Window* parent, const rect_t& rect, LcdFlags textFlags, LvglCreate objConstruct) : Window(parent, rect, 0, textFlags, objConstruct) @@ -28,6 +33,12 @@ FormField::FormField(Window* parent, const rect_t& rect, LcdFlags textFlags, lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); } +void FormField::setupLVGL() +{ + Window::setupLVGL(); + lv_obj_add_flag(lvobj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); +} + void FormField::setEditMode(bool newEditMode) { editMode = newEditMode; diff --git a/radio/src/thirdparty/libopenui/src/form.h b/radio/src/thirdparty/libopenui/src/form.h index 58f74fe4fe4..bd527ce6f8c 100644 --- a/radio/src/thirdparty/libopenui/src/form.h +++ b/radio/src/thirdparty/libopenui/src/form.h @@ -23,9 +23,12 @@ class FormField : public Window { public: + FormField(const rect_t& rect, LcdFlags textFlags); FormField(Window *parent, const rect_t &rect, LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr); + void setupLVGL() override; + virtual void changeEnd(bool forceChanged = false) { if (changeHandler) { diff --git a/radio/src/thirdparty/libopenui/src/numberedit.cpp b/radio/src/thirdparty/libopenui/src/numberedit.cpp index cefcb50a262..1530aa35cae 100644 --- a/radio/src/thirdparty/libopenui/src/numberedit.cpp +++ b/radio/src/thirdparty/libopenui/src/numberedit.cpp @@ -41,14 +41,19 @@ static void numberedit_cb(lv_event_t* e) NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, std::function getValue, std::function setValue, LcdFlags textFlags) : - FormField(parent, rect, textFlags, lv_textarea_create), + FormField(rect, textFlags), vmin(vmin), vmax(vmax), _getValue(std::move(getValue)), _setValue(std::move(setValue)) { lv_obj_enable_style_refresh(false); - + + // Workaround for performance issues with lv_textarea - create on top layer + // not this window then reparent to this window after setup finished + this->parent = parent; + lvobj = lv_textarea_create(lv_layer_top()); + // Do this first - before any styles are applied, otherwise it is very slow update(); @@ -61,6 +66,9 @@ NumberEdit::NumberEdit(Window* parent, const rect_t& rect, int vmin, int vmax, lv_obj_add_event_cb(lvobj, numberedit_cb, LV_EVENT_KEY, this); + lv_obj_set_parent(lvobj, parent->getLvObj()); + setupLVGL(); + lv_obj_enable_style_refresh(true); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); } diff --git a/radio/src/thirdparty/libopenui/src/textedit.cpp b/radio/src/thirdparty/libopenui/src/textedit.cpp index c9bba0c475c..1821612604f 100644 --- a/radio/src/thirdparty/libopenui/src/textedit.cpp +++ b/radio/src/thirdparty/libopenui/src/textedit.cpp @@ -27,12 +27,15 @@ TextEdit::TextEdit(Window* parent, const rect_t& rect, char* value, uint8_t length) : - FormField(parent, rect, 0, lv_textarea_create), - value(value), - length(length) + FormField(rect, 0), value(value), length(length) { lv_obj_enable_style_refresh(false); + // Workaround for performance issues with lv_textarea - create on top layer + // not this window then reparent to this window after setup finished + this->parent = parent; + lvobj = lv_textarea_create(lv_layer_top()); + // Do this first - before any styles are applied, otherwise it is very slow update(); @@ -43,6 +46,9 @@ TextEdit::TextEdit(Window* parent, const rect_t& rect, char* value, lv_textarea_set_max_length(lvobj, length); lv_textarea_set_placeholder_text(lvobj, "---"); + lv_obj_set_parent(lvobj, parent->getLvObj()); + setupLVGL(); + lv_obj_enable_style_refresh(true); lv_obj_refresh_style(lvobj, LV_PART_ANY, LV_STYLE_PROP_ANY); } diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index 4274ffc16d4..bae5aaa0b21 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -90,6 +90,14 @@ void Window::window_event_cb(lv_event_t *e) } } +// Constructor to allow lvobj to be created separately - used by NumberEdit and +// TextEdit +Window::Window(const rect_t &rect, LcdFlags textFlags) : + rect(rect), parent(nullptr), windowFlags(0), textFlags(textFlags) +{ + lvobj = nullptr; +} + Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags, LcdFlags textFlags, LvglCreate objConstruct) : rect(rect), parent(parent), windowFlags(windowFlags), textFlags(textFlags) @@ -98,6 +106,12 @@ Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags, if (objConstruct == nullptr) objConstruct = window_create; lvobj = objConstruct(lv_parent); + + Window::setupLVGL(); +} + +void Window::setupLVGL() +{ lv_obj_set_user_data(lvobj, this); lv_obj_add_event_cb(lvobj, Window::window_event_cb, LV_EVENT_ALL, nullptr); diff --git a/radio/src/thirdparty/libopenui/src/window.h b/radio/src/thirdparty/libopenui/src/window.h index a2d4dbc08a7..4c6abbbe33c 100644 --- a/radio/src/thirdparty/libopenui/src/window.h +++ b/radio/src/thirdparty/libopenui/src/window.h @@ -57,9 +57,12 @@ class FormLine; class Window { public: + Window(const rect_t& rect, LcdFlags textFlags); Window(Window *parent, const rect_t &rect, WindowFlags windowFlags = 0, LcdFlags textFlags = 0, LvglCreate objConstruct = nullptr); + virtual void setupLVGL(); + virtual ~Window(); #if defined(DEBUG_WINDOWS)