1 #include "../lv_examples.h"
2 #if LV_BUILD_EXAMPLES && LV_USE_IMG
3
4 /**
5 * Using multiple styles
6 */
lv_example_style_11(void)7 void lv_example_style_11(void)
8 {
9 /*A base style*/
10 static lv_style_t style_base;
11 lv_style_init(&style_base);
12 lv_style_set_bg_color(&style_base, lv_palette_main(LV_PALETTE_LIGHT_BLUE));
13 lv_style_set_border_color(&style_base, lv_palette_darken(LV_PALETTE_LIGHT_BLUE, 3));
14 lv_style_set_border_width(&style_base, 2);
15 lv_style_set_radius(&style_base, 10);
16 lv_style_set_shadow_width(&style_base, 10);
17 lv_style_set_shadow_ofs_y(&style_base, 5);
18 lv_style_set_shadow_opa(&style_base, LV_OPA_50);
19 lv_style_set_text_color(&style_base, lv_color_white());
20 lv_style_set_width(&style_base, 100);
21 lv_style_set_height(&style_base, LV_SIZE_CONTENT);
22
23 /*Set only the properties that should be different*/
24 static lv_style_t style_warning;
25 lv_style_init(&style_warning);
26 lv_style_set_bg_color(&style_warning, lv_palette_main(LV_PALETTE_YELLOW));
27 lv_style_set_border_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 3));
28 lv_style_set_text_color(&style_warning, lv_palette_darken(LV_PALETTE_YELLOW, 4));
29
30 /*Create an object with the base style only*/
31 lv_obj_t * obj_base = lv_obj_create(lv_scr_act());
32 lv_obj_add_style(obj_base, &style_base, 0);
33 lv_obj_align(obj_base, LV_ALIGN_LEFT_MID, 20, 0);
34
35 lv_obj_t * label = lv_label_create(obj_base);
36 lv_label_set_text(label, "Base");
37 lv_obj_center(label);
38
39 /*Create another object with the base style and earnings style too*/
40 lv_obj_t * obj_warning = lv_obj_create(lv_scr_act());
41 lv_obj_add_style(obj_warning, &style_base, 0);
42 lv_obj_add_style(obj_warning, &style_warning, 0);
43 lv_obj_align(obj_warning, LV_ALIGN_RIGHT_MID, -20, 0);
44
45 label = lv_label_create(obj_warning);
46 lv_label_set_text(label, "Warning");
47 lv_obj_center(label);
48 }
49
50 #endif
51