Label
Label
Module label
The simplest widget: text that never changes on its own.
import ui.label
| Module | label |
| Source | label/label.zirr |
| Imports | flow — Widget, NoCmd, Step; flow.node — Text |
A label holds a string and renders it. Messages are ignored, so its update always returns the model it was given together with NoCmd. It is the smallest complete example of the Widget attribute.
Contents
Data
Model
`label/label.zirr:11`
@Widget(update, view)
data Model {
value: String
}
The label state. It adopts Widget through update and view.
Fields
| Field | Type | Description |
|---|---|---|
value |
String |
The text to display. |
Functions
new
`label/label.zirr:6`
fn new(text: String) -> Label
Creates a label showing text.
Parameters
| Parameter | Type | Description |
|---|---|---|
text |
String |
The text to display. |
Returns
Label — as declared. The body returns a Model.
Declared result type
Label is not declared in this module; the only data type here is Model.
update
`label/label.zirr:15`
fn update(m: Model, msg: Any) -> Step
Handles a message. A label has no state to change, so every message yields the same model and NoCmd.
Parameters
| Parameter | Type | Description |
|---|---|---|
m |
Model |
The current label. |
msg |
Any |
The incoming message. Ignored. |
Returns
Step — Step(m, NoCmd()).
view
`label/label.zirr:19`
fn view(m: Model, dispatch: fn(Any)) -> flow.View
Renders the label as a single Text node.
Parameters
| Parameter | Type | Description |
|---|---|---|
m |
Model |
The label to render. |
dispatch |
fn(Any) |
Message sink. Unused, since a label emits nothing. |
Returns
flow.View — a Text node holding m.value.
See also
- Flow — the loop this widget plugs into.
- Text Input — a widget that does react to messages.