-
Notifications
You must be signed in to change notification settings - Fork 644
docs: add project.mdx, and databinding updates #361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kisvegabor
wants to merge
5
commits into
master
Choose a base branch
from
feat/more-details
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4645fd1
docs: add project.mdx, and databinding updates
kisvegabor 86e6932
clarify path of fonts and images
kisvegabor 48bb8b6
Apply suggestion from @kisvegabor
kisvegabor 3615234
Apply suggestion from @kisvegabor
kisvegabor a776f32
Apply suggestion from @kisvegabor
kisvegabor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,6 +94,101 @@ Explanation of complex bindings: | |
| Note: The `lv_obj-` prefix can be omitted. For example, you can simply | ||
| write `bind_state_if_gt` instead. | ||
|
|
||
| ### Choosing the right attribute | ||
|
|
||
| `bind_flag_*` and `bind_state_*` look almost identical but expect a different attribute and a different set of values: | ||
|
|
||
| - `bind_flag_*` toggles a widget **flag** — use the `flag` attribute. | ||
| - `bind_state_*` toggles a widget **state** — use the `state` attribute. | ||
|
|
||
| ```xml | ||
| <!-- Set the "hidden" flag while subject_mode != 1 --> | ||
| <lv_obj> | ||
| <bind_flag_if_not_eq subject="subject_mode" flag="hidden" ref_value="1"> | ||
| </lv_obj> | ||
|
|
||
| <!-- Enter the "checked" state while subject_lamp == 2 --> | ||
| <lv_obj> | ||
| <bind_state_if_eq subject="subject_lamp" state="checked" ref_value="2"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: This binding tag is also left unclosed, so the sample XML is invalid. Prompt for AI agents</file context> Tip: Review your code locally with the cubic CLI to iterate faster. |
||
| </lv_obj> | ||
| ``` | ||
|
|
||
| ### Valid state values | ||
|
|
||
| These match LVGL's `LV_STATE_*` constants. The same names are used as style selectors and in `bind_state_*` bindings. | ||
|
|
||
| | Value | Meaning | | ||
| |---|---| | ||
| | `default` | Widget is in its base state | | ||
| | `checked` | Widget is toggled on (e.g. a checkable button) | | ||
| | `focused` | Widget has focus from any input device | | ||
| | `focus_key` | Widget has focus from a keypad/encoder | | ||
| | `edited` | Widget is being edited (e.g. encoder edit mode) | | ||
| | `hovered` | Pointer is over the widget | | ||
| | `pressed` | Widget is currently pressed | | ||
| | `scrolled` | Widget is being scrolled | | ||
| | `disabled` | Widget rejects input | | ||
|
|
||
| ### Valid flag values | ||
|
|
||
| The most commonly bound `LV_OBJ_FLAG_*` flags, exposed by the same names without the prefix: | ||
|
|
||
| | Value | Effect when set | | ||
| |---|---| | ||
| | `hidden` | Widget is not drawn and ignores input | | ||
| | `clickable` | Widget can be pressed/clicked | | ||
| | `checkable` | Click toggles the `checked` state | | ||
| | `scrollable` | Widget can be scrolled | | ||
| | `scroll_on_focus` | Parent scrolls so the focused child is visible | | ||
| | `floating` | Excluded from the parent's layout | | ||
| | `ignore_layout` | Ignored by the parent's layout | | ||
|
|
||
| For the full list of states and flags see LVGL's [Object basics](https://lvgl.io/docs/open/intro/basics) and [Style states](https://lvgl.io/docs/open/main-modules/style#states) reference. | ||
|
|
||
| ## Selection groups via a shared subject | ||
|
|
||
| A common pattern is to express "exactly one of these widgets is active" with a single integer subject and one `ref_value` per option. Combining `subject_set_int_event` (writes the subject on click) with `bind_state_if_eq` (reads it to drive the `checked` state) produces a runtime-driven radio group with no application code. | ||
|
|
||
| ```xml | ||
| <!-- globals.xml --> | ||
| <subjects> | ||
| <int name="subject_lamp" value="0"/> | ||
| </subjects> | ||
| ``` | ||
|
|
||
| ```xml | ||
| <!-- lamp_cell.xml — one cell instantiated per option --> | ||
| <component> | ||
| <api> | ||
| <prop name="label" type="string" default="Lamp"/> | ||
| <prop name="ref_value" type="int" default="0"/> | ||
| </api> | ||
|
|
||
| <view extends="lv_obj" width="content" height="content" flex_flow="column"> | ||
| <lv_label text="$label"/> | ||
|
|
||
| <lv_button style_bg_color-checked="0xed7d31"> | ||
| <lv_image src="img_lightbulb"/> | ||
|
|
||
| <!-- Read: this button is checked iff subject_lamp == ref_value --> | ||
| <bind_state_if_eq subject="subject_lamp" state="checked" ref_value="$ref_value"/> | ||
|
|
||
| <!-- Write: clicking this button stores ref_value in subject_lamp --> | ||
| <subject_set_int_event subject="subject_lamp" trigger="clicked" value="$ref_value"/> | ||
| </lv_button> | ||
| </view> | ||
| </component> | ||
| ``` | ||
|
|
||
| ```xml | ||
| <!-- screen — each cell carries a unique ref_value --> | ||
| <lamp_cell label="Lamp 1" ref_value="0"/> | ||
| <lamp_cell label="Lamp 2" ref_value="1"/> | ||
| <lamp_cell label="Lamp 3" ref_value="2"/> | ||
| ``` | ||
|
|
||
| When the user taps a cell, `subject_lamp` is written to that cell's `ref_value`; every other cell's `bind_state_if_eq` re-evaluates and drops out of the `checked` state automatically. The same subject can also be set from C (`lv_subject_set_int(&subject_lamp, …)`) to drive the selection from application code. | ||
|
|
||
| ## Subject Related Events | ||
|
|
||
| Besides binding properties to subjects, it's also possible to add | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| --- | ||
| title: Project File | ||
| description: Configure your LVGL Pro project with project.xml — set the LVGL version, exported code name, and the display targets used to preview screens. | ||
| --- | ||
|
|
||
| `project.xml` is the top-level configuration file of an LVGL Pro project. It is read by the Editor, by the CLI, and by the runtime XML loader to learn the target LVGL version, the exported code's name, and the display configurations used to render screens in the preview. | ||
|
|
||
| `project.xml` lives next to `globals.xml` at the root of the project folder. | ||
|
|
||
| ## Recommended Project Layout | ||
|
|
||
| LVGL Pro doesn't enforce a folder structure, but the Editor, the tutorials, and the example projects all follow the same convention. Sticking to it keeps `src_path` references short and makes generated code predictable. | ||
|
|
||
| ``` | ||
| my_project/ | ||
| ├── project.xml ← target/display configuration (this file) | ||
| ├── globals.xml ← shared fonts, images, subjects, consts, styles | ||
| ├── translations.xml ← optional, multi-language strings | ||
| ├── fonts/ ← .ttf / .bin source files referenced by globals.xml | ||
| ├── images/ ← .png assets referenced by globals.xml | ||
| ├── widgets/ ← custom <widget> XMLs (one file per widget) | ||
| ├── components/ ← reusable <component> XMLs (one file per component) | ||
| └── screens/ ← <screen> XMLs (one file per screen) | ||
| ``` | ||
|
|
||
| The three XML files (`project.xml`, `globals.xml`, `translations.xml`) sit at the project root; the five sub-folders hold everything else. Any of the sub-folders can be omitted if the project doesn't use that category. | ||
|
|
||
| ## Minimal Example | ||
|
|
||
| The simplest valid project file just declares the LVGL version: | ||
|
|
||
| ```xml | ||
| <project lvgl_version="9.5.0"> | ||
| </project> | ||
| ``` | ||
|
|
||
| This is enough for the Editor to load the project, but no preview targets are defined — screens fall back to a default preview size. | ||
|
|
||
| ## Defining Display Targets | ||
|
|
||
| To preview Screens at the resolution(s) of the real hardware, declare one or more `<target>` elements inside `<targets>`. Each target contains a `<display>` describing the screen size. | ||
|
|
||
| ```xml | ||
| <project lvgl_version="9.5.0"> | ||
| <targets> | ||
| <target name="dashboard_large"> | ||
| <display width="800" height="480"/> | ||
| </target> | ||
| <target name="controller_small"> | ||
| <display width="480" height="320"/> | ||
| </target> | ||
| </targets> | ||
| </project> | ||
| ``` | ||
|
|
||
| When a Screen is open in the Editor, the Preview panel shows one entry per `<target>`. This is also how the Editor knows how to size a Screen's `<view>` when `width="100%"` or `height="100%"` is used at the screen root. | ||
|
|
||
| All Screens see all targets — there is no per-screen targeting. | ||
|
|
||
| ## Relation to Other Files | ||
|
|
||
| - **`globals.xml`** — Defines project-wide fonts, images, subjects, constants, and shared styles. See [Introduction](./introduction#shared-resources-with-globalsxml). | ||
| - **Screens** — Use the targets declared here to choose a preview resolution. See [Screens](./screens#preview). | ||
| - **Code export** — The `name` attribute controls the exported project name and init function. See [Using Exported C Code](../integration/using-exported-c-code). |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The binding tag is not closed, making this XML example invalid.
Prompt for AI agents