LVGL Json UI Backend Notes
This page records how brookesia_gui_lvgl implements the resolved JSON UI model. The JSON UI protocol fields themselves are still governed by
gui/brookesia_gui_interface/docs/json_ui; this page only explains how the LVGL backend realizes those fields.
Backend Pump
gui::Runtime::process_backend() forwards to the LVGL backend timer processing. In standalone examples or scenarios without a system main loop, call this interface periodically to drive LVGL animations, events, and internal timers.
Image .Bin
LVGL backend supports LVGL v9 image .bin:
RuntimeImageResource.primary_srcorimageSet.images[].srccan point to a.bin.Runtime::register_image(...), when width/height are missing, asks the LVGL backend through the backend metadata hook to read the.binheader and completewidth/height.the
.binis read into an in-memory descriptor through the backend preload hook during document load.the backend caches
.bincontent by image path and keeps a reference count; the same path is read only once even when referenced by multiple documents or global images.binding updates,
set_view_src(...), and props apply only reuse the preloaded descriptor and do not read files on the dynamic path.
For build-time PNG-to-.bin conversion, see LVGL Image Packaging.
Layout
layout.type mapping:
JSON value |
LVGL behavior |
|---|---|
|
|
|
|
|
|
In layout.gridTemplateColumns / layout.gridTemplateRows:
Dimension |
LVGL descriptor |
|---|---|
fixed px |
fixed track |
|
|
percent |
|
|
|
The backend does not currently expose the LVGL track cross-place parameter separately; crossAlign applies to both cross place and track cross place.
Placement
placement mapping:
Field / Mode |
LVGL behavior |
|---|---|
|
|
|
|
|
|
|
|
|
after sizes are applied, the outer frame is corrected a second time using fit short-edge semantics |
|
|
|
|
grid child fields |
|
out* placement align requires relativeTo, because LVGL parent-object alignment itself has no outside anchor.
Image sizing:
Placement size |
LVGL backend behavior |
|---|---|
|
use the image asset width/height to set object size and keep the original image ratio |
both |
use the fixed outer frame; image content is controlled by |
use percent / |
keep the explicit frame size; not overridden by the image asset width/height |
Props
Commonprops
scrollable = true: addsLV_OBJ_FLAG_SCROLLABLEand sets scrollbar mode toAUTO.scrollable = false: removesLV_OBJ_FLAG_SCROLLABLEand sets scrollbar mode toOFF.pressLock = true: addsLV_OBJ_FLAG_PRESS_LOCKand keeps locking the current pressed target when the press slides outside the node bounds.pressLock = false: removesLV_OBJ_FLAG_PRESS_LOCKand lets LVGL re-hit the target and firepressLostwhen the press slides out of range.pivotX/pivotYpercentage values refresh the object layout once before applying the transform, avoiding pivot calculation at(0, 0)when early sizes are not yet updated.
Image Props Inner Align
JSON value |
LVGL align |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Image Props Recolor
recolor = "#RRGGBB": callslv_obj_set_style_image_recolor().recolorOpacity = 0..255: callslv_obj_set_style_image_recolor_opa().recolor = "": removes the image node's local image-recolor property and falls back to the style/theme layer effect.
Style Image Recolor
imageRecolor = "#RRGGBB": callslv_style_set_image_recolor().imageRecolorOpacity = 0..255: callslv_style_set_image_recolor_opa().imageRecolor = ""or unset: removes the style-layer image-recolor property.
Keyboard Props Mode
JSON value |
LVGL mode |
|---|---|
|
|
|
|
|
|
|
|
The JSON UI parser/validator rejects unknown modes; on an invalid mode, the backend keeps the currently available layout.
Keyboard Props Target Text Input / Layouts
targetTextInput resolves to a target textInput within the same document. The backend does not hand the target to the LVGL default keyboard
handler; instead it caches the target object and writes manually by JSON key role on LV_EVENT_VALUE_CHANGED, so control-key display text or
image resource ids are not inserted as plain characters.
keyboardProps.layouts is converted into the LVGL keyboard map:
the
text,upper,number, andspeciallayouts each bind to the corresponding LVGL keyboard mode.a string key is used directly as the key text.
a
role=modekey uses themodefield to switch layout; when the target mode is not inallowedModesit is drawn in the disabled style and clicks are ignored.a key with
rolebut notextmaps to an LVGL symbol or control key, such asbackspace,left,right,space,ok,cancel.a key with
roleand a settextusestextas the fallback display, whilerolestill determines behavior.a key with
imagehides its label and centers the registered image resource onLV_EVENT_DRAW_TASK_ADDED;keyboardProps.iconSizecontrols the target icon size and creates no per-key child object.widthmaps to the relative width inlv_keyboard_set_ctrl_map(); its range is guaranteed by the JSON UI parser/validator.keyStylesmodifies the fill/label color ofLV_PART_ITEMSthrough a draw-task hook, supporting the normal, control, mode, confirm/cancel, and disabled classes.
Canvas Props Commands
The current LVGL backend supports:
|
Behavior |
|---|---|
|
fills the canvas background with |
|
sets the pixel at |
The width / height fields are accepted by the parser but unused by the current LVGL canvas command execution.
Style
During style apply, the LVGL backend maintains each node's lv_style_t and updates the relevant fields by dirty mask. Typical mapping:
JSON style fields |
LVGL operations |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Font resolution priority:
the native LVGL font in
ResolvedFontSpec.native_fontsclosest to the requested size.the
primary_srcof the JSON/backend font resource, creating a FreeType font along the fallback chain.a built-in font; used as fallback when FreeType or the file is unavailable.
Animations
Animations run through LVGL anim. Main property mapping:
Property |
LVGL operations |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
Easing mapping:
JSON value |
LVGL path |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|