feat(example) add style examples

This commit is contained in:
Gabor Kiss-Vamosi
2021-05-27 11:50:04 +02:00
parent 5bc529bc46
commit 0cafde653d
22 changed files with 461 additions and 177 deletions

View File

@@ -1,36 +1,40 @@
typedef int _keep_pedantic_happy;
//#include "../../lv_examples.h"
//
///**
// * Using the transitions style properties
// */
//void lv_example_style_10(void)
//{
// static lv_style_t style;
// lv_style_init(&style);
//
// /*Set a background color and a radius*/
// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5);
// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER);
// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, lv_color_grey_lighten_3());
//
// /*Set different background color in pressed state*/
// lv_style_set_bg_color(&style, LV_STATE_PRESSED, lv_palette_main(LV_PALETTE_GREY));
//
// /*Set different transition time in default and pressed state
// *fast press, slower revert to default*/
// lv_style_set_transition_time(&style, LV_STATE_DEFAULT, 500);
// lv_style_set_transition_time(&style, LV_STATE_PRESSED, 200);
//
// /*Small delay to make transition more visible*/
// lv_style_set_transition_delay(&style, LV_STATE_DEFAULT, 100);
//
// /*Add `bg_color` to transitioned properties*/
// lv_style_set_transition_prop_1(&style, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR);
//
// /*Create an object with the new style*/
// lv_obj_t * obj = lv_obj_create(lv_scr_act());
// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style);
// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0);
//}
//
#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_IMG
/**
* Creating a transition
*/
void lv_example_style_10(void)
{
static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, LV_STYLE_BORDER_COLOR, LV_STYLE_BORDER_WIDTH, 0};
/* A default transition
* Make it fast (100ms) and start with some delay (200 ms)*/
static lv_style_transition_dsc_t trans_def;
lv_style_transition_dsc_init(&trans_def, props, lv_anim_path_linear, 100, 200, NULL);
/* A special transition when going to pressed state
* Make it slow (500 ms) but start without delay*/
static lv_style_transition_dsc_t trans_pr;
lv_style_transition_dsc_init(&trans_pr, props, lv_anim_path_linear, 500, 0, NULL);
static lv_style_t style_def;
lv_style_init(&style_def);
lv_style_set_transition(&style_def, &trans_def);
static lv_style_t style_pr;
lv_style_init(&style_pr);
lv_style_set_bg_color(&style_pr, lv_palette_main(LV_PALETTE_RED));
lv_style_set_border_width(&style_pr, 6);
lv_style_set_border_color(&style_pr, lv_palette_darken(LV_PALETTE_RED, 3));
lv_style_set_transition(&style_pr, &trans_pr);
/*Create an object with the new style_pr*/
lv_obj_t * obj = lv_obj_create(lv_scr_act());
lv_obj_add_style(obj, &style_def, 0);
lv_obj_add_style(obj, &style_pr, LV_STATE_PRESSED);
lv_obj_center(obj);
}
#endif