Overview

Master XML syntax rules, naming conventions, and property types used in LVGL Pro Editor for defining UI components.

LVGL Pro Editor uses standard XML syntax with special conventions for property names, values, and type definitions that follow LVGL API patterns.

Naming Conventions

  • Attribute names use lowercase letters with _ separation (e.g., bg_color, font_size)
  • Tag names must start with a letter or _ and can contain letters, _, and digits
  • Compound names use - as separator (e.g., lv_chart-series)
  • Color values support multiple formats like CSS:
    • Hex with prefix: 0x112233 or #112233
    • Hex without prefix: 112233
    • Short hex: 0x123, #123, or 123 (all equivalent to #112233)
  • LVGL API alignment: Follow LVGL naming conventions (e.g., align="center", bg_color="0xff0000")
  • Parameter references: Use $ prefix (e.g., $param_name)
  • Constant references: Use # prefix (e.g., #const_name)

Property Names

Most XML properties use standard syntax without special formatting:

xml
<some_tag prop="value" other_prop="other value"/>

Style selectors can be added to property names for advanced styling:

xml
<lv_checkbox style_bg_color-indicator-checked-disabled="0xff0000"/>

Types

All types can be used as API property types. Some types are also supported for constants and observer subjects.

Simple Types

TypeDescriptionExample
boolBoolean valuetrue or false
intInteger (-2B to 2B, equivalent to int32_t)42, -100
pxPixel units (unit can be omitted)10, 10px
%Percentage (must include % unit)50%, 100%
contentAuto-sizing constant (LV_SIZE_CONTENT)content
stringNull-terminated string"hello", "'a' 'b'" (multiple)
color24-bit RGB color value0xff0000, #ff0000
opaOpacity (0-255 or 0-100%)128, 50%
lv_objWidget object pointerReference to widget
screenScreen object pointerReference to screen
time_msTime in milliseconds500, 1000
deg_0.1Degrees with 0.1 resolution45.5, 180
scale_1/256Scale/Zoom (256=100%, 128=50%)256, 512
style_propStyle property namebg_opa, text_color

LVGL's XML parser follows the HTML standard where there are reserved characters in property values. For example ", ', <, >, and new line.

So this is invalid: value="I'm here"' needs to be escaped as "I&apos;m here".

The Editor show a little popup when you click on a string property, where you can write text in the normal way, and the editor will handle the escaping.

Text editor popup in the Editor to automatically escape reserved XML characters

Name-Based Types

In XML files, fonts, images, styles, and other assets are referenced by name, not by pointer:

xml
<style name="red" bg_color="0xff0000"/>

Automatic binding occurs for:

  • Styles, fonts, images, animations
  • Gradients and other visual components
  • Components and globals registered in globals.xml

Manual binding is required for:

  • Event callbacks (only available in code)
  • Custom fonts or images stored in memory

To register name-data pairs, see the Editor Integration guide.

Arrays

Arrays can be defined in three ways:

SyntaxDescription
int[5]Array with a fixed set of elements.
string[NULL]Array terminated with a NULL element. NULL can be any other string too.
string[]No termination or count parameter

The termination of the array is important only to

  1. Validate the correctness of the XML files
  2. Generate correct code

The items in the array are separated by spaces and the termination is not included. For example

If there is an <api> property like <prop name="values" type="int[3]"/> it can be used as <my_widget values="10 33 55"/>

String items need to be wrapped in ' because an item can be composed of multiple words, so a space alone can't be used as a separator. For example <prop name="list" type="string[NULL]"/> it can be used as: <my_widget values="'This is the first' 'The second' '3rd'"/>

Enums

Custom enums for Widgets can be created using enumdef (not supported for Components):

xml
<api>
  <enumdef name="my_widget_mode" help="Possible modes">
    <enum name="normal" value="0x10" help="Normal mode"/>
    <enum name="inverted" help="Inverted mode"/>
  </enumdef>

  <prop name="mode" type="enum:my_widget_mode" help="Select mode"/>
</api>

Multiple enum values with + suffix allow OR'ing values:

xml
type="axis+"  <!-- Allows selecting multiple axis values -->
axis="primary_x|secondary_y"  <!-- Separate with | -->

Compound Types

Types can be combined to allow multiple options. For example:

xml
type="px|%|content"  <!-- Accepts pixels, percentage, or auto-size -->

Limiting Accepted Values

This feature is planned but not yet supported. The examples below show the intended syntax.

You can restrict possible values for enums, colors, and strings:

xml
<!-- Enum with limited options -->
type="dir(top bottom)"

<!-- Color with color palette -->
type="color(0xff0000 0x00ff00 0x0000ff)"

<!-- String with fixed options -->
type="string('Ok' 'Cancel')"

How is this guide?

Last updated on

On this page