Skip to content

Controls

ButtonVariant :: enum {...}
button :: proc{button_label, button_icon}
button_icon :: proc(icon: Icon, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default) -> bool
button_label :: proc(label: string, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default, icon := Icon{}) -> bool
checkbox :: 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 :: 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

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_label proc(label: string, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default, icon := Icon{}) -> bool
  • button_icon proc(icon: Icon, variant := ButtonVariant.Primary, disabled := false, fill := false, tone := Tone.Default) -> bool

Source: kiln/controls.odin:23

button_icon :: proc(
icon: Icon,
variant := ButtonVariant.Primary,
disabled := false,
fill := false,
tone := Tone.Default,
) -> bool
ArgumentTypeDefault
iconIconrequired
variantButtonVariantButtonVariant.Primary
disabledboolfalse
fillboolfalse
toneToneTone.Default
ReturnsType
#0bool

Source: kiln/controls.odin:39

button_label :: proc(
label: string,
variant := ButtonVariant.Primary,
disabled := false,
fill := false,
tone := Tone.Default,
icon := Icon{},
) -> bool
ArgumentTypeDefault
labelstringrequired
variantButtonVariantButtonVariant.Primary
disabledboolfalse
fillboolfalse
toneToneTone.Default
iconIconIcon{}
ReturnsType
#0bool

Source: kiln/controls.odin:28

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})}
ArgumentTypeDefault
checkedboolrequired
labelstring""
disabledboolfalse
ReturnsType
valuebool
changedbool

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})}
}
ArgumentTypeDefault
selected$Trequired
valueTrequired
labelstring""
disabledboolfalse
ReturnsType
new_valueT
changedbool

Source: kiln/controls.odin:146

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})}
ArgumentTypeDefault
value$Trequired
loTrequired
hiTrequired
disabledboolfalse
keystring""
ReturnsType
new_valueT
changedbool

Source: kiln/controls.odin:241

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.

ArgumentTypeDefault
valuestringrequired
placeholderstring""
disabledboolfalse
passwordboolfalse
keystring""
ReturnsType
textstring
changedbool

Source: kiln/text_field.odin:47

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.

ArgumentTypeDefault
onboolrequired
labelstring""
disabledboolfalse
ReturnsType
valuebool
changedbool

Source: kiln/controls.odin:129