2021-04-08 13:07:48 +02:00
|
|
|
#include "../lv_examples.h"
|
2021-02-16 20:41:11 +01:00
|
|
|
#if LV_USE_BTN && LV_BUILD_EXAMPLES
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create styles from scratch for buttons.
|
|
|
|
*/
|
|
|
|
void lv_example_get_started_2(void)
|
|
|
|
{
|
|
|
|
static lv_style_t style_btn;
|
|
|
|
static lv_style_t style_btn_red;
|
|
|
|
static lv_style_t style_btn_pressed;
|
|
|
|
|
|
|
|
/*Create a simple button style*/
|
|
|
|
lv_style_init(&style_btn);
|
|
|
|
lv_style_set_radius(&style_btn, 10);
|
|
|
|
lv_style_set_bg_opa(&style_btn, LV_OPA_COVER);
|
2021-02-23 15:03:06 +01:00
|
|
|
lv_style_set_bg_color(&style_btn, lv_color_grey_lighten_3());
|
|
|
|
lv_style_set_bg_grad_color(&style_btn, lv_color_grey());
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_style_set_bg_grad_dir(&style_btn, LV_GRAD_DIR_VER);
|
|
|
|
|
|
|
|
/*Add a border*/
|
2021-02-23 15:03:06 +01:00
|
|
|
lv_style_set_border_color(&style_btn, lv_color_white());
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_style_set_border_opa(&style_btn, LV_OPA_70);
|
|
|
|
lv_style_set_border_width(&style_btn, 2);
|
|
|
|
|
|
|
|
/*Set the text style*/
|
2021-02-23 15:03:06 +01:00
|
|
|
lv_style_set_text_color(&style_btn, lv_color_white());
|
2021-02-16 20:41:11 +01:00
|
|
|
|
|
|
|
/*Create a red style. Change only some colors.*/
|
|
|
|
lv_style_init(&style_btn_red);
|
2021-02-24 15:12:36 +01:00
|
|
|
lv_style_set_bg_color(&style_btn_red, lv_color_light_blue());
|
|
|
|
lv_style_set_bg_grad_color(&style_btn_red, lv_color_light_blue_darken_3());
|
2021-02-16 20:41:11 +01:00
|
|
|
|
|
|
|
/*Create a style for the pressed state. Add color filter to make every color darker*/
|
|
|
|
lv_style_init(&style_btn_pressed);
|
2021-02-24 15:12:36 +01:00
|
|
|
lv_style_set_bg_color(&style_btn_red, lv_color_blue());
|
|
|
|
lv_style_set_bg_grad_color(&style_btn_red, lv_color_blue_darken_3());
|
2021-02-16 20:41:11 +01:00
|
|
|
|
|
|
|
/*Create a button and use the new styles*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_obj_set_pos(btn, 10, 10); /*Set its position*/
|
|
|
|
lv_obj_set_size(btn, 120, 50); /*Set its size*/
|
2021-03-31 19:57:14 +02:00
|
|
|
lv_obj_remove_style_all(btn); /*Remove the styles coming from the theme*/
|
|
|
|
lv_obj_add_style(btn, &style_btn, 0);
|
|
|
|
lv_obj_add_style(btn, &style_btn_pressed, LV_STATE_PRESSED);
|
2021-02-16 20:41:11 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_label_set_text(label, "Button"); /*Set the labels text*/
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(label);
|
2021-02-16 20:41:11 +01:00
|
|
|
|
|
|
|
/*Create an other button and use the red style too*/
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_obj_set_pos(btn2, 10, 80);
|
|
|
|
lv_obj_set_size(btn2, 120, 50); /*Set its size*/
|
2021-03-31 19:57:14 +02:00
|
|
|
lv_obj_remove_style_all(btn2); /*Remove the styles coming from the theme*/
|
|
|
|
lv_obj_add_style(btn2, &style_btn, 0);
|
|
|
|
lv_obj_add_style(btn2, &style_btn_red, 0);
|
|
|
|
lv_obj_add_style(btn2, &style_btn_pressed, LV_STATE_PRESSED);
|
|
|
|
lv_obj_set_style_radius(btn2, LV_RADIUS_CIRCLE, 0); /*Add a local style*/
|
2021-02-16 20:41:11 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
label = lv_label_create(btn2); /*Add a label to the button*/
|
2021-02-16 20:41:11 +01:00
|
|
|
lv_label_set_text(label, "Button 2"); /*Set the labels text*/
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(label);
|
2021-02-16 20:41:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|