UI Primitives
The View is the window: the root of every view, which is there without being written. It has the box properties and the container properties, so a view can be given a background, a padding or a direction by writing it as the outermost element:
fn view(state: State): Node => #view(fill: white, padding: 16px, direction: "column") { #text("Hello") }A #view has to be the outermost element, and there is only one. Without one, the view still has its View, with
nothing to paint.
Fragments
Section titled “Fragments”Fragments allow for grouping of UI Primitives but cannot effect the layout and do not have any properties>.
Box Properties
Section titled “Box Properties”Boxes are the absolute most basic UI primitive
Properties
| Name | Type | Description |
|---|---|---|
| width | Px | Pct | Fr | auto | Width of the box ( |
| height | Px | Pct | Fr | auto | Height of the box ( |
| min-width | Px | Pct | Minimum width constraint ( |
| min-height | Px | Pct | Minimum height constraint ( |
| max-width | Px | Pct | Inner spacing between the box edge and its content ( |
| max-height | Px | Pct | Inner spacing between the box edge and its content ( |
| max-height | Px | Pct | Maximum height constraint ( |
| padding | Px | Pct | Inner spacing between the box edge and its content ( |
| margin | Px | Pct | Outer spacing around the box. |
| grow | Number | Flex grow factor when extra space is available ( |
| shrink | Number | Flex shrink factor when space is constrained ( |
| basis | Px | Pct | Fr | auto | Initial main-axis size before growing or shrinking ( |
| align-self | Align | Overrides the parent’s |
| fill | Color | Background fill color of the box. |
| border-color | Color | Color of the box border. A color with no |
| border-width | Px | Thickness of the border, in |
| radius | Px | Corner rounding radius, in |
| tooltip | String | A tooltip: text that is shown next to the pointer once it has been over the box for a moment (half a second, unless
the host says otherwise), over everything else. What is inside the box has the box’s tooltip unless it has its own, and
where the box is cut off, by a |
| opacity | Number | Opacity from |
| on-click | Message | Message dispatched when the box is clicked. |
Container Properties
Section titled “Container Properties”Containers are #boxes that contain children
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#box | ||
| gap | Px | Pct | Spacing between adjacent children ( |
| direction | Direction | Main layout axis: |
| align | Align | Cross-axis alignment of children: |
| justify | Justify | Main-axis distribution: |
| wrap | Bool | Whether children wrap onto multiple lines when they overflow the main axis. |
A general-purpose layout container for grouping and arranging child elements.
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#container | ||
Example
#block(direction: "column", gap: 12px, padding: 16px, fill: #1e1e1e, radius: 8px) { #text(value: "Settings", size: 20px, color: white) #text(value: "Manage your preferences.", size: 14px, color: #a0a0a0)}A #box for displaying text
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#box | ||
| value | String | What to show. |
| size | Px | The font size, in |
| font-family | String | The font: a name, or a comma-separated list in order of preference. |
| color | Color | The color of the text. Opaque black if it isn’t given. |
| text-align | String | Horizontal text alignment: |
| Positional Arguments | ||
| value | String | The text to render |
Example
#text(size: 24px, font-family: "Inter, sans-serif", color: white, "Hello World")A single-line #box for user input.
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#box | ||
| size | Px | The font size, in |
| font-family | String | The font: a name, or a comma-separated list in order of preference. |
| color | Color | The color of the input text. |
| text-align | String | Horizontal text alignment: |
| on-input | Message | Message dispatched when the user edits the text. |
| Positional Properties | ||
| value | String | The current text value inside the input. |
Example
#input(size: 16px, padding: 8px, border-color: #444444, border-width: 1px, on-input: UpdateQuery, "Search....")A #box for rendering an image
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#box | ||
| fit | String | How the image scales inside its box: |
| Positional Properties | ||
| source | String | The source uri for the image |
Example
#image(width: 120px, height: 120px, fit: "contain" source)Button
Section titled “Button”A #box that response to clicks
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#container | ||
Example
#button(padding: 10px, fill: blue, radius: 6px, on-click: Submit) { #text(value: "Save", size: 14px, color: white)}Scroll & List
Section titled “Scroll & List”A #container for displaying more children than fit. What is in it is laid out at its own size, and
the box shows the part of it that has been scrolled to, clipping the rest. Its padding, gap, direction, align
and justify are for what is inside it, and its width, height, fill, border-* and radius for the box.
A #list is a #scroll that goes down: its direction is "column" unless it says otherwise. Every row of a list is
laid out and drawn, whether it is in view or not.
The host scrolls it (Session::Scroll, or kura_rt_event_scroll): the wheel moves the topmost container under the
pointer that has room to go that way, and when it is as far as it goes the one it is in gets the wheel. How far a
container is scrolled is kept from one frame to the next, and is kept in range if its content shrinks.
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#container | ||
| on-scroll | Message | Message dispatched when the scroll offset changes. It doesn’t say where the offset is yet. |
Example
#scroll(height: 300px, direction: "column", gap: 8px, on-scroll: Scrolled) { #text(value: "Item 1", size: 14px) #text(value: "Item 2", size: 14px)}Progress
Section titled “Progress”A #box visual indicator showing completion progress.
Properties
| Name | Type | Description |
|---|---|---|
| Inherits from:#box | ||
| Positional Properties | ||
| value | Number | Completion ratio between |
Example
#progress(width: 200px, height: 8px, fill: #333333, radius: 4px 0.75)