1#
2# Show how to style a slider.
3#
4# Create a transition
5props = [lv.STYLE.BG_COLOR, 0]
6transition_dsc = lv.style_transition_dsc_t()
7transition_dsc.init(props, lv.anim_t.path_linear, 300, 0, None)
8
9style_main = lv.style_t()
10style_indicator = lv.style_t()
11style_knob = lv.style_t()
12style_pressed_color = lv.style_t()
13style_main.init()
14style_main.set_bg_opa(lv.OPA.COVER)
15style_main.set_bg_color(lv.color_hex3(0xbbb))
16style_main.set_radius(lv.RADIUS.CIRCLE)
17style_main.set_pad_ver(-2)                 # Makes the indicator larger
18
19style_indicator.init()
20style_indicator.set_bg_opa(lv.OPA.COVER)
21style_indicator.set_bg_color(lv.palette_main(lv.PALETTE.CYAN))
22style_indicator.set_radius(lv.RADIUS.CIRCLE)
23style_indicator.set_transition(transition_dsc)
24
25style_knob.init()
26style_knob.set_bg_opa(lv.OPA.COVER)
27style_knob.set_bg_color(lv.palette_main(lv.PALETTE.CYAN))
28style_knob.set_border_color(lv.palette_darken(lv.PALETTE.CYAN, 3))
29style_knob.set_border_width(2)
30style_knob.set_radius(lv.RADIUS.CIRCLE)
31style_knob.set_pad_all(6)                   # Makes the knob larger
32style_knob.set_transition(transition_dsc)
33
34style_pressed_color.init()
35style_pressed_color.set_bg_color(lv.palette_darken(lv.PALETTE.CYAN, 2))
36
37# Create a slider and add the style
38slider = lv.slider(lv.scr_act())
39slider.remove_style_all()                   # Remove the styles coming from the theme
40
41slider.add_style(style_main, lv.PART.MAIN)
42slider.add_style(style_indicator, lv.PART.INDICATOR)
43slider.add_style(style_pressed_color, lv.PART.INDICATOR | lv.STATE.PRESSED)
44slider.add_style(style_knob, lv.PART.KNOB)
45slider.add_style(style_pressed_color, lv.PART.KNOB | lv.STATE.PRESSED)
46
47slider.center()
48
49