From 170fa8152e5d859e0ea6f8b4e222ee1de50fd9ed Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Sat, 14 May 2022 08:00:04 +0200 Subject: [PATCH] choice: dramatically reduce refresh frequency Done now only when a real change happened --- radio/src/thirdparty/libopenui/src/choice.cpp | 10 +++++++--- radio/src/thirdparty/libopenui/src/choice.h | 3 ++- radio/src/thirdparty/libopenui/src/filechoice.cpp | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/radio/src/thirdparty/libopenui/src/choice.cpp b/radio/src/thirdparty/libopenui/src/choice.cpp index f17d47a1e..1ed2fe7a3 100644 --- a/radio/src/thirdparty/libopenui/src/choice.cpp +++ b/radio/src/thirdparty/libopenui/src/choice.cpp @@ -21,11 +21,11 @@ #include "menu.h" #include "theme.h" -void choicePaintCallback(lv_event_t *e) +void choice_changed_cb(lv_event_t *e) { auto code = lv_event_get_code(e); - if (code == LV_EVENT_DRAW_MAIN_BEGIN) { + if (code == LV_EVENT_VALUE_CHANGED) { lv_obj_t *target = lv_event_get_target(e); if (target != nullptr) { ChoiceBase *cb = (ChoiceBase*)lv_obj_get_user_data(target); @@ -46,7 +46,7 @@ ChoiceBase::ChoiceBase(Window* parent, const rect_t& rect, ChoiceType type, lv_obj_set_layout(lvobj, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(lvobj, LV_FLEX_FLOW_ROW); - lv_obj_add_event_cb(lvobj, choicePaintCallback, LV_EVENT_DRAW_MAIN_BEGIN, lvobj); + lv_obj_add_event_cb(lvobj, choice_changed_cb, LV_EVENT_VALUE_CHANGED, lvobj); label = lv_label_create(lvobj); lv_group_t * def_group = lv_group_get_default(); @@ -99,6 +99,7 @@ Choice::Choice(Window* parent, const rect_t & rect, int vmin, int vmax, getValue(std::move(getValue)), setValue(std::move(setValue)) { + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); } Choice::Choice(Window* parent, const rect_t& rect, const char* const values[], @@ -111,6 +112,7 @@ Choice::Choice(Window* parent, const rect_t& rect, const char* const values[], setValue(std::move(setValue)) { setValues(values); + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); } Choice::Choice(Window* parent, const rect_t& rect, @@ -124,6 +126,7 @@ Choice::Choice(Window* parent, const rect_t& rect, getValue(std::move(getValue)), setValue(std::move(setValue)) { + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); } Choice::Choice(Window* parent, const rect_t& rect, const char* values, int vmin, @@ -144,6 +147,7 @@ Choice::Choice(Window* parent, const rect_t& rect, const char* values, int vmin, value += len; } } + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); } void Choice::addValue(const char * value) diff --git a/radio/src/thirdparty/libopenui/src/choice.h b/radio/src/thirdparty/libopenui/src/choice.h index 059eb0d53..5b6d6e53c 100644 --- a/radio/src/thirdparty/libopenui/src/choice.h +++ b/radio/src/thirdparty/libopenui/src/choice.h @@ -40,7 +40,7 @@ class ChoiceBase : public FormField } protected: - friend void choicePaintCallback(lv_event_t *e); + friend void choice_changed_cb(lv_event_t *e); ChoiceType type; lv_obj_t *label; virtual std::string getLabelText() { return ""; }; @@ -149,6 +149,7 @@ class Choice: public ChoiceBase { void setTextHandler(std::function handler) { textHandler = std::move(handler); + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); } void setMenuTitle(std::string value) diff --git a/radio/src/thirdparty/libopenui/src/filechoice.cpp b/radio/src/thirdparty/libopenui/src/filechoice.cpp index ba82b1e3a..0e153fd49 100644 --- a/radio/src/thirdparty/libopenui/src/filechoice.cpp +++ b/radio/src/thirdparty/libopenui/src/filechoice.cpp @@ -46,6 +46,7 @@ FileChoice::FileChoice(Window* parent, const rect_t &rect, setValue(std::move(setValue)), stripExtension(stripExtension) { + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); } std::string FileChoice::getLabelText() @@ -100,7 +101,10 @@ bool FileChoice::openMenu() int current = -1; std::string value = getValue(); for (const auto &file : files) { - menu->addLine(file, [=]() { setValue(file); }); + menu->addLine(file, [=]() { + setValue(file); + lv_event_send(lvobj, LV_EVENT_VALUE_CHANGED, nullptr); + }); // TRACE("%s %d %s %d", value.c_str(), value.size(), file.c_str(), // file.size()); if (value.compare(file) == 0) {