1#
2# Create a style transition on a button to act like a gum when clicked
3#
4
5# Properties to transition
6props = [lv.STYLE.TRANSFORM_WIDTH, lv.STYLE.TRANSFORM_HEIGHT, lv.STYLE.TEXT_LETTER_SPACE, 0]
7
8# Transition descriptor when going back to the default state.
9# Add some delay to be sure the press transition is visible even if the press was very short*/
10transition_dsc_def = lv.style_transition_dsc_t()
11transition_dsc_def.init(props, lv.anim_t.path_overshoot, 250, 100, None)
12
13# Transition descriptor when going to pressed state.
14# No delay, go to pressed state immediately
15transition_dsc_pr = lv.style_transition_dsc_t()
16transition_dsc_pr.init(props, lv.anim_t.path_ease_in_out, 250, 0, None)
17
18# Add only the new transition to the default state
19style_def = lv.style_t()
20style_def.init()
21style_def.set_transition(transition_dsc_def)
22
23# Add the transition and some transformation to the presses state.
24style_pr = lv.style_t()
25style_pr.init()
26style_pr.set_transform_width(10)
27style_pr.set_transform_height(-10)
28style_pr.set_text_letter_space(10)
29style_pr.set_transition(transition_dsc_pr)
30
31btn1 = lv.btn(lv.scr_act())
32btn1.align(lv.ALIGN.CENTER, 0, -80)
33btn1.add_style(style_pr, lv.STATE.PRESSED)
34btn1.add_style(style_def, 0)
35
36label = lv.label(btn1)
37label.set_text("Gum")
38
39