feat(color): Add tick marks to Sliders with less than 10 steps (#4125)
Also update Slider style so not so overwhelmingly large
This commit is contained in:
@@ -257,11 +257,14 @@ static void style_init(void)
|
|||||||
// Slider
|
// Slider
|
||||||
lv_style_init(&styles.slider_main);
|
lv_style_init(&styles.slider_main);
|
||||||
lv_style_set_bg_opa(&styles.slider_main, LV_OPA_100);
|
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_init(&styles.slider_knob);
|
||||||
lv_style_set_bg_opa(&styles.slider_knob, LV_OPA_COVER);
|
lv_style_set_bg_opa(&styles.slider_knob, LV_OPA_COVER);
|
||||||
lv_style_set_border_width(&styles.slider_knob, 1);
|
lv_style_set_border_width(&styles.slider_knob, 2);
|
||||||
lv_style_set_pad_all(&styles.slider_knob, lv_disp_dpx(theme.disp, 6));
|
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
|
// Choice
|
||||||
lv_style_init(&styles.choice_main);
|
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_main, LV_PART_MAIN);
|
||||||
lv_obj_add_style(obj, &styles.slider_knob, LV_PART_KNOB);
|
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_MAIN);
|
||||||
lv_obj_add_style(obj, &styles.circle, LV_PART_KNOB);
|
|
||||||
lv_obj_add_style(obj, &styles.bg_color_focus,
|
lv_obj_add_style(obj, &styles.bg_color_focus,
|
||||||
LV_PART_MAIN | LV_STATE_FOCUSED);
|
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_PART_MAIN | LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||||
lv_obj_add_style(obj, &styles.bg_color_focus,
|
lv_obj_add_style(obj, &styles.bg_color_focus,
|
||||||
LV_PART_INDICATOR | LV_STATE_FOCUSED);
|
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_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)
|
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,
|
.user_data = nullptr,
|
||||||
.event_cb = nullptr,
|
.event_cb = nullptr,
|
||||||
.width_def = 0,
|
.width_def = 0,
|
||||||
.height_def = 16,
|
.height_def = 8,
|
||||||
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
|
.editable = LV_OBJ_CLASS_EDITABLE_INHERIT,
|
||||||
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
|
.group_def = LV_OBJ_CLASS_GROUP_DEF_INHERIT,
|
||||||
.instance_size = sizeof(lv_slider_t),
|
.instance_size = sizeof(lv_slider_t),
|
||||||
|
|||||||
+22
-3
@@ -17,9 +17,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "slider.h"
|
#include "slider.h"
|
||||||
#include "theme.h"
|
|
||||||
|
|
||||||
#include "LvglWrapper.h"
|
#include "LvglWrapper.h"
|
||||||
|
#include "theme.h"
|
||||||
|
|
||||||
static void slider_changed_cb(lv_event_t* e)
|
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)),
|
_getValue(std::move(getValue)),
|
||||||
_setValue(std::move(setValue))
|
_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_set_width(slider, lv_pct(100));
|
||||||
|
|
||||||
lv_obj_add_event_cb(slider, slider_changed_cb, LV_EVENT_VALUE_CHANGED, this);
|
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)
|
if (_getValue != nullptr)
|
||||||
lv_slider_set_value(slider, _getValue(), LV_ANIM_OFF);
|
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
@@ -35,9 +35,12 @@ class Slider : public Window
|
|||||||
if (_setValue != nullptr) _setValue(limit(vmin, value, vmax));
|
if (_setValue != nullptr) _setValue(limit(vmin, value, vmax));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void paint(BitmapBuffer *) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
int vmin;
|
int vmin;
|
||||||
int vmax;
|
int vmax;
|
||||||
|
lv_obj_t* slider;
|
||||||
std::function<int()> _getValue;
|
std::function<int()> _getValue;
|
||||||
std::function<void(int)> _setValue;
|
std::function<void(int)> _setValue;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user