diff --git a/docs/src/details/auxiliary-modules/xml/api.rst b/docs/src/details/auxiliary-modules/xml/api.rst index 7d989cb631..d0333ad817 100644 --- a/docs/src/details/auxiliary-modules/xml/api.rst +++ b/docs/src/details/auxiliary-modules/xml/api.rst @@ -4,334 +4,314 @@ API === -The ```` tag can be a child of ```` and ```` tags, although -each supports slightly different features. +The ```` tag can be a child of ```` and ```` tags. +The only common point is that both Widgets and Components support having +```` (properties) in the ```` tag to describe their interface. +However, as Widgets and Components work very differently (Widgets have C code, +but Components are pure XML), even properties are interpreted differently. -Properties +Components ********** -Inside ```` elements, ```` elements can be defined to describe the arguments. +Overview +-------- -For **Widgets**, all properties are optional. -If a property is not set on an instance of a Widget, it simply won't be applied, -and the created Widget's default value for that property will be used (e.g., ``text`` -for a label's text). +While Widgets can have complex ``set``/``get`` APIs, Components are very simple. -For **Components**, all properties are mandatory; however, default values can be defined -to be used when a property is not set. - -If a property has only one parameter (which is usually the case), a shorthand syntax -can be applied as shown below. - -For example: +When their XML is converted to a C file, only a ``create`` function is generated, +where all the ````s are arguments. For example: .. code-block:: xml - - - - - + + -When a property is used, all parameters are set as a single attribute value. For example: - -.. code-block:: xml - - - -For **Widgets**, each property corresponds to a setter function. -The ``name`` in ```` is used to build the name of the setter function like this: +This generates the following C function: .. code-block:: c - _set_(lv_obj_t * obj, , , ...); + lv_obj_t * my_component_create(lv_obj_t * parent, int32_t prop1, const char * prop2); -For **Components**, the exported code contains only a single ``create`` function -to which all the properties are passed: +These properties are set once (at creation time), and there are no specific +``set`` functions to modify the property later. LVGL's general API can still be +used to modify any widget in the component, but no dedicated API functions are generated. -.. code-block:: c +Referencing properties +---------------------- - _create(lv_obj_t * parent, , , ...); +````s are simply forwarded to widget or component APIs. +For example, if a component has ````, +it can be used in a label as ````. -```` elements have an optional ```` boolean attribute. -By default, it is ``false``, but if set to ``true``, the given property will be -applied after all children are created. A practical example is setting the current -tab of a tab view, which cannot be set before the tabs are created. This feature is -not supported yet. +In the generated code, these are passed as arguments in create/set functions. +Default values +-------------- +Since each property is passed as an argument to the create function, each must have a value. +This can be ensured by: -```` -************* +- Setting them in the XML instance +- Providing a default value, e.g., ```` -This tag is used only with Widgets. It is used to define new enum types for a given -Widget. It should contain ```` elements to define possible options. +Limitations +----------- -Example: +Note that none of the Widget API features such as ````, ````, or ```` +can be used for Components. Only simple properties that are forwarded are supported. + +Example +------- + +.. code-block:: xml + + + + + + + + + + + + + + + + + + + + + + + +Widgets +******* + +Properties +---------- + +Properties are the core part of describing a Widget's API. + +.. code-block:: xml + + + + + +Parameters +---------- + +Some properties take multiple parameters. For example: +:cpp:expr:`lv_label_set_bind_text(label, subject, "%d °C");` + +It's described as: + +.. code-block:: xml + + + + + + + + +And used as: + +.. code-block:: xml + + + +Parameters with the same name as the property can be referenced directly. +Other parameters use ``property-param`` notation. + +Unset parameters fall back to: + +- Their default value (if defined) +- Type-specific defaults (e.g., 0, false, NULL) + +Mapping +------- + +Each ```` is mapped to a ``set`` function. This mapping is implemented +in the Widget's XML parser. +See `the LVGL XML parsers `_. + +If ````s are used, they are passed to the same ``set`` function. +If a property is not set on a Widget instance, it is skipped and the Widget's +built-in default is used. + + +--------- + +Only used with Widgets, this tag defines enums for parameter values. .. code-block:: xml - - -Note that the enum values are not important because: +Enum values are ignored in export; the names are used and resolved by the compiler. +XML parsers must handle mapping enum names to C enums. -1. When the code is exported, the enum names will be used, and the compiler generates - its own value for each enumerator symbol. -2. When loaded from XML, the Widget's XML parser should convert the enum names to C - enum fields. + +-------- +Also exclusive to Widgets, elements define sub-widgets or internal structures +(e.g., chart series, dropdown list, tab views). +They support ```` and ````: -```` -************* +- ````s are required and used for creation. +- ````s are optional and mapped to setters. -```` tags also apply only to Widgets. Elements are used to describe -sub-Widgets or internal parts of Widgets. Examples include the list of a dropdown, -the tabs of a tab view, or the data series of a chart. +Elements are referenced as ```` in views. -Elements can have ```` and ```` definitions. ```` elements are -mandatory (default values are supported) as they are used to create the element, -whereas ```` elements are optional as they are mapped to setter functions. +Name parts are separated by `-` (not allowed inside names). -An element in a ```` can be referenced like this: ````. -Note that the ``-`` separates two names inside that tag name: the Widget name and the -element name. ``-`` is not allowed in Widget and element names. Only ``_`` can be -used to separate words in tag names. +Element `access` types: -Example: +- ``add``: Create multiple elements dynamically. +- ``get``: Access implicitly created elements. +- ``set``: Access indexed parts (e.g., table cells). + +``type="obj"`` allows children; custom types do not. + +Only the API can be defined in XML for elements; implementations must be in C. + +access="add" +~~~~~~~~~~~~ + +Elements are created via an ``add`` function: .. code-block:: xml - - -An important attribute of elements is ``access``. The possible values are: - -- ``add``: Create any number of elements dynamically (e.g., chart series). -- ``get``: Get a pointer to an implicitly created Widget or any data (e.g., list of a Drop-Down List). -- ``set``: Select specific parts of the Widget with indexes (e.g., table cells). - -Elements with ``access="add"`` or ``access="get"`` can have a custom data type -defined using ``type="my_data"``. In these cases, no children can be added. If the -``type`` is ``lv_obj``, the element can have children. - -It is not yet possible to describe the ```` of elements in XML; only the API can be defined. -The actual implementation needs to be done in C. - - -``access="add"`` ----------------- - -The element is explicitly created with an ``add`` function, e.g., ``lv_tabview_add_tab(obj, "Title");``. - -```` elements defined as direct children of the ```` are passed to the -``add`` function as arguments. - -Example: - -.. code-block:: xml - - - - - - - + + + + + - -