Description
What MCU/Processor/Board and compiler are you using?
LVGL (v7.0) PC simulator
Commit: e6f89ad7990718b7b0fc85b7aba02edaecdd277c (tag: v7.0.0, upstream/release/v7)
What do you experience?
In v7, I can’t figure out how to make a slider with the following style (picture from v6):
This is what I’ve managed to make in v7 for comparison:
What do you expect?
The slider to look like the v6 version.
Code to reproduce
Working v6 style:
#define SLIDER_BAR_HEIGHT 6
#define SLIDER_KNOB_SIZE 56
static void slider_init(void)
{
#if LV_USE_SLIDER != 0
static lv_style_t slider_bg;
lv_style_copy(&slider_bg, &lv_style_plain);
slider_bg.body.main_color = slider_bg.body.grad_color = LV_COLOR_MAKE(0x5b, 0x5b, 0x5b);
slider_bg.body.radius = LV_RADIUS_CIRCLE;
slider_bg.body.padding.left = slider_bg.body.padding.right = SLIDER_KNOB_SIZE / 2;
slider_bg.body.padding.top = slider_bg.body.padding.bottom = (SLIDER_KNOB_SIZE - SLIDER_BAR_HEIGHT) / 2;
static lv_style_t slider_indic;
lv_style_copy(&slider_indic, &lv_style_plain);
slider_indic.body.main_color = slider_indic.body.grad_color = LV_COLOR_MAKE(0x24, 0x61, 0x92);
slider_indic.body.radius = LV_RADIUS_CIRCLE;
slider_indic.body.padding.left = 0;
slider_indic.body.padding.right = 0;
slider_indic.body.padding.top = 0;
slider_indic.body.padding.bottom = 0;
static lv_style_t slider_knob;
lv_style_copy(&slider_knob, &lv_style_plain);
slider_knob.body.main_color = slider_knob.body.grad_color = LV_COLOR_MAKE(0xe6, 0xe6, 0xe6);
slider_knob.body.radius = LV_RADIUS_CIRCLE;
theme.style.slider.bg = &slider_bg;
theme.style.slider.indic = &slider_indic;
theme.style.slider.knob = &slider_knob;
#endif
}
Ported v7 style:
#define SLIDER_BAR_HEIGHT 6
#define SLIDER_KNOB_SIZE 56
static void slider_init(void)
{
#if LV_USE_SLIDER != 0
style_init_reset(&slider_knob);
lv_style_set_radius(&slider_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_bg_opa(&slider_knob, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xe6, 0xe6, 0xe6));
style_init_reset(&slider_bg);
//lv_style_set_border_width(&slider_bg, LV_STATE_DEFAULT, (SLIDER_KNOB_SIZE - SLIDER_BAR_HEIGHT) / 2);
//lv_style_set_border_color(&slider_bg, LV_STATE_DEFAULT, LV_COLOR_BLACK);
//lv_style_set_border_opa(&slider_bg, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_pad_left(&slider_bg, LV_STATE_DEFAULT, SLIDER_KNOB_SIZE / 2);
lv_style_set_pad_right(&slider_bg, LV_STATE_DEFAULT, SLIDER_KNOB_SIZE / 2);
lv_style_set_pad_top(&slider_bg, LV_STATE_DEFAULT, (SLIDER_KNOB_SIZE - SLIDER_BAR_HEIGHT) / 2);
lv_style_set_pad_bottom(&slider_bg, LV_STATE_DEFAULT, (SLIDER_KNOB_SIZE - SLIDER_BAR_HEIGHT) / 2);
lv_style_set_radius(&slider_bg, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_bg_opa(&slider_bg, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&slider_bg, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x5b, 0x5b, 0x5b));
style_init_reset(&slider_indic);
lv_style_set_radius(&slider_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE);
lv_style_set_bg_opa(&slider_indic, LV_STATE_DEFAULT, LV_OPA_COVER);
lv_style_set_bg_color(&slider_indic, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x24, 0x61, 0x92));
#endif
}
Uncommenting the border gives this result, which is nearly there (see a bit of grey at the far left), but not a great solution because I assume it involves lots of overdraw:
Screenshot and/or video
Included inline.
Misc
I was using lv_slider_set_knob_in(slider, true);
in the v6 code too which has been removed in v7. I’ve used the lv_style_set_pad_left/right functions in v7 which seems to do the same thing.
Is there a style I can set that I’m missing that can achieve the effect I’m after? I’ve tried all the margin and pad styles on all 3 different styles without luck!
It looks like it’s not possible to adjust the background draw area:
This is how the indic draw area is modified:
I assumed that LV_BAR_PART_BG
style_pad_* would be used to adjust the padding on the background and LV_BAR_PART_INDIC
style_pad* would be used to adjust the padding on the indicator. It seems that LV_BAR_PART_BG
controls the padding on the indicator and LV_BAR_PART_INDIC
padding does nothing.