Controls

Buttons, text fields, checkboxes and selects: controlled widgets with stable ids.

Pass the current value every frame. Callbacks write back to the app struct. Give every interactive widget a stable unique id (hover/caret/scroll are stored under that key).

ui.TextField("url", app.url).
    Placeholder("https://…").
    IconStart(icons.Search).
    OnChange(func(s string) { app.url = s }).
    OnSubmit(app.fetch).
    Grow(1)

ui.Button("send", ui.Text("Send")).Primary().Hint("⌘↵").OnClick(app.fetch)
ui.Checkbox("notify", "Notify").Check(app.notify).OnToggle(func(v bool) { app.notify = v })
ui.Radio("ra", "A").Check(app.mode == 0).OnClick(func() { app.mode = 0 })
ui.Select("lang", opts).Width(200).Selected(i).OnChange(func(v string) { app.lang = v })

A text field can also mark up its own text and finish it for the user. .Highlight(fn) colors byte ranges of the value — template placeholders, matches, tokens — and .Suggest(fn) opens a completion popup under the field, driven by ↑ ↓ Enter/Tab and Escape:

ui.TextField("url", app.url).
    Highlight(func(v string) []ui.TextSpan { return app.vars.Spans(v) }).
    Suggest(func(v string, caret int) ([]ui.Suggestion, int, int) {
        // Candidates, plus the byte range they replace.
        return app.vars.Complete(v, caret)
    })

.HoverInfo(fn) adds the third piece: a card explaining whatever the pointer rests on, returning a HoverCard{Title, Body, Start, End} whose range the card is anchored under.

Table offers all three per cell through CellHighlight, CellSuggest, and CellHoverInfo. A masked (password) value is never highlighted, completed, or explained, so none of the hooks can leak it.

Button variants: default Secondary; .Primary(), .Subtle(), and .Ghost(). Ghost is text-like (no padding or chrome) for footers and status bars; chain .HoverFill() for a hover background. Supports .IconStart() and .Tooltip(). Icon-only: ui.IconButton(id, icons.Settings).

Typography: Text, Title, Subtitle, Caption, Strong, Muted. Color inherits from the parent (for example a button’s label uses the button’s text token) unless you override with .Style(ui.Spec{}.TextColor(ui.TokenForegroundMuted)).

Edit this page on GitHub
esc