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:
+22
-3
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user