The `.slint` File
You write user interfaces in the Slint language and saved in files with the .slint
extension.
Each .slint
file defines one or several components. These components declare
a tree of elements. Components form the basis of composition in Slint. Use them
to build your own re-usable set of UI controls. You can use each declared
component under its name as an element in another component.
Below is an example of components and elements:
Both MyButton
and MyApp
are components. Window
and Rectangle
are built-in elements
used by MyApp
. MyApp
also re-uses the MyButton
component as two separate elements.
Elements have properties, which you can assign values to. The example above assigns a string
constant “hello” to the first MyButton
’s text
property. You
can also assign entire expressions. Slint re-evaluates the expressions when any
of the properties they depend on change, which makes the user-interface reactive.
You can name elements using the :=
syntax:
:::{note}
Names have to be valid identifiers.
:::
Some elements are also accessible under pre-defined names:
root
refers to the outermost element of a component.self
refers to the current element.parent
refers to the parent element of the current element.
These names are reserved and you can’t re-define them.