docs/src/xml/best_practices.rst
.. _editor_best_practices:
These guidelines help keep projects organized, maintainable, and easier to scale when working with the LVGL Pro Editor.
Avoid project names that may conflict with libraries or frameworks.
Do NOT use:
lvglRecommended:
This prevents naming conflicts and keeps the build system clean.
Use clear and consistent prefixes for generated assets.
Images
icon_image_Fonts
Use structured naming to handle different sizes and styles:
font_<name>_<size>font_<name>_<size>_<format>Examples:
font_roboto_14_regularfont_roboto_16_boldThis is especially important when managing multiple font sizes and formats such as bold, italic, or medium.
Keep raw resources separate from generated resources.
Recommended structure:
::
images/ images/raw/
Example:
::
images/raw/icon_home.png images/icon_home.c
For assets with multiple sizes, include the size in the filename:
icon_home_20dp.pngicon_home_40dp.pngBenefits:
Use a consistent prefix for subjects.
subject_settingssubject_homeThis improves readability and ensures naming consistency across the project.
Always prefix styles.
Base styles:
style_buttonstyle_containerstyle_textTheme variants:
If multiple themes are used (e.g., dark and light), include a theme prefix:
style_dark_buttonstyle_light_buttonThis approach simplifies theme management and scaling.
Create screens, components, and widgets using their respective folders.
Recommended approach:
Use:
This automatically organizes them into subfolders, improving navigation and maintainability.
Use a prefix for widgets:
wd_menuwd_statusbarwd_clockThis makes widgets easy to identify and avoids naming conflicts.
Files generated by the editor are overwritten during regeneration.
Do not modify them directly.
Instead:
Direct edits to generated files will be lost.
Minimize the use of inline style attributes.
Avoid:
.. code-block:: xml
<lv_obj style_bg_color="0x000000" style_bg_opa="255" />
Recommended:
.. code-block:: xml
<styles> <style name="style_obj" bg_color="0x000000" bg_opa="255" /> </styles><lv_obj> <style name="style_obj" /> </lv_obj>
Benefits:
Avoid defining API properties that may conflict with editor-specific behavior.
Avoid:
.. code-block:: xml
<prop name="name" type="text" />Also avoid unnecessary API overrides:
.. code-block:: xml
<api> <prop name="width" type="int" /> </api> <view width="$width" />Recommended:
Use the help property to document API usage:
.. code-block:: xml
<api name="text" type="string" help="Sets the label text of the component" />Avoid overriding default states or flags on the root object unless necessary.
Avoid:
.. code-block:: xml
<component> <view checked="true" /> </component>Recommended:
Set such properties when the component is used within a screen.
This ensures components remain flexible and reusable.
Avoid combining fixed component sizes with fixed child sizes.
Not recommended:
.. code-block:: xml
<view width="content"> <lv_dropdown width="420" /> </view>This prevents proper resizing when the component is reused.
Recommended:
.. code-block:: xml
<view width="420"> <lv_dropdown width="100%" /> </view>Benefits: