Skip to content

Commit

Permalink
Workaround for lv_textarea performance issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Dec 22, 2023
1 parent 5a0e89e commit b4340dc
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 5 deletions.
11 changes: 11 additions & 0 deletions radio/src/thirdparty/libopenui/src/form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,24 @@
#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)
{
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;
Expand Down
3 changes: 3 additions & 0 deletions radio/src/thirdparty/libopenui/src/form.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 10 additions & 2 deletions radio/src/thirdparty/libopenui/src/numberedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int()> getValue,
std::function<void(int)> 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();

Expand All @@ -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);
}
Expand Down
12 changes: 9 additions & 3 deletions radio/src/thirdparty/libopenui/src/textedit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
Expand Down
14 changes: 14 additions & 0 deletions radio/src/thirdparty/libopenui/src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions radio/src/thirdparty/libopenui/src/window.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b4340dc

Please sign in to comment.