#include "../lv_examples.h" #if LV_BUILD_EXAMPLES #if LV_USE_DRAW_SW_COMPLEX_GRADIENTS /** * Using various gradients for button background */ void lv_example_style_18(void) { static const lv_color_t grad_colors[2] = { LV_COLOR_MAKE(0x26, 0xa0, 0xda), LV_COLOR_MAKE(0x31, 0x47, 0x55), }; /*Create a linear gradient going from the top left corner to the bottom at an angle, with reflected color map*/ static lv_style_t style_with_linear_gradient_bg; static lv_grad_dsc_t linear_gradient_dsc; /*NOTE: the gradient descriptor must be static or global variable!*/ lv_style_init(&style_with_linear_gradient_bg); lv_gradient_init_stops(&linear_gradient_dsc, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t)); lv_grad_linear_init(&linear_gradient_dsc, lv_pct(0), lv_pct(0), lv_pct(20), lv_pct(100), LV_GRAD_EXTEND_REFLECT); lv_style_set_bg_grad(&style_with_linear_gradient_bg, &linear_gradient_dsc); lv_style_set_bg_opa(&style_with_linear_gradient_bg, LV_OPA_COVER); /*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*/ static lv_style_t style_with_radial_gradient_bg; static lv_grad_dsc_t radial_gradient_dsc; /*NOTE: the gradient descriptor must be static or global variable!*/ lv_style_init(&style_with_radial_gradient_bg); lv_gradient_init_stops(&radial_gradient_dsc, grad_colors, NULL, NULL, sizeof(grad_colors) / sizeof(lv_color_t)); lv_grad_radial_init(&radial_gradient_dsc, lv_pct(30), lv_pct(30), lv_pct(100), lv_pct(100), LV_GRAD_EXTEND_REFLECT); lv_style_set_bg_grad(&style_with_radial_gradient_bg, &radial_gradient_dsc); lv_style_set_bg_opa(&style_with_radial_gradient_bg, LV_OPA_COVER); /*Create buttons with different gradient styles*/ lv_obj_t * btn; lv_obj_t * label; /*Simple horizontal gradient*/ btn = lv_button_create(lv_screen_active()); lv_obj_set_style_bg_color(btn, grad_colors[0], 0); lv_obj_set_style_bg_grad_color(btn, grad_colors[1], 0); lv_obj_set_style_bg_grad_dir(btn, LV_GRAD_DIR_HOR, 0); lv_obj_set_size(btn, 150, 50); lv_obj_align(btn, LV_ALIGN_CENTER, 0, -100); label = lv_label_create(btn); lv_label_set_text(label, "Horizontal"); lv_obj_center(label); /*Simple vertical gradient*/ btn = lv_button_create(lv_screen_active()); lv_obj_set_style_bg_color(btn, grad_colors[0], 0); lv_obj_set_style_bg_grad_color(btn, grad_colors[1], 0); lv_obj_set_style_bg_grad_dir(btn, LV_GRAD_DIR_VER, 0); lv_obj_set_size(btn, 150, 50); lv_obj_align(btn, LV_ALIGN_CENTER, 0, -40); label = lv_label_create(btn); lv_label_set_text(label, "Vertical"); lv_obj_center(label); /*Complex linear gradient*/ btn = lv_button_create(lv_screen_active()); lv_obj_add_style(btn, &style_with_linear_gradient_bg, 0); lv_obj_set_size(btn, 150, 50); lv_obj_align(btn, LV_ALIGN_CENTER, 0, 20); label = lv_label_create(btn); lv_label_set_text(label, "Linear"); lv_obj_center(label); /*Complex radial gradient*/ btn = lv_button_create(lv_screen_active()); lv_obj_add_style(btn, &style_with_radial_gradient_bg, 0); lv_obj_set_size(btn, 150, 50); lv_obj_align(btn, LV_ALIGN_CENTER, 0, 80); label = lv_label_create(btn); lv_label_set_text(label, "Radial"); lv_obj_center(label); } #else void lv_example_style_18(void) { lv_obj_t * label = lv_label_create(lv_screen_active()); lv_obj_set_width(label, LV_PCT(80)); lv_label_set_text(label, "LV_USE_DRAW_SW_COMPLEX_GRADIENTS is not enabled"); lv_label_set_long_mode(label, LV_LABEL_LONG_MODE_SCROLL_CIRCULAR); lv_obj_center(label); } #endif /*LV_USE_DRAW_SW_COMPLEX_GRADIENTS*/ #endif /*LV_BUILD_EXAMPLES*/