Skip to content

Commit

Permalink
feat(color): Add tick marks to Sliders with less than 10 steps (EdgeT…
Browse files Browse the repository at this point in the history
…X#4125)

Also update Slider style so not so overwhelmingly large
  • Loading branch information
philmoz authored Oct 16, 2023
1 parent d396b38 commit 661542a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
20 changes: 11 additions & 9 deletions radio/src/gui/colorlcd/themes/etx_lv_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
25 changes: 22 additions & 3 deletions radio/src/thirdparty/libopenui/src/slider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand All @@ -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);
}
}
}
3 changes: 3 additions & 0 deletions radio/src/thirdparty/libopenui/src/slider.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int()> _getValue;
std::function<void(int)> _setValue;
};

0 comments on commit 661542a

Please sign in to comment.