1class LV_ExampleAnimTimeline_1(object):
2
3    def __init__(self):
4        self.obj_width = 120
5        self.obj_height = 150
6        #
7        # Create an animation timeline
8        #
9
10        self.par = lv.scr_act()
11        self.par.set_flex_flow(lv.FLEX_FLOW.ROW)
12        self.par.set_flex_align(lv.FLEX_ALIGN.SPACE_AROUND, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
13
14        self.btn_run = lv.btn(self.par)
15        self.btn_run.add_event_cb(self.btn_run_event_handler, lv.EVENT.VALUE_CHANGED, None)
16        self.btn_run.add_flag(lv.obj.FLAG.IGNORE_LAYOUT)
17        self.btn_run.add_flag(lv.obj.FLAG.CHECKABLE)
18        self.btn_run.align(lv.ALIGN.TOP_MID, -50, 20)
19
20        self.label_run = lv.label(self.btn_run)
21        self.label_run.set_text("Run")
22        self.label_run.center()
23
24        self.btn_del = lv.btn(self.par)
25        self.btn_del.add_event_cb(self.btn_del_event_handler, lv.EVENT.CLICKED, None)
26        self.btn_del.add_flag(lv.obj.FLAG.IGNORE_LAYOUT)
27        self.btn_del.align(lv.ALIGN.TOP_MID, 50, 20)
28
29        self.label_del = lv.label(self.btn_del)
30        self.label_del.set_text("Stop")
31        self.label_del.center()
32
33        self.slider = lv.slider(self.par)
34        self.slider.add_event_cb(self.slider_prg_event_handler, lv.EVENT.VALUE_CHANGED, None)
35        self.slider.add_flag(lv.obj.FLAG.IGNORE_LAYOUT)
36        self.slider.align(lv.ALIGN.BOTTOM_RIGHT, -20, -20)
37        self.slider.set_range(0, 65535)
38
39        self.obj1 = lv.obj(self.par)
40        self.obj1.set_size(self.obj_width, self.obj_height)
41
42        self.obj2 = lv.obj(self.par)
43        self.obj2.set_size(self.obj_width, self.obj_height)
44
45        self.obj3 = lv.obj(self.par)
46        self.obj3.set_size(self.obj_width, self.obj_height)
47
48        self.anim_timeline = None
49
50    def set_width(self,obj, v):
51        obj.set_width(v)
52
53    def set_height(self,obj, v):
54        obj.set_height(v)
55
56    def anim_timeline_create(self):
57        # obj1
58        self.a1 = lv.anim_t()
59        self.a1.init()
60        self.a1.set_values(0, self.obj_width)
61        self.a1.set_early_apply(False)
62        self.a1.set_custom_exec_cb(lambda a,v: self.set_width(self.obj1,v))
63        self.a1.set_path_cb(lv.anim_t.path_overshoot)
64        self.a1.set_time(300)
65
66        self.a2 = lv.anim_t()
67        self.a2.init()
68        self.a2.set_values(0, self.obj_height)
69        self.a2.set_early_apply(False)
70        self.a2.set_custom_exec_cb(lambda a,v: self.set_height(self.obj1,v))
71        self.a2.set_path_cb(lv.anim_t.path_ease_out)
72        self.a2.set_time(300)
73
74        # obj2
75        self.a3=lv.anim_t()
76        self.a3.init()
77        self.a3.set_values(0, self.obj_width)
78        self.a3.set_early_apply(False)
79        self.a3.set_custom_exec_cb(lambda a,v: self.set_width(self.obj2,v))
80        self.a3.set_path_cb(lv.anim_t.path_overshoot)
81        self.a3.set_time(300)
82
83        self.a4 = lv.anim_t()
84        self.a4.init()
85        self.a4.set_values(0, self.obj_height)
86        self.a4.set_early_apply(False)
87        self.a4.set_custom_exec_cb(lambda a,v: self.set_height(self.obj2,v))
88        self.a4.set_path_cb(lv.anim_t.path_ease_out)
89        self.a4.set_time(300)
90
91        # obj3
92        self.a5 = lv.anim_t()
93        self.a5.init()
94        self.a5.set_values(0, self.obj_width)
95        self.a5.set_early_apply(False)
96        self.a5.set_custom_exec_cb(lambda a,v: self.set_width(self.obj3,v))
97        self.a5.set_path_cb(lv.anim_t.path_overshoot)
98        self.a5.set_time(300)
99
100        self.a6 = lv.anim_t()
101        self.a6.init()
102        self.a6.set_values(0, self.obj_height)
103        self.a6.set_early_apply(False)
104        self.a6.set_custom_exec_cb(lambda a,v: self.set_height(self.obj3,v))
105        self.a6.set_path_cb(lv.anim_t.path_ease_out)
106        self.a6.set_time(300)
107
108        # Create anim timeline
109        print("Create new anim_timeline")
110        self.anim_timeline = lv.anim_timeline_create()
111        lv.anim_timeline_add(self.anim_timeline, 0, self.a1)
112        lv.anim_timeline_add(self.anim_timeline, 0, self.a2)
113        lv.anim_timeline_add(self.anim_timeline, 200, self.a3)
114        lv.anim_timeline_add(self.anim_timeline, 200, self.a4)
115        lv.anim_timeline_add(self.anim_timeline, 400, self.a5)
116        lv.anim_timeline_add(self.anim_timeline, 400, self.a6)
117
118    def slider_prg_event_handler(self,e):
119        slider = e.get_target()
120
121        if  not self.anim_timeline:
122            self.anim_timeline_create()
123
124        progress = slider.get_value()
125        lv.anim_timeline_set_progress(self.anim_timeline, progress)
126
127
128    def btn_run_event_handler(self,e):
129        btn = e.get_target()
130        if not self.anim_timeline:
131            self.anim_timeline_create()
132
133        reverse = btn.has_state(lv.STATE.CHECKED)
134        lv.anim_timeline_set_reverse(self.anim_timeline,reverse)
135        lv.anim_timeline_start(self.anim_timeline)
136
137    def btn_del_event_handler(self,e):
138        if self.anim_timeline:
139            lv.anim_timeline_del(self.anim_timeline)
140        self.anim_timeline = None
141
142
143lv_example_anim_timeline_1 = LV_ExampleAnimTimeline_1()
144