1 #include "../../lv_examples.h"
2 #if LV_USE_SLIDER && LV_BUILD_EXAMPLES
3
4 /**
5 * Show how to style a slider.
6 */
lv_example_slider_2(void)7 void lv_example_slider_2(void)
8 {
9 /*Create a transition*/
10 static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, 0};
11 static lv_style_transition_dsc_t transition_dsc;
12 lv_style_transition_dsc_init(&transition_dsc, props, lv_anim_path_linear, 300, 0, NULL);
13
14 static lv_style_t style_main;
15 static lv_style_t style_indicator;
16 static lv_style_t style_knob;
17 static lv_style_t style_pressed_color;
18 lv_style_init(&style_main);
19 lv_style_set_bg_opa(&style_main, LV_OPA_COVER);
20 lv_style_set_bg_color(&style_main, lv_color_hex3(0xbbb));
21 lv_style_set_radius(&style_main, LV_RADIUS_CIRCLE);
22 lv_style_set_pad_ver(&style_main, -2); /*Makes the indicator larger*/
23
24 lv_style_init(&style_indicator);
25 lv_style_set_bg_opa(&style_indicator, LV_OPA_COVER);
26 lv_style_set_bg_color(&style_indicator, lv_palette_main(LV_PALETTE_CYAN));
27 lv_style_set_radius(&style_indicator, LV_RADIUS_CIRCLE);
28 lv_style_set_transition(&style_indicator, &transition_dsc);
29
30 lv_style_init(&style_knob);
31 lv_style_set_bg_opa(&style_knob, LV_OPA_COVER);
32 lv_style_set_bg_color(&style_knob, lv_palette_main(LV_PALETTE_CYAN));
33 lv_style_set_border_color(&style_knob, lv_palette_darken(LV_PALETTE_CYAN, 3));
34 lv_style_set_border_width(&style_knob, 2);
35 lv_style_set_radius(&style_knob, LV_RADIUS_CIRCLE);
36 lv_style_set_pad_all(&style_knob, 6); /*Makes the knob larger*/
37 lv_style_set_transition(&style_knob, &transition_dsc);
38
39 lv_style_init(&style_pressed_color);
40 lv_style_set_bg_color(&style_pressed_color, lv_palette_darken(LV_PALETTE_CYAN, 2));
41
42 /*Create a slider and add the style*/
43 lv_obj_t * slider = lv_slider_create(lv_scr_act());
44 lv_obj_remove_style_all(slider); /*Remove the styles coming from the theme*/
45
46 lv_obj_add_style(slider, &style_main, LV_PART_MAIN);
47 lv_obj_add_style(slider, &style_indicator, LV_PART_INDICATOR);
48 lv_obj_add_style(slider, &style_pressed_color, LV_PART_INDICATOR | LV_STATE_PRESSED);
49 lv_obj_add_style(slider, &style_knob, LV_PART_KNOB);
50 lv_obj_add_style(slider, &style_pressed_color, LV_PART_KNOB | LV_STATE_PRESSED);
51
52 lv_obj_center(slider);
53 }
54
55 #endif
56