Created
June 27, 2021 22:40
-
-
Save amirgon/dcddf84509f66c2448d8a7d3e763f0e0 to your computer and use it in GitHub Desktop.
anim timeline example with callback setters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/bin/lv_micropython -i | |
import sys | |
sys.path.append('') # See: https://github.com/micropython/micropython/issues/6419 | |
import time | |
import lvgl as lv | |
import display_driver_utils | |
lv.init() | |
driver = display_driver_utils.driver() | |
def event_handler(e): | |
# print("event_handler") | |
obj = e.get_target() | |
if obj == btn: | |
playback = btn.has_state(lv.STATE.CHECKED) | |
lv.anim_timeline_t.start(anim_timeline, playback) | |
elif obj == slider: | |
progress = slider.get_value() | |
lv.anim_timeline_t.set_progress(anim_timeline, progress) | |
# | |
# Create an animation timeline | |
# | |
par = lv.scr_act() | |
par.set_flex_flow(lv.FLEX_FLOW.ROW) | |
par.set_flex_align(lv.FLEX_ALIGN.SPACE_AROUND, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER) | |
btn = lv.btn(par) | |
btn.add_event_cb(event_handler, lv.EVENT.VALUE_CHANGED, None) | |
btn.add_flag(lv.obj.FLAG.IGNORE_LAYOUT) | |
btn.add_flag(lv.obj.FLAG.CHECKABLE) | |
btn.align(lv.ALIGN.BOTTOM_LEFT, 0, 0) | |
slider = lv.slider(par) | |
slider.add_event_cb(event_handler, lv.EVENT.VALUE_CHANGED, None) | |
slider.add_flag(lv.obj.FLAG.IGNORE_LAYOUT) | |
slider.align(lv.ALIGN.BOTTOM_RIGHT, -20, -20) | |
slider.set_range(0, 65535) | |
obj1 = lv.obj(par) | |
obj2 = lv.obj(par) | |
obj3 = lv.obj(par) | |
obj_width = obj1.get_style_width(0) | |
obj_height = obj1.get_style_height(0) | |
anim_timeline = [lv.anim_timeline_t({"start_time" : 0, | |
"var" : obj1, | |
# "exec_cb" : set_width, | |
"start_value" : 0, | |
"end_value" : obj_width, | |
"duration" : 300, | |
# "path_cb" : lv.anim_t.path_overshoot | |
}), | |
lv.anim_timeline_t({ | |
"start_time" : 0, | |
"var" : obj1, | |
# "exec_cb" : set_height, | |
"start_value" : 0, | |
"end_value" : obj_height, | |
"duration" : 300, | |
# "path_cb" : lv.anim_t.path_ease_out | |
}), | |
lv.anim_timeline_t({ | |
"start_time" : 200, | |
"var" : obj2, | |
# "exec_cb" : set_width, | |
"start_value" : 0, | |
"end_value" : obj_width, | |
"duration" : 300, | |
# "path_cb" : lv.anim_t.path_overshoot | |
}), | |
lv.anim_timeline_t({ | |
"start_time": 200, | |
"var" : obj2, | |
# "exec_cb" : set_height, | |
"start_value" : 0, | |
"end_value" : obj_height, | |
"duration" : 300, | |
# "path_cb" : lv.anim_t.path_ease_out | |
}), | |
lv.anim_timeline_t({ | |
"start_time" : 400, | |
"var" : obj3, | |
# "exec_cb" : set_width, | |
"start_value" : 0, | |
"end_value" : obj_width, | |
"duration" : 300, | |
# "path_cb" : lv.anim_t.path_overshoot | |
}), | |
lv.anim_timeline_t({ | |
"start_time" : 400, | |
"var" : obj3, | |
# "exec_cb" : set_height, | |
"start_value" : 0, | |
"end_value" : obj_height, | |
"duration" : 300, | |
# "path_cb" : lv.anim_t.path_ease_out | |
}), | |
lv.anim_timeline_t({ | |
"start_time" : -1})] | |
anim_timeline[0].set_exec_cb(lambda a,v: obj1.set_width(v)) | |
anim_timeline[0].set_path_cb(lv.anim_t.path_overshoot) | |
anim_timeline[1].set_exec_cb(lambda a,v: obj1.set_height(v)) | |
anim_timeline[1].set_path_cb(lv.anim_t.path_ease_out) | |
anim_timeline[2].set_exec_cb(lambda a,v: obj2.set_width(v)) | |
anim_timeline[2].set_path_cb(lv.anim_t.path_overshoot) | |
anim_timeline[3].set_exec_cb(lambda a,v: obj2.set_height(v)) | |
anim_timeline[3].set_path_cb(lv.anim_t.path_ease_out) | |
anim_timeline[4].set_exec_cb(lambda a,v: obj3.set_width(v)) | |
anim_timeline[4].set_path_cb(lv.anim_t.path_overshoot) | |
anim_timeline[5].set_exec_cb(lambda a,v: obj3.set_height(v)) | |
anim_timeline[5].set_path_cb(lv.anim_t.path_ease_out) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment