From 661542a47416767d8c40ffa514abeaed893e20a1 Mon Sep 17 00:00:00 2001 From: philmoz Date: Mon, 16 Oct 2023 16:38:41 +1100 Subject: [PATCH] feat(color): Add tick marks to Sliders with less than 10 steps (#4125) Also update Slider style so not so overwhelmingly large --- .../src/gui/colorlcd/themes/etx_lv_theme.cpp | 20 ++++++++------- radio/src/thirdparty/libopenui/src/slider.cpp | 25 ++++++++++++++++--- radio/src/thirdparty/libopenui/src/slider.h | 3 +++ 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp b/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp index a62b5e1db9d..af55bb146ad 100644 --- a/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp +++ b/radio/src/gui/colorlcd/themes/etx_lv_theme.cpp @@ -257,11 +257,14 @@ static void style_init(void) // Slider lv_style_init(&styles.slider_main); lv_style_set_bg_opa(&styles.slider_main, LV_OPA_100); - lv_style_set_pad_all(&styles.slider_main, 6); lv_style_init(&styles.slider_knob); lv_style_set_bg_opa(&styles.slider_knob, LV_OPA_COVER); - lv_style_set_border_width(&styles.slider_knob, 1); - lv_style_set_pad_all(&styles.slider_knob, lv_disp_dpx(theme.disp, 6)); + lv_style_set_border_width(&styles.slider_knob, 2); + lv_style_set_pad_top(&styles.slider_knob, 9); + lv_style_set_pad_bottom(&styles.slider_knob, 9); + lv_style_set_pad_left(&styles.slider_knob, 4); + lv_style_set_pad_right(&styles.slider_knob, 4); + lv_style_set_radius(&styles.slider_knob, 4); // Choice lv_style_init(&styles.choice_main); @@ -591,17 +594,16 @@ void etx_slider_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj) lv_obj_add_style(obj, &styles.slider_main, LV_PART_MAIN); lv_obj_add_style(obj, &styles.slider_knob, LV_PART_KNOB); lv_obj_add_style(obj, &styles.circle, LV_PART_MAIN); - lv_obj_add_style(obj, &styles.circle, LV_PART_KNOB); lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_MAIN | LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.bg_color_focus, + lv_obj_add_style(obj, &styles.bg_color_edit, LV_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_EDITED); lv_obj_add_style(obj, &styles.bg_color_focus, LV_PART_INDICATOR | LV_STATE_FOCUSED); - lv_obj_add_style(obj, &styles.bg_color_focus, - LV_PART_INDICATOR | LV_STATE_FOCUSED | LV_STATE_EDITED); lv_obj_add_style(obj, &styles.bg_color_edit, - LV_PART_KNOB | LV_STATE_FOCUSED | LV_STATE_EDITED); + LV_PART_INDICATOR | LV_STATE_FOCUSED | LV_STATE_EDITED); + lv_obj_add_style(obj, &styles.focussed, + LV_PART_KNOB | LV_STATE_FOCUSED); } void etx_btnmatrix_constructor(const lv_obj_class_t* class_p, lv_obj_t* obj) @@ -788,7 +790,7 @@ const lv_obj_class_t etx_slider_class = { .user_data = nullptr, .event_cb = nullptr, .width_def = 0, - .height_def = 16, + .height_def = 8, .editable = LV_OBJ_CLASS_EDITABLE_INHERIT, .group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT, .instance_size = sizeof(lv_slider_t), diff --git a/radio/src/thirdparty/libopenui/src/slider.cpp b/radio/src/thirdparty/libopenui/src/slider.cpp index 1223711b019..d63e877ac56 100644 --- a/radio/src/thirdparty/libopenui/src/slider.cpp +++ b/radio/src/thirdparty/libopenui/src/slider.cpp @@ -17,9 +17,9 @@ */ #include "slider.h" -#include "theme.h" #include "LvglWrapper.h" +#include "theme.h" static void slider_changed_cb(lv_event_t* e) { @@ -41,9 +41,11 @@ Slider::Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax, _getValue(std::move(getValue)), _setValue(std::move(setValue)) { - padAll(7); + padTop(9); + padLeft(8); + padRight(8); - auto slider = (new FormField(this, rect_t{}, 0, 0, etx_slider_create))->getLvObj(); + slider = (new FormField(this, rect_t{}, 0, 0, etx_slider_create))->getLvObj(); lv_obj_set_width(slider, lv_pct(100)); lv_obj_add_event_cb(slider, slider_changed_cb, LV_EVENT_VALUE_CHANGED, this); @@ -52,3 +54,20 @@ Slider::Slider(Window* parent, coord_t width, int32_t vmin, int32_t vmax, if (_getValue != nullptr) lv_slider_set_value(slider, _getValue(), LV_ANIM_OFF); } + +void Slider::paint(BitmapBuffer* dc) +{ + coord_t w = lv_obj_get_width(slider); + coord_t x = (lv_obj_get_width(lvobj) - w) / 2 - 1; + int range = vmax - vmin; + LcdFlags color = lv_obj_has_state(slider, LV_STATE_EDITED) ? COLOR_THEME_EDIT + : lv_obj_has_state(slider, LV_STATE_FOCUSED) + ? COLOR_THEME_FOCUS + : COLOR_THEME_SECONDARY1; + + if (range < 10) { + for (int n = 1; n < range; n += 1) { + dc->drawSolidRect(x + (w * n) / range, 6, 2, 2, 1, color); + } + } +} diff --git a/radio/src/thirdparty/libopenui/src/slider.h b/radio/src/thirdparty/libopenui/src/slider.h index b2991090387..f772dc43850 100644 --- a/radio/src/thirdparty/libopenui/src/slider.h +++ b/radio/src/thirdparty/libopenui/src/slider.h @@ -35,9 +35,12 @@ class Slider : public Window if (_setValue != nullptr) _setValue(limit(vmin, value, vmax)); } + void paint(BitmapBuffer *) override; + protected: int vmin; int vmax; + lv_obj_t* slider; std::function _getValue; std::function _setValue; };