1 #include "../lv_examples.h"
2 #if LV_BUILD_EXAMPLES
3 
4 #if LV_USE_DRAW_SW_COMPLEX_GRADIENTS
5 
6 /**
7  * Using various gradients for button background
8  */
lv_example_style_18(void)9 void lv_example_style_18(void)
10 {
11     static const lv_color_t grad_colors[2] = {
12         LV_COLOR_MAKE(0x26, 0xa0, 0xda),
13         LV_COLOR_MAKE(0x31, 0x47, 0x55),
14     };
15 
16     /*Create a linear gradient going from the top left corner to the bottom at an angle, with reflected color map*/
17     static lv_style_t style_with_linear_gradient_bg;
18     static lv_grad_dsc_t linear_gradient_dsc;     /*NOTE: the gradient descriptor must be static or global variable!*/
19 
20     lv_style_init(&style_with_linear_gradient_bg);
21     lv_gradient_init_stops(&linear_gradient_dsc, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
22     lv_grad_linear_init(&linear_gradient_dsc, lv_pct(0), lv_pct(0), lv_pct(20), lv_pct(100), LV_GRAD_EXTEND_REFLECT);
23     lv_style_set_bg_grad(&style_with_linear_gradient_bg, &linear_gradient_dsc);
24     lv_style_set_bg_opa(&style_with_linear_gradient_bg, LV_OPA_COVER);
25 
26     /*Create a radial gradient with the center in the top left 1/3rd of the object, extending to the bottom right corner, with reflected color map*/
27     static lv_style_t style_with_radial_gradient_bg;
28     static lv_grad_dsc_t radial_gradient_dsc;     /*NOTE: the gradient descriptor must be static or global variable!*/
29 
30     lv_style_init(&style_with_radial_gradient_bg);
31     lv_gradient_init_stops(&radial_gradient_dsc, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t));
32     lv_grad_radial_init(&radial_gradient_dsc, lv_pct(30), lv_pct(30), lv_pct(100), lv_pct(100), LV_GRAD_EXTEND_REFLECT);
33     lv_style_set_bg_grad(&style_with_radial_gradient_bg, &radial_gradient_dsc);
34     lv_style_set_bg_opa(&style_with_radial_gradient_bg, LV_OPA_COVER);
35 
36     /*Create buttons with different gradient styles*/
37 
38     lv_obj_t * btn;
39     lv_obj_t * label;
40 
41     /*Simple horizontal gradient*/
42     btn = lv_button_create(lv_screen_active());
43     lv_obj_set_style_bg_color(btn, grad_colors[0], 0);
44     lv_obj_set_style_bg_grad_color(btn, grad_colors[1], 0);
45     lv_obj_set_style_bg_grad_dir(btn, LV_GRAD_DIR_HOR, 0);
46     lv_obj_set_size(btn, 150, 50);
47     lv_obj_align(btn, LV_ALIGN_CENTER, 0, -100);
48 
49     label = lv_label_create(btn);
50     lv_label_set_text(label, "Horizontal");
51     lv_obj_center(label);
52 
53     /*Simple vertical gradient*/
54     btn = lv_button_create(lv_screen_active());
55     lv_obj_set_style_bg_color(btn, grad_colors[0], 0);
56     lv_obj_set_style_bg_grad_color(btn, grad_colors[1], 0);
57     lv_obj_set_style_bg_grad_dir(btn, LV_GRAD_DIR_VER, 0);
58     lv_obj_set_size(btn, 150, 50);
59     lv_obj_align(btn, LV_ALIGN_CENTER, 0, -40);
60 
61     label = lv_label_create(btn);
62     lv_label_set_text(label, "Vertical");
63     lv_obj_center(label);
64 
65     /*Complex linear gradient*/
66     btn = lv_button_create(lv_screen_active());
67     lv_obj_add_style(btn, &style_with_linear_gradient_bg, 0);
68     lv_obj_set_size(btn, 150, 50);
69     lv_obj_align(btn, LV_ALIGN_CENTER, 0, 20);
70 
71     label = lv_label_create(btn);
72     lv_label_set_text(label, "Linear");
73     lv_obj_center(label);
74 
75     /*Complex radial gradient*/
76     btn = lv_button_create(lv_screen_active());
77     lv_obj_add_style(btn, &style_with_radial_gradient_bg, 0);
78     lv_obj_set_size(btn, 150, 50);
79     lv_obj_align(btn, LV_ALIGN_CENTER, 0, 80);
80 
81     label = lv_label_create(btn);
82     lv_label_set_text(label, "Radial");
83     lv_obj_center(label);
84 }
85 
86 #else
87 
lv_example_style_18(void)88 void lv_example_style_18(void)
89 {
90     lv_obj_t * label = lv_label_create(lv_screen_active());
91     lv_obj_set_width(label, LV_PCT(80));
92     lv_label_set_text(label, "LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not enabled");
93     lv_label_set_long_mode(label, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR);
94     lv_obj_center(label);
95 }
96 
97 #endif /*LV_USE_DRAW_SW_COMPLEX_GRADIENTS*/
98 
99 #endif /*LV_BUILD_EXAMPLES*/
100