lv_example_style_10.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "../lv_examples.h"
  2. #if LV_BUILD_EXAMPLES && LV_USE_IMG
  3. /**
  4. * Creating a transition
  5. */
  6. void lv_example_style_10(void)
  7. {
  8. static const lv_style_prop_t props[] = {LV_STYLE_BG_COLOR, LV_STYLE_BORDER_COLOR, LV_STYLE_BORDER_WIDTH, 0};
  9. /* A default transition
  10. * Make it fast (100ms) and start with some delay (200 ms)*/
  11. static lv_style_transition_dsc_t trans_def;
  12. lv_style_transition_dsc_init(&trans_def, props, lv_anim_path_linear, 100, 200, NULL);
  13. /* A special transition when going to pressed state
  14. * Make it slow (500 ms) but start without delay*/
  15. static lv_style_transition_dsc_t trans_pr;
  16. lv_style_transition_dsc_init(&trans_pr, props, lv_anim_path_linear, 500, 0, NULL);
  17. static lv_style_t style_def;
  18. lv_style_init(&style_def);
  19. lv_style_set_transition(&style_def, &trans_def);
  20. static lv_style_t style_pr;
  21. lv_style_init(&style_pr);
  22. lv_style_set_bg_color(&style_pr, lv_palette_main(LV_PALETTE_RED));
  23. lv_style_set_border_width(&style_pr, 6);
  24. lv_style_set_border_color(&style_pr, lv_palette_darken(LV_PALETTE_RED, 3));
  25. lv_style_set_transition(&style_pr, &trans_pr);
  26. /*Create an object with the new style_pr*/
  27. lv_obj_t * obj = lv_obj_create(lv_scr_act());
  28. lv_obj_add_style(obj, &style_def, 0);
  29. lv_obj_add_style(obj, &style_pr, LV_STATE_PRESSED);
  30. lv_obj_center(obj);
  31. }
  32. #endif