lvgl-ui-layout
Skill1 starsChanged 8 days agoMITView on GitHub
Design, implement, review, and repair adaptive LVGL 9.6 user interfaces in MicroTech, with emphasis on Flex/Grid sizing, content-driven containers, per-class text display policy (one-line identifiers, wrapped prose, external input), text measurement and wrapping, clipping and overlap prevention, scroll ownership, touch propagation, and efficient label construction. Use when an LVGL page or widget clips text, ellipsizes required information, wraps a title, leaves an orphaned punctuation tail, overlaps controls, scrolls incorrectly, loses touch gestures over children, relies on absolute coordinates, uses truncating label modes, or needs responsive layout and host-test coverage.
In this repository12 other files it gives its agents.
- AGENTS.mdAGENTS.md
- aesthetic-reviewSkill
- app-developmentSkill
- codesizeSkill
- design-contractSkill
- device-operationsSkill
- esp32Skill
- lvgl-integrationSkill
- motion-interactionSkill
- ui-reviewSkill
- ux-heuristicsSkill
- visual-designSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 6 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Read AGENTS.md, the locked LVGL version, project theme/fonts, target display dimensions, parent page helper, and relevant host fakes.
- Distinctive: line 19
Read references/lvgl9-layout-patterns.md when budgeting a page against the viewport, selecting a label policy, or changing event and scroll …
- Very specific: line 24
Treat findings as review prompts, not proof of defects.
- Very specific: line 41
Use percentages only against a parent with a resolved size.
- Very specific: line 44
Use LV_SIZE_CONTENT for content-driven containers and unconstrained short labels.
- Distinctive: line 48
Keep fixed pixels only where the invariant is real: touch targets, bitmap dimensions, chart/canvas geometry, bounded controls, or …
- Distinctive: line 93
Create it and establish passive or interactive behavior.
- Very specific: line 96
Call lv_label_set_text() or lv_label_set_text_fmt() last.
- Very specific: line 115
Never "fix" a T1 overflow by switching to DOT or by squeezing a sibling.
- Very specific: line 126
Never hand-insert \n to fake a break.
- Distinctive: line 151
Keep short numeric values, symbols, and fixed units content-sized.
- Very specific: line 175
Read the fit verdict from the simulator, not from the box height: sim.tree reports long_mode, max_lines, line_space and a lines array with …
- Very specific: line 187
Remove LV_OBJ_FLAG_CLICKABLE from passive generic containers and overlays.
- Very specific: line 188
Do not add it to decorative labels or symbols.
- Very specific: line 191
Add LV_OBJ_FLAG_EVENT_BUBBLE, LV_OBJ_FLAG_GESTURE_BUBBLE, or scroll-chain flags only after naming the intended receiver and axis.
- Distinctive: line 194
Verify taps and vertical drags that begin over every child label, icon, image, and nested control.
- Very specific: line 231
Run the narrow host tests and project-required formatting/diff checks.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
LVGL UI Layout
Build layout contracts from the outside in. Treat every dynamic label, flex track, scrollable axis, and input target as an explicit constraint rather than fixing visible symptoms with additional coordinates.
Establish the Current Contract
- Read
AGENTS.md, the locked LVGL version, project theme/fonts, target display dimensions, parent page helper, and relevant host fakes. - Inspect the complete object tree and all style padding, border, gap, width, height, flex/grid, scroll, and event flags that affect it. Do not reason from a cropped source fragment.
- Read references/lvgl9-layout-patterns.md when budgeting a page against the viewport, selecting a label policy, or changing event and scroll propagation.
- Optionally run
scripts/audit_lvgl_layout.py <paths>to locate suspicious absolute positioning, truncation, label setup order, and clickable labels. Treat findings as review prompts, not proof of defects. The script does not see through project helpers:BUTTON_CHILD_INPUTis usually cleared byapp_ui_make_passive(), andFONT_ROLE_REVIEW/MISSING_EXPLICIT_FONTare usually satisfied by theapp_ui_*label constructors' explicit font binding, so confirm against the helper before acting on those two codes.DOT_WITHOUT_WIDTHmeans aDOTlabel in this file never received a width, so the ellipsis can never appear and the text is silently cut by the parent instead; give it a width or flex share, or pick another long mode. Trace dynamic font, symbol, and object-helper arguments manually when the script reports an indirect role or cannot see the call site.
Design Outside In
- Define the page's usable content rectangle after header, safe area, border, padding, and scrollbar reservation.
- Give each axis one owner. Use Flex for ordered rows/columns and Grid for aligned two-dimensional data. Use alignment for overlays and anchors.
- Use percentages only against a parent with a resolved size. Do not put a
percentage-sized child on the same axis as an
LV_SIZE_CONTENTparent; that creates a circular size dependency. - Use
LV_SIZE_CONTENTfor content-driven containers and unconstrained short labels. Uselv_obj_set_flex_grow()or Grid fractional tracks for remaining space. Budget fixed children, gaps, padding, and borders before assigning flexible space. - Keep fixed pixels only where the invariant is real: touch targets, bitmap dimensions, chart/canvas geometry, bounded controls, or font-derived line boxes. Document the invariant and test its worst case. Do not use guessed coordinates to assemble ordinary page content.
- Decide fit before scroll. Measure the page's vertical extent (last child
bottom plus
pad_bottom, which counts toward the scrollable range) against the viewport. When everything fits with a clean composition, disable scrolling explicitly (LV_DIR_NONEand clearSCROLLABLE); never leave a few-pixel rubber band. When it cannot fit, keep the page content as the one scroll owner, distribute rows with a uniform gap, and end the first screen on a whole-row boundary so no control is sliced by the viewport edge. Disable accidental horizontal scrolling and avoid nested scrollables unless their handoff is specified. When a page must land exactly on the viewport, let fractional grid rows (LV_GRID_FR) withLV_GRID_ALIGN_SPACE_BETWEENabsorb the slack instead of guessed gaps.
Adapt Across the Supported Panels
Resolve the target profile from doc/design/targets/ and the selected
product/board manifest; do not hardcode a panel size in a page or in this
skill. The current products include the ESP32-S3 368 x 448 AMOLED and the
ESP32-P4 320 x 480 IPS, but a new board is a new target profile, not a reason
to fork a page. Read the resolved density before choosing raw pixels versus
lv_pct()/LV_GRID_FR(); do not port the demos' LV_DPX(), LV_HOR_RES, or
size-class tiering unless the target profile actually provides a different
density. Derive the available content box from the current page and target
profile, and keep geometry adaptive across targets:
- Let content-driven sizing carry the design (
LV_SIZE_CONTENT,lv_obj_set_flex_grow(), fractional grid tracks), and cap a content-sized card or chart withlv_obj_set_style_max_*()when its content is unbounded. - For geometry Flex/Grid cannot express (a dial needle, canvas annotation, or
centered overlay), resolve it after
lv_obj_update_layout()and recompute it in anLV_EVENT_SIZE_CHANGEDhandler instead of writing literals. - Exclude decorative overlays from the flow with
lv_obj_set_ignore_layout()and keep them fixed under scroll withlv_obj_set_floating(), then position by alignment. Confirm they do not intercept input meant for the content.
See references/lvgl9-layout-patterns.md for the concrete patterns.
Give Every Label a Policy
Configure a label before assigning its first real text:
- Create it and establish passive or interactive behavior.
- Set width/height or flex/grid participation and long mode.
- Set font, color, letter/line spacing, and alignment.
- Call
lv_label_set_text()orlv_label_set_text_fmt()last.
Bind project fonts explicitly rather than relying on inheritance or widget
defaults. Bind every ordinary text label, including Chinese and dynamic text,
to the appropriate APP_THEME_FONT_* role. Bind every LV_SYMBOL_* label to
LV_FONT_DEFAULT. Do this before assigning text so layout uses the final font
and available glyph set; treat a missing explicit binding as a defect even when
the current theme happens to render correctly.
Select sizing by text class. Pick the class first; the class decides the long mode, not the other way round.
T1: fixed-shape labels. Page titles, section headings, row titles, status
words, chip and button captions, values with units. The app authors this text,
so it must render as one line: bounded width (or content width) plus
LV_LABEL_LONG_WRAP with a content-driven height. When it does not fit,
condense the copy first (drop separators, the least essential segment, or
trailing punctuation) and only then change the layout (wider container, split
the fact onto its own row, delete what the selection state already shows).
Never "fix" a T1 overflow by switching to DOT or by squeezing a sibling.
Verification: the simulator tree reports len(lines) == 1.
T2: authored prose. Explanations, warnings, empty states, sheet messages,
app_ui_add_body_label bodies. Give it its own region: LV_PCT(100) width,
LV_LABEL_LONG_WRAP, LV_SIZE_CONTENT height, and a page that can scroll or
that fits its worst case. A multi-line paragraph must not end on a 1–2 cluster
tail (a lone character or punctuation mark): widen the label by 8–24 px inside
its own layout first, then shorten the copy, then split it into two paragraphs.
For self-wrapped prose these are all one knob — pad_left/pad_right — because
app_ui_wrap_prose() breaks lines from lv_obj_get_content_width(label).
Never hand-insert \n to fake a break; app_ui_set_prose_text() is the one
sanctioned wrapper because it applies the line-start/line-end kinsoku rule
sets (layers/apps/common/src/app_ui_text.c). LVGL's own wrap has no kinsoku
rules: it breaks at LV_TXT_BREAK_CHARS and anywhere inside CJK, so free-form
prose that matters must go through that helper.
T3: external input. SSID (≤32 B), recording file names (≤64 B), weather
city/alert title/body, app display_name, mount paths. Length is not yours to
choose, so pick the treatment by position:
| Position | Treatment | Why |
| Primary identifier of a list row (SSID, file name, alert title) | Row height LV_SIZE_CONTENT with min_height APP_UI_ROW_HEIGHT; identifier LV_LABEL_LONG_WRAP on the full row width | The user picks from it and must read it whole |
| Passive header identifier (weather city) | LV_LABEL_LONG_SCROLL_CIRCULAR | Locked decision, asserted in tests/integration/test_cross_layer.c |
| Value in a compact summary row (the settings row labelled "网络" (Network), Bluetooth name) | LV_LABEL_LONG_DOT allowed, but only if the complete value is readable on the owning detail page or confirm sheet | The summary is not the decision surface |
| Unbounded block text (alert body and advice) | Own WRAP region plus app_ui_set_prose_text(); overlong text is flagged by content_truncated | Already implemented in weather_alert_pages.c |
Two hard constraints close this class. Never cap required text with
lv_label_set_max_lines(): in WRAP mode it only clamps the computed height
and adds no ellipsis, which is silent clipping. A DOT label is only
acceptable when its full value is reachable in one step; an ellipsis on a
primary identifier is a defect, not a style choice.
The rest of the policy:
- Keep short numeric values, symbols, and fixed units content-sized. Keep a value and inseparable unit in one label, or in a non-wrapping content-sized row whose worst-case width is proven.
- Give frequently changing bounded values a stable width based on their worst-case formatted text to prevent layout jitter.
- Transient feedback never owns layout space. Do not reveal a transient
message by unhiding a label inside a flex/grid flow; that moves every
following control. Use
app_ui_toast_show(page->root, text), which appliesIGNORE_LAYOUT+FLOATINGat the page root and auto-dismisses. LV_LABEL_LONG_SCROLL_CIRCULARanimates forever: the page never goes idle, which breaks simulatorwait_idlecoverage and burns refresh cycles. Reserve it for a single prominent header or status label, never for repeated list rows. A locked product decision to keep long text fully readable is a deliberate exception: MicroTech's weather header city and status staySCROLL_CIRCULARand are asserted intests/integration/test_cross_layer.c; do not downgrade them without updating that contract. Treat the no-idle cost as a review flag, not an automatic edit.app_uirow titles and summaries still useDOT. They are the target of this policy, not an example of it: change them together with their row height the next time you touch those rows.- Measure actual fonts and strings with
lv_text_get_size()andlv_font_get_line_height()when a tight bound is unavoidable. Include Chinese glyphs, fallback fonts, negative values, units, and line spacing; do not infer geometry from nominal font size. - Read the fit verdict from the simulator, not from the box height:
sim.treereportslong_mode,max_lines,line_spaceand alinesarray with each rendered line's text and pixel width. AWRAPlabel clipped by a fixed height still reports its fulltext, soexpect_visiblealone can never prove it fits — theclipped text,clipped by parentandtruncated textlints are the detectors.
Define Input Ownership
- Let the nearest interactive ancestor own an ordinary tap whenever possible.
LVGL 9.6 generic objects start clickable, while labels remove
CLICKABLEin their constructor. Inspect each widget class rather than assuming defaults. - Remove
LV_OBJ_FLAG_CLICKABLEfrom passive generic containers and overlays. Do not add it to decorative labels or symbols. Remember thatlv_obj_remove_style_all()changes styles only; a styleless generic wrapper inside a button remains clickable and can intercept the button's center. - Add
LV_OBJ_FLAG_EVENT_BUBBLE,LV_OBJ_FLAG_GESTURE_BUBBLE, or scroll-chain flags only after naming the intended receiver and axis. They solve different propagation problems and are not interchangeable. - Verify taps and vertical drags that begin over every child label, icon, image, and nested control. Confirm that an interactive child neither triggers its parent accidentally nor blocks the intended page scroll.
- A row container that forwards taps to an inner switch needs three
coordinated pieces: make the row
CLICKABLE(dropPRESS_LOCK), toggle the switch on the row'sCLICKED, and emitLV_EVENT_VALUE_CHANGEDexplicitly because a programmatic state flip never fires it; guard the handler withlv_event_get_target(event) != lv_event_get_current_target(event), since 9.6 propagates a child'sCLICKEDup to clickable ancestors and an unguarded forward double-toggles a direct switch tap. There is nolv_obj_toggle()in LVGL 9.6; uselv_obj_has_state()with add/remove. - An
lv_async_callcannot be cancelled (nolv_async_call_deletein LVGL 9.6), so deferred work — such as rebuilding a list from inside a clicked row's own callback — must re-validate its page root in the callback and no-op when the page is gone. - A control that activates on tap must bind only
LV_EVENT_CLICKED; never fire onPRESSED,PRESS_LOST, orRELEASED. In LVGL 9.6 clickable objects inheritLV_OBJ_FLAG_PRESS_LOCK, soCLICKEDstill fires when the finger slides off before release. Callapp_ui_click_only()(dropsPRESS_LOCK) on every click-activated button, row, chip, and switch so leaving the control sendsPRESS_LOSTand cancels activation; verify with a simulatordragthat starts on the control and ends outside it, asserting no navigation. App Manager and other code that cannot includeapp_uimust drop the flag directly withlv_obj_set_press_lock(obj, false); every click-activated control in the app_manager system layer (control-center tiles and power buttons, task-switcher buttons) needs the same treatment.
Validate Before Declaring the Layout Fixed
- Force layout calculation with
lv_obj_update_layout()in diagnostics or tests before reading coordinates. Check child bounds against the parent's content rectangle and verify that required text is not clipped. - Extend the LVGL host fake to record explicit width, height, long mode, font, flags, parentage, and events when the changed contract depends on them, and let host tests drive gestures that begin over child content — labels, rows, gaps — not only direct taps on the parent.
- Run the narrow host tests and project-required formatting/diff checks.
Broader sanitizer, firmware-build, and hardware scope follows the
doc/verification.mdworkflow. - Simulator-side validation — worst-case data states (shortest, longest,
missing, loading, error; signed numeric formats; multi-line Chinese), the
scroll policy checked both ways by dragging (a scrolling page must move
scroll.y; a pinned page must stay at 0 withflags.scrollablefalse), geometry judged fromcoordsandstyles.line_heightrather than a PNG, and the release gate — are specified once, by theui-reviewskill at its assigned tier. Reserve the real display for touch feel, RF, and AMOLED color only.
Report the tested resolutions, data extremes, interaction paths, and any unexecuted hardware checks. Do not claim that a single nominal screenshot proves adaptive behavior.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

