MantisIDE

Style effects · Round 1.28" touch watch

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

Widget gallery 11 - Style effects: transitions, shadows, opacity, rotation, outlines

You’ll learn: transitions, shadows, rotation, outline

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 11 - Style effects: transitions, shadows, opacity, rotation, outlines
import lvgl as lv
import display

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

BG = 0x05110A
ACCENT = 0x46E07C
BLUE = 0x6CB8FF
AMBER = 0xF2B84B
VIOLET = 0xB593FF
keep = []                             # styles, buffers and callbacks LVGL uses must stay referenced


def anim(obj, start, end, ms, setter, path=None, repeat=1, playback=0, delay=0, done=None):
    """Animate start -> end over ms, calling setter(obj, value). repeat=-1 loops forever."""
    a = lv.anim_t()
    a.init()
    a.set_var(obj)
    a.set_values(start, end)
    a.set_duration(ms)
    a.set_delay(delay)
    a.set_custom_exec_cb(lambda _a, v: setter(obj, v))
    a.set_path_cb(path or lv.anim_t.path_ease_in_out)
    if repeat < 0:
        a.set_repeat_count(lv.ANIM_REPEAT_INFINITE)
    elif repeat > 1:
        a.set_repeat_count(repeat)
    if playback:
        a.set_reverse_duration(playback)  # play back to start
    if done:
        a.set_completed_cb(lambda _a: done())
    a.start()
    keep.append(a)
    return a

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)

# Style transition: colour + size change animate smoothly on press/release
props = [lv.STYLE.BG_COLOR, lv.STYLE.TRANSFORM_WIDTH, lv.STYLE.TRANSFORM_HEIGHT, 0]
trans = lv.style_transition_dsc_t()
trans.init(props, lv.anim_t.path_ease_in_out, 250, 0, None)
st_pr = lv.style_t()
st_pr.init()
st_pr.set_bg_color(lv.color_hex(ACCENT))
st_pr.set_transform_width(10)
st_pr.set_transform_height(10)
st_pr.set_transition(trans)
st_def = lv.style_t()
st_def.init()
st_def.set_transition(trans)
keep.extend([props, trans, st_pr, st_def])

btn = lv.button(scr)
btn.set_size(110, 46)
btn.align(lv.ALIGN.CENTER, 0, -55)
btn.add_style(st_def, 0)
btn.add_style(st_pr, lv.STATE.PRESSED)
lv.label(btn).set_text("Press me")
btn.get_child(0).center()

# Glow shadow that pulses
glow = lv.obj(scr)
glow.set_size(60, 60)
glow.align(lv.ALIGN.CENTER, -45, 20)
glow.set_style_radius(18, 0)
glow.set_style_bg_color(lv.color_hex(VIOLET), 0)
glow.set_style_border_width(0, 0)
glow.set_style_shadow_color(lv.color_hex(VIOLET), 0)
glow.set_style_shadow_opa(lv.OPA._70, 0)
anim(glow, 0, 30, 900, lambda o, v: o.set_style_shadow_width(v, 0), repeat=-1, playback=900)

# Rotating square (transform_rotation is in 0.1 degree units)
sq = lv.obj(scr)
sq.set_size(50, 50)
sq.align(lv.ALIGN.CENTER, 45, 20)
sq.set_style_bg_color(lv.color_hex(AMBER), 0)
sq.set_style_border_width(0, 0)
sq.set_style_transform_pivot_x(25, 0)
sq.set_style_transform_pivot_y(25, 0)
anim(sq, 0, 3600, 4000, lambda o, v: o.set_style_transform_rotation(v, 0), path=lv.anim_t.path_linear,
        repeat=-1)

# Outline + opacity
ghost = lv.obj(scr)
ghost.set_size(120, 26)
ghost.align(lv.ALIGN.CENTER, 0, 80)
ghost.set_style_bg_color(lv.color_hex(BLUE), 0)
ghost.set_style_outline_color(lv.color_hex(BLUE), 0)
ghost.set_style_outline_width(3, 0)
ghost.set_style_outline_pad(4, 0)
ghost.set_style_radius(13, 0)
anim(ghost, 60, 255, 1200, lambda o, v: o.set_style_opa(v, 0), repeat=-1, playback=1200)
print("Press the button: its colour and size transition smoothly.")
Loading post…

Dialog