Controls
At a glance
Section titled “At a glance”ButtonVariant :: enum {...}button :: proc{button_label, button_icon}button_icon :: proc(icon: Icon, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default) -> boolbutton_label :: proc(label: string, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default, icon := Icon{}) -> boolcheckbox :: proc(checked: bool, label := "", disabled := false) -> (value: bool, changed: bool)radio :: proc(selected: $T, value: T, label := "", disabled := false) -> (new_value: T, changed: bool) where intrinsics.type_is_enum(T) || intrinsics.type_is_integer(T)slider :: proc(value: $T, lo, hi: T, disabled := false, key := "") -> (new_value: T, changed: bool) where intrinsics.type_is_integer(T) || intrinsics.type_is_float(T)text_field :: proc(value: string, placeholder := "", disabled := false, password := false, key := "") -> (text: string, changed: bool)toggle :: proc(on: bool, label := "", disabled := false) -> (value: bool, changed: bool)ButtonVariant
Section titled “ButtonVariant”ButtonVariant :: enum { Primary, // filled with the primary color Secondary, // raised surface with a border Ghost, // transparent until hovered Danger, // filled with the danger color}Values: .Primary, .Secondary, .Ghost, .Danger
Source: kiln/controls.odin:11
Procedure groups
Section titled “Procedure groups”button
Section titled “button”button :: proc{button_label, button_icon}A button; returns true in the frame it was clicked. icon goes before the label. An icon alone
(button(kiln.ICON_MENU, .Ghost)) or a single-character label (”✕”) gives a square button.
fill makes it as wide as its container; inside actions on compact screens buttons fill
automatically. tone colors the label of ghost and secondary buttons, e.g. a red ghost
“Entfernen”.
Calls one of these, depending on the argument types:
button_labelproc(label: string, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default, icon := Icon{}) -> boolbutton_iconproc(icon: Icon, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default) -> bool
Source: kiln/controls.odin:23
Procedures
Section titled “Procedures”button_icon
Section titled “button_icon”button_icon :: proc( icon: Icon, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default,) -> bool| Argument | Type | Default |
|---|---|---|
icon | Icon | required |
variant | ButtonVariant | ButtonVariant.Primary |
disabled | bool | false |
fill | bool | false |
tone | Tone | Tone.Default |
| Returns | Type |
|---|---|
| #0 | bool |
Source: kiln/controls.odin:39
button_label
Section titled “button_label”button_label :: proc( label: string, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default, icon := Icon{},) -> bool| Argument | Type | Default |
|---|---|---|
label | string | required |
variant | ButtonVariant | ButtonVariant.Primary |
disabled | bool | false |
fill | bool | false |
tone | Tone | Tone.Default |
icon | Icon | Icon{} |
| Returns | Type |
|---|---|
| #0 | bool |
Source: kiln/controls.odin:28
checkbox
Section titled “checkbox”checkbox :: proc(checked: bool, label := "", disabled := false) -> (value: bool, changed: bool)A checkbox with an optional label:
if v, ok := kiln.checkbox(m.notify, "Benachrichtigungen"); ok {append(out, Set_Notify{v})}| Argument | Type | Default |
|---|---|---|
checked | bool | required |
label | string | "" |
disabled | bool | false |
| Returns | Type |
|---|---|
value | bool |
changed | bool |
Source: kiln/controls.odin:116
radio :: proc( selected: $T, value: T, label := "", disabled := false,) -> (new_value: T, changed: bool) where intrinsics.type_is_enum(T) || intrinsics.type_is_integer(T)One option of a radio group: selects value when clicked. Works with enums and integers:
for s in Size { if v, ok := kiln.radio(m.size, s, SIZE_NAMES[s]); ok {append(out, Set_Size{v})}}| Argument | Type | Default |
|---|---|---|
selected | $T | required |
value | T | required |
label | string | "" |
disabled | bool | false |
| Returns | Type |
|---|---|
new_value | T |
changed | bool |
Source: kiln/controls.odin:146
slider
Section titled “slider”slider :: proc( value: $T, lo, hi: T, disabled := false, key := "",) -> (new_value: T, changed: bool) where intrinsics.type_is_integer(T) || intrinsics.type_is_float(T)A horizontal slider for integers and floats in [lo, hi]:
if v, ok := kiln.slider(m.volume, 0, 100); ok {append(out, Set_Volume{v})}| Argument | Type | Default |
|---|---|---|
value | $T | required |
lo | T | required |
hi | T | required |
disabled | bool | false |
key | string | "" |
| Returns | Type |
|---|---|
new_value | T |
changed | bool |
Source: kiln/controls.odin:241
text_field
Section titled “text_field”text_field :: proc( value: string, placeholder := "", disabled := false, password := false, key := "",) -> (text: string, changed: bool)A text field. Returns the edited text and whether it changed in this frame; ask
kiln.submitted() afterwards for Enter. The returned string lives until the end of the frame:
if t, ok := kiln.text_field(m.draft, "Neue Aufgabe..."); ok {append(out, Set_Draft{t})}if kiln.submitted() {append(out, Add{})}password masks the text and adds a button that reveals it; copying is disabled while masked.
The field is identified by its placeholder; give two fields with the same placeholder a
distinct key.
| Argument | Type | Default |
|---|---|---|
value | string | required |
placeholder | string | "" |
disabled | bool | false |
password | bool | false |
key | string | "" |
| Returns | Type |
|---|---|
text | string |
changed | bool |
Source: kiln/text_field.odin:47
toggle
Section titled “toggle”toggle :: proc(on: bool, label := "", disabled := false) -> (value: bool, changed: bool)An on/off switch with an optional label. Same as checkbox, for settings that apply at once.
| Argument | Type | Default |
|---|---|---|
on | bool | required |
label | string | "" |
disabled | bool | false |
| Returns | Type |
|---|---|
value | bool |
changed | bool |
Source: kiln/controls.odin:129