Skip to main content

EditText

widget.EditText is a focusable text input. It comes in two modes:

  • Single-linewidget.NewEditText() — horizontal scroll when content exceeds width
  • Multi-linewidget.NewMultiLineEditText() — vertical scroll; Enter inserts a line break

Basic usage

// Single-line
input := widget.NewEditText().
WithPlaceholder("Enter a value…")

// Multi-line
body := widget.NewMultiLineEditText().
WithPlaceholder("Write here…")

Builder options

MethodDescription
WithStyle(s latte.Style)Override the display style (border, colours, padding)
WithID(id string)Set a stable identifier for Canvas.GetValue(id)
WithPlaceholder(text string)Muted text shown when the field is empty
WithHint(text string)Persistent muted label rendered above the content area
WithMaxLength(n int)Maximum character count (single-line only; 0 = unlimited)
WithOnChange(fn func(string))Callback fired on every keystroke
WithOnSave(fn func(string))Callback fired when the user presses ^S
WithOnCancel(fn func())Callback fired when the user presses ^G

Hint label

WithHint renders a persistent muted label directly above the content area. Unlike a placeholder, it is always visible and serves as an inline field label. Use it instead of a separate Text widget.

input := widget.NewEditText().
WithHint("Email address")

Borderless fields

Use WithStyle with latte.BorderExplicitNone to suppress the border entirely. Combined with WithHint, this produces a clean, label-only field well-suited for editor panels:

titleInput := widget.NewEditText().
WithStyle(latte.Style{Border: latte.BorderExplicitNone}).
WithHint("Title").
WithPlaceholder("Untitled…")

bodyInput := widget.NewMultiLineEditText().
WithStyle(latte.Style{Border: latte.BorderExplicitNone}).
WithHint("Body").
WithPlaceholder("Write here…")

Callbacks

input.WithOnChange(func(text string) {
// fired on every keystroke
})

input.WithOnSave(func(text string) {
// fired when the user presses ^S (or Enter on a single-line field)
})

input.WithOnCancel(func() {
// fired when the user presses ^G
})

When WithOnSave is registered, ^S Save is advertised in the StatusBar automatically.

Reading and setting text

input.SetText("initial value")
current := input.GetText()

EditText also implements oat.ValueGetter: Canvas.GetValue(id) returns the current text as a string.

Max length

input := widget.NewEditText().WithMaxLength(64)

Built-in key bindings

KeyAction
^SSave — fires onSave callback
^GCancel — fires onCancel callback
^KKill to end of line
^UKill from start of line to cursor
^A / HomeMove cursor to start of line
^E / EndMove cursor to end of line
/ Move cursor left / right
/ Move cursor up / down (multi-line only)
EnterInsert line break (multi-line) or fire onSave (single-line, if set)
BackspaceDelete character before cursor
DeleteDelete character after cursor