From 5a0e89e12b6853ec83108c68d773bfd72c0d378c Mon Sep 17 00:00:00 2001 From: philmoz Date: Fri, 22 Dec 2023 12:05:59 +1100 Subject: [PATCH] Only add scrollbar styles when scrollbar is needed. --- radio/src/gui/colorlcd/curveedit.cpp | 2 +- radio/src/gui/colorlcd/input_edit.cpp | 2 +- radio/src/gui/colorlcd/model_select.cpp | 4 ++-- radio/src/gui/colorlcd/page.cpp | 2 +- radio/src/gui/colorlcd/radio_theme.cpp | 2 +- radio/src/gui/colorlcd/tabsgroup.cpp | 2 +- radio/src/gui/colorlcd/themes/etx_lv_theme.cpp | 5 +++-- radio/src/gui/colorlcd/view_text.cpp | 4 ++-- radio/src/thirdparty/libopenui/src/dialog.cpp | 1 - radio/src/thirdparty/libopenui/src/menu.cpp | 2 +- radio/src/thirdparty/libopenui/src/table.cpp | 2 +- radio/src/thirdparty/libopenui/src/window.cpp | 10 ++-------- 12 files changed, 16 insertions(+), 22 deletions(-) diff --git a/radio/src/gui/colorlcd/curveedit.cpp b/radio/src/gui/colorlcd/curveedit.cpp index 83fcb87f582..3feaffc0b0b 100644 --- a/radio/src/gui/colorlcd/curveedit.cpp +++ b/radio/src/gui/colorlcd/curveedit.cpp @@ -36,7 +36,7 @@ CurveDataEdit::CurveDataEdit(Window* parent, const rect_t& rect, uint8_t index) : Window(parent, rect), index(index) { - lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(lvobj); } #if LCD_W > LCD_H diff --git a/radio/src/gui/colorlcd/input_edit.cpp b/radio/src/gui/colorlcd/input_edit.cpp index 00b64da62e7..1e916e1bf72 100644 --- a/radio/src/gui/colorlcd/input_edit.cpp +++ b/radio/src/gui/colorlcd/input_edit.cpp @@ -58,7 +58,7 @@ InputEditWindow::InputEditWindow(int8_t input, uint8_t index) : auto box = new Window(&body, rect_t{}); auto box_obj = box->getLvObj(); lv_obj_set_flex_grow(box_obj, 2); - lv_obj_set_scrollbar_mode(box->getLvObj(), LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(box_obj); #if LCD_H > LCD_W // portrait box->setWidth(body.width() - 2 * lv_dpx(8)); diff --git a/radio/src/gui/colorlcd/model_select.cpp b/radio/src/gui/colorlcd/model_select.cpp index d37071f57fb..eb757cfc6c3 100644 --- a/radio/src/gui/colorlcd/model_select.cpp +++ b/radio/src/gui/colorlcd/model_select.cpp @@ -666,8 +666,8 @@ void ModelLabelsWindow::buildBody(Window *window) lblselector->setMultiSelect(true); lblselector->setSelected(modelslabels.filteredLabels()); updateFilteredLabels(modelslabels.filteredLabels(), false); - lv_obj_set_scrollbar_mode(lbl_obj, LV_SCROLLBAR_MODE_AUTO); - lv_obj_set_scrollbar_mode(mdl_obj, LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(lbl_obj); + etx_scrollbar(mdl_obj); lblselector->setMultiSelectHandler([=](std::set selected, std::set oldselection) { diff --git a/radio/src/gui/colorlcd/page.cpp b/radio/src/gui/colorlcd/page.cpp index 403f5446cdb..2db8c989a2c 100644 --- a/radio/src/gui/colorlcd/page.cpp +++ b/radio/src/gui/colorlcd/page.cpp @@ -63,7 +63,7 @@ Page::Page(EdgeTxIcon icon, PaddingSize padding) : etx_solid_bg(lvobj); lv_obj_set_style_max_height(body.getLvObj(), LCD_H - MENU_HEADER_HEIGHT, LV_PART_MAIN); - lv_obj_set_scrollbar_mode(body.getLvObj(), LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(body.getLvObj()); Layer::back()->hide(); Layer::push(this); diff --git a/radio/src/gui/colorlcd/radio_theme.cpp b/radio/src/gui/colorlcd/radio_theme.cpp index 2a42915e071..bf5d524c947 100644 --- a/radio/src/gui/colorlcd/radio_theme.cpp +++ b/radio/src/gui/colorlcd/radio_theme.cpp @@ -601,7 +601,7 @@ void ThemeSetupPage::setupListbox(Window *window, rect_t r, ThemePersistance *tp) { listBox = new ListBox(window, r, tp->getNames()); - lv_obj_set_scrollbar_mode(listBox->getLvObj(), LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(listBox->getLvObj()); listBox->setAutoEdit(true); listBox->setSelected(currentTheme); listBox->setActiveItem(tp->getThemeIndex()); diff --git a/radio/src/gui/colorlcd/tabsgroup.cpp b/radio/src/gui/colorlcd/tabsgroup.cpp index 1b0233e37e3..0a30558706c 100644 --- a/radio/src/gui/colorlcd/tabsgroup.cpp +++ b/radio/src/gui/colorlcd/tabsgroup.cpp @@ -259,7 +259,7 @@ TabsGroup::TabsGroup(EdgeTxIcon icon) : { etx_solid_bg(lvobj); lv_obj_set_style_max_height(body.getLvObj(), MENU_BODY_HEIGHT, LV_PART_MAIN); - lv_obj_set_scrollbar_mode(body.getLvObj(), LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(body.getLvObj()); Layer::back()->hide(); Layer::push(this); diff --git a/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp b/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp index 0f00ffa3f5a..f9e1cc0cbdc 100644 --- a/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp +++ b/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp @@ -70,6 +70,7 @@ LV_STYLE_CONST_SINGLE_INIT(EdgeTxStyles::pad_left_2, LV_STYLE_PAD_LEFT, 2); // Scrollbar const lv_style_const_prop_t scrollbar_props[] = { + LV_STYLE_CONST_BG_OPA(LV_OPA_50), LV_STYLE_CONST_PAD_TOP(3), LV_STYLE_CONST_PAD_BOTTOM(3), LV_STYLE_CONST_PAD_LEFT(3), LV_STYLE_CONST_PAD_RIGHT(3), LV_STYLE_CONST_WIDTH(4), LV_STYLE_PROP_INV, @@ -471,7 +472,7 @@ void etx_padding(lv_obj_t* obj, PaddingSize padding, etx_obj_add_style(obj, styles->pad_large, selector); break; default: - etx_obj_add_style(obj, styles->pad_zero, selector); + // etx_obj_add_style(obj, styles->pad_zero, selector); break; }; } @@ -486,11 +487,11 @@ void etx_std_style(lv_obj_t* obj, lv_style_selector_t selector, void etx_scrollbar(lv_obj_t* obj) { - etx_obj_add_style(obj, styles->bg_opacity_50, LV_PART_SCROLLBAR); etx_obj_add_style(obj, styles->scrollbar, LV_PART_SCROLLBAR); etx_obj_add_style(obj, styles->bg_color_grey, LV_PART_SCROLLBAR); etx_obj_add_style(obj, styles->bg_opacity_cover, LV_PART_SCROLLBAR | LV_STATE_SCROLLED); + lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_AUTO); } void etx_textarea_style(lv_obj_t* obj) diff --git a/radio/src/gui/colorlcd/view_text.cpp b/radio/src/gui/colorlcd/view_text.cpp index d677a0fc305..a67925d4279 100644 --- a/radio/src/gui/colorlcd/view_text.cpp +++ b/radio/src/gui/colorlcd/view_text.cpp @@ -135,7 +135,7 @@ void ViewTextWindow::buildBody(Window* window) lv_obj_add_flag( obj, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_SCROLL_WITH_ARROW | LV_OBJ_FLAG_SCROLL_MOMENTUM | LV_OBJ_FLAG_CLICK_FOCUSABLE); - lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(obj); // prevents resetting the group's edit mode lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICK_FOCUSABLE); @@ -333,7 +333,7 @@ class ViewChecklistWindow : public ViewTextWindow lv_obj_add_flag( obj, LV_OBJ_FLAG_SCROLLABLE | LV_OBJ_FLAG_SCROLL_WITH_ARROW | LV_OBJ_FLAG_SCROLL_MOMENTUM | LV_OBJ_FLAG_CLICK_FOCUSABLE); - lv_obj_set_scrollbar_mode(obj, LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(obj); // prevents resetting the group's edit mode lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICK_FOCUSABLE); diff --git a/radio/src/thirdparty/libopenui/src/dialog.cpp b/radio/src/thirdparty/libopenui/src/dialog.cpp index 21c7ae9da64..d0c51d784ce 100644 --- a/radio/src/thirdparty/libopenui/src/dialog.cpp +++ b/radio/src/thirdparty/libopenui/src/dialog.cpp @@ -30,7 +30,6 @@ class BaseDialogForm : public Window public: BaseDialogForm(Window* parent, lv_coord_t width) : Window(parent, rect_t{}) { - lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_AUTO); etx_scrollbar(lvobj); padAll(PAD_MEDIUM); setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_MEDIUM, width, LV_SIZE_CONTENT); diff --git a/radio/src/thirdparty/libopenui/src/menu.cpp b/radio/src/thirdparty/libopenui/src/menu.cpp index f40b018f7a0..5c9e84150af 100644 --- a/radio/src/thirdparty/libopenui/src/menu.cpp +++ b/radio/src/thirdparty/libopenui/src/menu.cpp @@ -73,7 +73,7 @@ class MenuBody : public TableField // Allow encoder acceleration lv_obj_add_flag(lvobj, LV_OBJ_FLAG_ENCODER_ACCEL); // Add scroll bar if needed - lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(lvobj); setColumnWidth(0, rect.w); diff --git a/radio/src/thirdparty/libopenui/src/table.cpp b/radio/src/thirdparty/libopenui/src/table.cpp index 0468680da00..df4476d5143 100644 --- a/radio/src/thirdparty/libopenui/src/table.cpp +++ b/radio/src/thirdparty/libopenui/src/table.cpp @@ -173,7 +173,7 @@ static void table_event(const lv_obj_class_t* class_p, lv_event_t* e) TableField::TableField(Window* parent, const rect_t& rect) : Window(parent, rect, OPAQUE, 0, table_create) { - lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_AUTO); + etx_scrollbar(lvobj); lv_table_set_col_cnt(lvobj, 1); } diff --git a/radio/src/thirdparty/libopenui/src/window.cpp b/radio/src/thirdparty/libopenui/src/window.cpp index a7b9de1ab73..4274ffc16d4 100644 --- a/radio/src/thirdparty/libopenui/src/window.cpp +++ b/radio/src/thirdparty/libopenui/src/window.cpp @@ -26,15 +26,9 @@ std::list Window::trash; -static void window_base_constructor(const lv_obj_class_t *class_p, - lv_obj_t *obj) -{ - etx_scrollbar(obj); -} - const lv_obj_class_t window_base_class = { .base_class = &lv_obj_class, - .constructor_cb = window_base_constructor, + .constructor_cb = nullptr, .destructor_cb = nullptr, .user_data = nullptr, .event_cb = nullptr, @@ -111,7 +105,7 @@ Window::Window(Window *parent, const rect_t &rect, WindowFlags windowFlags, if (rect.w) lv_obj_set_width(lvobj, rect.w); if (rect.h) lv_obj_set_height(lvobj, rect.h); - lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF); + // lv_obj_set_scrollbar_mode(lvobj, LV_SCROLLBAR_MODE_OFF); lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_SCROLL_ELASTIC); if (parent) {