MantisIDE

Animation timeline · Round 1.28" touch watch

Guide by MantisIDE Team · Fri Nov 27 2026 · 0 points · 0 comments

Widget gallery 13 - Animation timeline: sequence many animations, then play, pause, reverse or scrub them with one object (lv.anim_timeline).

You’ll learn: anim_timeline, scrubbing, replay

Board: Waveshare ESP32-S3-Touch-LCD-1.28 (ESP32-S3R2). Part of the kit’s Widget gallery. Needs the board’s LVGL firmware: flash it from the notebook’s Flash button, then press Open in Full IDE.

# Widget gallery 13 - Animation timeline: sequence many animations, then play,
# pause, reverse or scrub them with one object (lv.anim_timeline).
import lvgl as lv
import display

display.init()                     # start the display and touch (does nothing if already on)

BG = 0x05110A
TEXT = 0xE3EFE6
MUTED = 0x8EA999
ACCENT = 0x46E07C
BLUE = 0x6CB8FF
AMBER = 0xF2B84B
RED = 0xFF6B6B
keep = []                             # styles, buffers and callbacks LVGL uses must stay referenced

FONTS = {12: lv.font_montserrat_12, 14: lv.font_montserrat_14, 16: lv.font_montserrat_16}


def label(parent, text="", color=TEXT, font=16, align=lv.ALIGN.CENTER, x=0, y=0, zoom=0):
    """lv.label with a colour and a Montserrat 12/14/16 font. zoom=2 draws it twice as big."""
    lb = lv.label(parent)
    lb.set_text(text)
    lb.set_style_text_color(lv.color_hex(color), 0)
    lb.set_style_text_font(FONTS.get(font, lv.font_montserrat_16), 0)
    if zoom:
        lb.set_style_transform_scale(int(256 * zoom), 0)   # 256 = 100 %
        lb.update_layout()
        lb.set_style_transform_pivot_x(lb.get_width() // 2, 0)
        lb.set_style_transform_pivot_y(lb.get_height() // 2, 0)
    lb.align(align, int(x), int(y))
    return lb


A = lv.anim_t
scr = lv.screen_active()             # the screen LVGL is showing
scr.clean()                           # remove what the last program drew
scr.set_style_bg_color(lv.color_hex(BG), 0)
scr.remove_flag(lv.obj.FLAG.SCROLLABLE)

cards = []
for i, col in enumerate((RED, AMBER, ACCENT, BLUE)):
    c = lv.obj(scr)
    c.set_size(36, 36)
    c.set_style_radius(10, 0)
    c.set_style_border_width(0, 0)
    c.set_style_bg_color(lv.color_hex(col), 0)
    c.align(lv.ALIGN.CENTER, -66 + i * 44, 60)
    c.set_style_opa(0, 0)
    cards.append(c)

tl = lv.anim_timeline_create()
keep.append(tl)


def make(obj, start, end, ms, setter, path=A.path_overshoot):
    a = A()
    a.init()
    a.set_var(obj)
    a.set_values(start, end)
    a.set_duration(ms)
    cb = lambda _a, v: setter(obj, v)  # noqa: E731
    a.set_custom_exec_cb(cb)
    a.set_path_cb(path)
    keep.extend([a, cb])
    return a

for i, c in enumerate(cards):
    t0 = i * 180
    tl.add(t0, make(c, 0, 255, 300, lambda o, v: o.set_style_opa(v, 0), A.path_linear))
    tl.add(t0, make(c, 60, -10, 600, lambda o, v: o.set_y(v)))
    tl.add(t0 + 600, make(c, 0, 900, 500, lambda o, v: o.set_style_transform_rotation(v, 0)))

# Slider scrubs the timeline progress (0..65535)
s = lv.slider(scr)
s.set_width(140)
s.align(lv.ALIGN.CENTER, 0, -60)
s.set_range(0, 65535)
s.add_event_cb(lambda e: tl.set_progress(s.get_value()), lv.EVENT.VALUE_CHANGED, None)
label(scr, "drag to scrub  -  tap to replay", MUTED, 12, y=-84)


def replay(e):
    if hasattr(tl, "set_reverse"):
        tl.set_reverse(False)
    tl.set_progress(0)
    tl.start()

scr.add_event_cb(replay, lv.EVENT.CLICKED, None)
tl.start()
print("lv.anim_timeline: add(start_ms, anim), start(), set_progress(0..65535), set_reverse().")
Loading post…

Dialog