MantisIDE

Lesson 3: Layout on a round screen · Round 1.28" touch watch

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

Lesson 3 - Layout on a round screen Goal: place things with polar maths (angle + radius) and with flex layouts. A square UI loses its corners on this display - design in circles.

You’ll learn: polar positions, flex rows, symbols

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

# Lesson 3 - Layout on a round screen
# Goal: place things with polar maths (angle + radius) and with flex layouts.
# A square UI loses its corners on this display - design in circles.
import math

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

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


def dot(parent, size, color, x=0, y=0, align=lv.ALIGN.CENTER):
    """A filled circle: a plain lv.obj with every theme style removed."""
    o = lv.obj(parent)
    o.remove_style_all()
    size = max(1, int(size))
    o.set_size(size, size)
    o.set_style_radius(lv.RADIUS_CIRCLE, 0)
    o.set_style_bg_color(lv.color_hex(color), 0)
    o.set_style_bg_opa(lv.OPA.COVER, 0)
    o.remove_flag(lv.obj.FLAG.CLICKABLE)
    o.align(align, int(x), int(y))
    return o


def polar(radius, degrees):
    """(x, y) from the centre for a point on a circle; 0 deg = 12 o'clock, clockwise."""
    r = math.radians(degrees - 90)
    return int(radius * math.cos(r)), int(radius * math.sin(r))

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)

# 12 "hour" markers placed with polar coordinates
for i in range(12):
    x, y = polar(104, i * 30)
    size = 10 if i % 3 == 0 else 5
    dot(scr, size, ACCENT if i % 3 == 0 else MUTED, x, y)

# A flex row of three icons in the middle - LVGL spaces them for you
row = lv.obj(scr)
row.remove_style_all()
row.set_size(160, 50)
row.center()
row.set_flex_flow(lv.FLEX_FLOW.ROW)
row.set_flex_align(lv.FLEX_ALIGN.SPACE_EVENLY, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
for sym in (lv.SYMBOL.WIFI, lv.SYMBOL.BLUETOOTH, lv.SYMBOL.BATTERY_3):
    icon = lv.label(row)
    icon.set_text(sym)
    icon.set_style_text_color(lv.color_hex(TEXT), 0)

# Text that follows the curve: one label per character
word = "MANTIS IDE"
for i, ch in enumerate(word):
    angle = -50 + i * (100 / (len(word) - 1))
    x, y = polar(80, angle)
    label(scr, ch, BLUE, 14, x=x, y=y)

print("Built-in symbols: lv.SYMBOL.WIFI, HOME, SETTINGS, PLAY, PAUSE, BELL, GPS ...")
Loading post…

Dialog