MantisIDE

Text and fonts · Round 1.28" touch watch

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

Widget gallery 8 - Text: label long modes, recolouring, span groups, symbols

You’ll learn: long modes, recolor, spangroup, symbols

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 8 - Text: label long modes, recolouring, span groups, symbols
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
VIOLET = 0xB593FF

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


L = lv.label
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)

# Scrolling marquee (circular)
marquee = lv.label(scr)
marquee.set_width(150)
marquee.set_long_mode(L.LONG_MODE.SCROLL_CIRCULAR)
marquee.set_text("This text is too long, so it scrolls around forever  -  ")
marquee.set_style_text_color(lv.color_hex(ACCENT), 0)
marquee.align(lv.ALIGN.CENTER, 0, -70)

# Dots at the end when it does not fit
dots = lv.label(scr)
dots.set_width(150)
dots.set_long_mode(L.LONG_MODE.DOTS)
dots.set_text("Shortened with dots because it is long")
dots.set_style_text_color(lv.color_hex(MUTED), 0)
dots.align(lv.ALIGN.CENTER, 0, -45)

# Inline colours with the recolor feature: #RRGGBB text#
rc = lv.label(scr)
if hasattr(rc, "set_recolor"):
    rc.set_recolor(True)
    rc.set_text("#ff6b6b red# #46e07c green# #6cb8ff blue#")
else:
    rc.set_text("red green blue")
rc.align(lv.ALIGN.CENTER, 0, -18)

# Span group: rich text with different styles in one paragraph
sg = lv.spangroup(scr)
sg.set_width(170)
sg.align(lv.ALIGN.CENTER, 0, 22)
for text, color in (("Rich ", TEXT), ("text ", AMBER), ("with ", TEXT), ("spans", VIOLET)):
    span = sg.add_span()
    span.set_text(text)
    st = span.get_style() if hasattr(span, "get_style") else span.style   # LVGL 9.4: get_style()
    st.set_text_color(lv.color_hex(color))
if hasattr(sg, "refresh"):
    sg.refresh()

# Fonts and symbols
label(scr, "12 px", MUTED, 12, x=-50, y=62)
label(scr, "14 px", MUTED, 14, x=0, y=62)
label(scr, "16 px", MUTED, 16, x=52, y=62)
label(scr, lv.SYMBOL.HOME + " " + lv.SYMBOL.WIFI + " " + lv.SYMBOL.BATTERY_FULL + " " + lv.SYMBOL.BELL
         + " " + lv.SYMBOL.CHARGE, BLUE, 16, y=88)
print("Label long modes: WRAP, DOTS, SCROLL, SCROLL_CIRCULAR, CLIP.")
Loading post…

Dialog