2021-04-08 13:07:48 +02:00
|
|
|
#include "../../lv_examples.h"
|
2021-02-08 09:53:03 +01:00
|
|
|
#include <stdio.h>
|
2021-03-29 18:24:23 +02:00
|
|
|
#if LV_USE_BTN && LV_BUILD_EXAMPLES
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Style a button from scratch
|
|
|
|
*/
|
|
|
|
void lv_example_btn_2(void)
|
|
|
|
{
|
2021-03-29 18:24:23 +02:00
|
|
|
static lv_style_transition_dsc_t trans;
|
|
|
|
static lv_style_prop_t props[] = {LV_STYLE_OUTLINE_WIDTH, LV_STYLE_OUTLINE_OPA, 0};
|
|
|
|
lv_style_transition_dsc_init(&trans, props, &lv_anim_path_def, 300, 0);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
|
|
|
static lv_style_t style;
|
|
|
|
lv_style_init(&style);
|
2021-03-29 18:24:23 +02:00
|
|
|
lv_style_set_outline_opa(&style, LV_OPA_COVER);
|
|
|
|
lv_style_set_outline_color(&style, lv_color_blue());
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-29 18:24:23 +02:00
|
|
|
static lv_style_t style_pr;
|
|
|
|
lv_style_init(&style_pr);
|
|
|
|
lv_style_set_outline_width(&style_pr, 30);
|
|
|
|
lv_style_set_outline_opa(&style_pr, LV_OPA_TRANSP);
|
|
|
|
lv_style_set_transition(&style_pr, &trans);
|
|
|
|
|
|
|
|
//
|
|
|
|
// /*Init the default style*/
|
|
|
|
// lv_style_set_radius(&style, 3);
|
|
|
|
//
|
|
|
|
// lv_style_set_bg_opa(&style, LV_OPA_100);
|
|
|
|
// lv_style_set_bg_color(&style, lv_color_blue());
|
|
|
|
// lv_style_set_bg_grad_color(&style, lv_color_blue_darken_2());
|
|
|
|
// lv_style_set_bg_grad_dir(&style, LV_GRAD_DIR_VER);
|
|
|
|
//
|
|
|
|
// lv_style_set_border_opa(&style, LV_OPA_40);
|
|
|
|
// lv_style_set_border_width(&style, 2);
|
|
|
|
// lv_style_set_border_color(&style, lv_color_grey());
|
|
|
|
//
|
|
|
|
// lv_style_set_shadow_width(&style, 8);
|
|
|
|
// lv_style_set_shadow_color(&style, lv_color_grey());
|
|
|
|
// lv_style_set_shadow_ofs_y(&style, 8);
|
|
|
|
//
|
|
|
|
// lv_style_set_text_color(&style, lv_color_white());
|
|
|
|
//
|
|
|
|
// lv_style_set_pad_all(&style, 10);
|
|
|
|
// lv_style_set_pad_all(&style_pr, 40);
|
2021-02-24 15:12:36 +01:00
|
|
|
|
2021-02-08 09:53:03 +01:00
|
|
|
/*Init the pressed style*/
|
2021-02-24 15:12:36 +01:00
|
|
|
lv_style_set_shadow_ofs_y(&style_pr, 3);
|
|
|
|
lv_style_set_bg_color(&style_pr, lv_color_blue_darken_2());
|
|
|
|
lv_style_set_bg_grad_color(&style_pr, lv_color_blue_darken_4());
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * btn1 = lv_btn_create(lv_scr_act());
|
2021-03-29 18:24:23 +02:00
|
|
|
// lv_obj_remove_style(btn1, LV_PART_ANY, LV_STATE_ANY, NULL);
|
2021-03-31 19:57:14 +02:00
|
|
|
lv_obj_add_style(btn1, &style, 0);
|
|
|
|
lv_obj_add_style(btn1, &style_pr, LV_STATE_PRESSED);
|
2021-03-29 18:24:23 +02:00
|
|
|
lv_obj_set_size(btn1, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(btn1);
|
2021-02-08 09:53:03 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * label = lv_label_create(btn1);
|
2021-02-08 09:53:03 +01:00
|
|
|
lv_label_set_text(label, "Button");
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_center(label);
|
2021-02-08 09:53:03 +01:00
|
|
|
}
|
|
|
|
#endif
|