input

package
v1.0.31-alpha.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 28 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AutofillKind

type AutofillKind int

AutofillKind is what a field holds, for password managers and the keyboard's AutoFill.

const (
	AutofillNone AutofillKind = iota
	AutofillUsername
	AutofillPassword
	// AutofillNewPassword is a password being chosen: managers offer to
	// make a strong one and save it.
	AutofillNewPassword
	AutofillEmail
	// AutofillOneTimeCode is a code sent by text message or email: the
	// keyboard offers it as it arrives.
	AutofillOneTimeCode
	AutofillName
	AutofillPhone
	AutofillAddress
	AutofillPostalCode
)

type Input

type Input struct {
	// Contextual gives it a context menu (Context).
	elements.Contextual
	// contains filtered or unexported fields
}

Input is a stateful text field, single-line by default. Create it once with New and lay it out every frame.

func New

func New(placeholder string, st ...styles.Styles) *Input

New returns an Input with the given placeholder. The styles argument is optional.

func (*Input) Autocorrect

func (i *Input) Autocorrect(on bool) *Input

Autocorrect(false) has the on-screen keyboard take text as typed: no corrections or word suggestions, no automatic capitals, and no smart quotes or dashes - for a terminal, code, commands or user names. It keeps the Keyboard's layout. Autocorrect(true), the default, leaves them to the keyboard. It returns i for chaining.

Builds by the giode CLI (Gio patch revision 18 on) honor it on Android and iOS; other Android builds get the plain text keyboard. The web turns correction, capitals and spell checking off; desktops ignore it.

func (*Input) Autofill

func (i *Input) Autofill(kind AutofillKind) *Input

Autofill says what the field holds, so password managers (iCloud Keychain, Google Password Manager, 1Password, Bitwarden) and the keyboard can fill it. A Password field is AutofillPassword unless set otherwise. It works on iOS and Android in builds made with the Giode CLI. It returns i for chaining.

func (*Input) Blur

func (i *Input) Blur()

Blur takes keyboard focus away from the field, if it has it, in the next frame, and closes the on-screen keyboard: nothing has focus then, so the app's shortcuts get every key.

func (*Input) CanRedo

func (i *Input) CanRedo() bool

func (*Input) CanUndo

func (i *Input) CanUndo() bool

CanUndo and CanRedo report whether there's an edit to undo or redo.

func (*Input) Caret

func (i *Input) Caret() int

Caret returns the caret's position: the number of runes before it. With a selection, it's the end the caret is at (see Selection).

func (*Input) CaretRect

func (i *Input) CaretRect() image.Rectangle

CaretRect is where the caret was last drawn, in the window: for a popover that follows it, such as mention suggestions.

func (*Input) ChangeText

func (i *Input) ChangeText(s string)

ChangeText replaces the content and invokes OnChange, as typing would. Like SetText, it leaves the caret at the end.

func (*Input) Focus

func (i *Input) Focus()

Focus gives the field keyboard focus in the next frame, which it asks for: call it from anywhere on the UI goroutine, also right after showing the field for the first time.

func (*Input) Focused

func (i *Input) Focused() bool

Focused reports whether the field had keyboard focus in the last frame.

func (*Input) InsertText

func (i *Input) InsertText(s string)

InsertText replaces the selection (or inserts at the caret) with s and invokes OnChange, as typing would.

func (*Input) Invalid

func (i *Input) Invalid(message string) *Input

Invalid marks the field's value as wrong, with the message why ("Enter an email address"): its border shows in the danger color, and screen readers read the message with the field. "" clears it. It returns i for chaining.

func (*Input) KeepsKeyboard

func (i *Input) KeepsKeyboard(p image.Point) bool

KeepsKeyboard reports whether a tap at p, in window coordinates, lands on the field, or anywhere while its edit menu shows (its menu and handles sit outside it; a tap elsewhere closes the menu first).

func (*Input) Keyboard

func (i *Input) Keyboard(k Keyboard) *Input

Keyboard selects the on-screen keyboard shown while the field is focused on a touch device; Password overrides it with the password keyboard. It returns i for chaining.

func (*Input) Label

func (i *Input) Label(label string) *Input

Label sets the accessible name reported to automation (the semantic tree, the MCP server); the placeholder is used when unset. It returns i for chaining.

func (*Input) Layout

func (i *Input) Layout(gtx layout.Context) layout.Dimensions

Layout lays out and updates the field.

func (*Input) Lines

func (i *Input) Lines(min, max int) *Input

Lines makes a multiline field grow with its content from min to max lines, then scroll; 0 for max means no limit. It also turns Multiline on. It returns i for chaining.

func (*Input) MaxLength

func (i *Input) MaxLength(n int) *Input

MaxLength limits the content to n runes; 0 removes the limit. It returns i for chaining.

func (*Input) Misspellings

func (i *Input) Misspellings() []spellcheck.Misspelling

Misspellings are the misspelled words found in the current text.

func (*Input) Multiline

func (i *Input) Multiline(on bool) *Input

Multiline lets the field hold several lines; Enter inserts a newline instead of submitting (see SubmitOn). It returns i for chaining.

func (*Input) OnBlur

func (i *Input) OnBlur(fn func()) *Input

OnBlur sets a handler called when the field loses keyboard focus. It returns i for chaining.

func (*Input) OnChange

func (i *Input) OnChange(fn func(text string)) *Input

OnChange sets the handler invoked after every edit. It returns i for chaining.

func (*Input) OnFocus

func (i *Input) OnFocus(fn func()) *Input

OnFocus sets a handler called when the field gains keyboard focus. It returns i for chaining.

func (*Input) OnKeys

func (i *Input) OnKeys(fn func(e key.Event), names ...key.Name) *Input

OnKeys has fn take presses of the named keys while the field has focus, before the editor sees them, with any of Shift, Ctrl, Alt and Cmd held: a number field steps its value with Up and Down this way. It returns i for chaining.

func (*Input) OnPaste

func (i *Input) OnPaste(fn func(pasteText func())) *Input

OnPaste sets fn to run in place of pasting when the user pastes into the field: Ctrl+V (Cmd+V on Apple platforms) or Paste in the editing menu. fn runs on the UI goroutine; it may call pasteText to paste the clipboard's text as the field would have, then or later from the UI goroutine (through App.Post, from a goroutine). A chat composer attaches a copied image this way and pastes text otherwise:

in.OnPaste(func(pasteText func()) {
	go func() {
		img, err := app.ReadClipboardImage(ctx)
		app.Post(func() {
			if err == nil && img != nil {
				attach(img)
			} else {
				pasteText()
			}
		})
	}()
})

A read-only field doesn't paste and doesn't call fn. It returns i for chaining.

func (*Input) Password

func (i *Input) Password(on bool) *Input

Password masks the content with bullets and asks touch devices for the password keyboard. It returns i for chaining.

func (*Input) Placeholder

func (i *Input) Placeholder(s string) *Input

Placeholder replaces the text shown while the field is empty. It returns i for chaining.

func (*Input) ReadOnly

func (i *Input) ReadOnly(on bool) *Input

ReadOnly makes the content selectable but not editable. It returns i for chaining.

func (*Input) Redo

func (i *Input) Redo()

Redo redoes the last undone edit.

func (*Input) Required

func (i *Input) Required(on bool) *Input

Required marks the field as one that must be filled: screen readers say so. It returns i for chaining.

func (*Input) SelectAll

func (i *Input) SelectAll()

SelectAll selects the whole content.

func (*Input) Selection

func (i *Input) Selection() (start, end int)

Selection returns the selected runes as [start, end), start <= end; start == end is the caret alone.

func (*Input) SetCaret

func (i *Input) SetCaret(pos int)

SetCaret moves the caret to pos runes from the start, clamped to the content, and clears the selection.

func (*Input) SetSelection

func (i *Input) SetSelection(start, end int)

SetSelection selects the runes [start, end), clamped to the content, with the caret at end; start == end places the caret alone. To replace the word at the caret, select it and call InsertText.

func (*Input) SetText

func (i *Input) SetText(s string)

SetText replaces the content without invoking OnChange, and leaves the caret at the end, as typing it would: a recalled history line or a restored draft continues where it ends. SetCaret places it elsewhere.

func (*Input) SpellCheck

func (i *Input) SpellCheck(on bool) *Input

SpellCheck underlines misspelled words in red, with suggestions in the edit menu (right-click, or a long press on a touch screen). It uses the platform's spell checker (see package spellcheck) in the user's language, or the one SpellLanguage sets. It returns i for chaining.

func (*Input) SpellLanguage

func (i *Input) SpellLanguage(tag string) *Input

SpellLanguage sets the language to check, a BCP 47 tag ("en-US", "fa"); the user's by default. It returns i for chaining.

func (*Input) Styles

func (i *Input) Styles(st styles.Styles) *Input

Styles replaces the field's styles, from the next frame, keeping its text and focus. It returns i for chaining.

func (*Input) Submit

func (i *Input) Submit(fn func(text string)) *Input

Submit sets the handler invoked when Enter is pressed in a single-line field. It returns i for chaining.

func (*Input) SubmitOn

func (i *Input) SubmitOn(m SubmitMode) *Input

SubmitOn selects which key presses call the Submit handler; see SubmitMode. It returns i for chaining.

func (*Input) SubmitText

func (i *Input) SubmitText()

SubmitText invokes the Submit handler with the current content, as pressing Enter would.

func (*Input) Text

func (i *Input) Text() string

Text returns the current content.

func (*Input) Undo

func (i *Input) Undo()

Undo undoes the last edit: a word typed, a paste, a cut.

type Keyboard

type Keyboard uint8

Keyboard selects the on-screen keyboard a field asks for on touch devices. Desktop platforms ignore it.

const (
	// KeyboardText is the plain text keyboard, the default.
	KeyboardText Keyboard = iota
	// KeyboardNumeric shows digits, "." and ",".
	KeyboardNumeric
	// KeyboardEmail adds shortcuts such as "@" and ".com".
	KeyboardEmail
	// KeyboardURL adds shortcuts such as "/" and ".com".
	KeyboardURL
	// KeyboardPhone shows digits, "#" and "*".
	KeyboardPhone
)

type KeyboardInput

type KeyboardInput struct {
	// contains filtered or unexported fields
}

KeyboardInput takes the keyboard for content drawn by the app itself - a terminal, a game, a canvas, a custom editor: it gets focus, the text typed while it has it and the other keys, and asks for the on-screen keyboard on phones, while content draws what that changes. Create it once with NewKeyboardInput and lay it out every frame.

Typed text arrives at OnText as the platform composes it: in the keyboard layout in effect, with Shift and Caps Lock applied, dead keys and compose sequences combined ("´" then "e" gives "é"), and input-method text (Chinese, Japanese, Korean; a phone keyboard's swipes and suggestions) once it's committed. The text being composed meanwhile is Composition; Caret says where the app draws its caret, so the input method's candidate window opens there.

The other keys - arrows, Enter, Tab, Backspace, Escape, function keys, and any key with Ctrl, Alt or Cmd held - go to OnKey. Enter, Space and Tab do nothing of their own here: Enter and Tab go to OnKey (Tab doesn't move the focus while it has it), Space is typed text.

func NewKeyboardInput

func NewKeyboardInput(content elements.Element) *KeyboardInput

NewKeyboardInput returns a KeyboardInput showing content.

func (*KeyboardInput) Autocorrect

func (k *KeyboardInput) Autocorrect(on bool) *KeyboardInput

Autocorrect lets a phone keyboard correct, capitalize and suggest words; off by default, as a terminal or a game wants the keys as typed. Corrections reach OnKey as Backspace presses and OnText as the new text. It returns k for chaining.

func (*KeyboardInput) Blur

func (k *KeyboardInput) Blur()

Blur takes keyboard focus away from it, if it has it, in the next frame, and closes the on-screen keyboard.

func (*KeyboardInput) Caret

Caret tells the input method where the app draws its caret: r in pixels, relative to the element's top-left corner. The candidate window of a Chinese or Japanese input method opens at it, and a phone keyboard keeps it in view. Call it as the caret moves, also while laying out content. It returns k for chaining.

func (*KeyboardInput) Composition

func (k *KeyboardInput) Composition() string

Composition returns the text an input method is composing, not yet committed to OnText, for the app to draw at its caret; "" when none.

func (*KeyboardInput) Content

func (k *KeyboardInput) Content(content elements.Element) *KeyboardInput

Content replaces what it shows. It returns k for chaining.

func (*KeyboardInput) Focus

func (k *KeyboardInput) Focus()

Focus gives it keyboard focus in the next frame. Call it on the UI goroutine, also right after showing it for the first time.

func (*KeyboardInput) Focused

func (k *KeyboardInput) Focused() bool

Focused reports whether it had keyboard focus in the last frame.

func (*KeyboardInput) KeepsKeyboard

func (k *KeyboardInput) KeepsKeyboard(p image.Point) bool

KeepsKeyboard reports whether a tap at p, in window coordinates, lands on it: a tap elsewhere closes the on-screen keyboard.

func (*KeyboardInput) Keyboard

func (k *KeyboardInput) Keyboard(kb Keyboard) *KeyboardInput

Keyboard has it ask for an on-screen keyboard of kind kb on phones and tablets while it has focus; without it, none shows. Desktop platforms ignore it. It returns k for chaining.

func (*KeyboardInput) Label

func (k *KeyboardInput) Label(label string) *KeyboardInput

Label sets the accessible name reported to screen readers and automation. It returns k for chaining.

func (*KeyboardInput) Layout

func (k *KeyboardInput) Layout(gtx layout.Context) layout.Dimensions

Layout lays out content and handles the keyboard.

func (*KeyboardInput) OnBlur

func (k *KeyboardInput) OnBlur(fn func()) *KeyboardInput

OnBlur has fn run when it loses keyboard focus. It returns k for chaining.

func (*KeyboardInput) OnFocus

func (k *KeyboardInput) OnFocus(fn func()) *KeyboardInput

OnFocus has fn run when it gains keyboard focus. It returns k for chaining.

func (*KeyboardInput) OnKey

func (k *KeyboardInput) OnKey(fn func(e key.Event) bool, names ...key.Name) *KeyboardInput

OnKey has fn take the keys that don't type text, pressed and released while it has focus (check e.State): arrows, Enter, Tab and Shift+Tab, Backspace, Delete, Escape, Home, End, Page Up and Down, function keys, the modifier keys themselves, and any key with Ctrl, Alt, Cmd or Super held (Ctrl+C included); Android's Back goes on to HandleBack. With names it takes only those keys, with any modifiers held, and the rest go on to the app's OnKey shortcuts: a game names "W", "A", "S" and "D" (as key.Event names them: capitals, key.NameSpace) to get their presses and releases, whose text also arrives at OnText. fn returns whether it used the key; one it didn't use goes on to the app's OnKey shortcuts too. It returns k for chaining.

func (*KeyboardInput) OnText

func (k *KeyboardInput) OnText(fn func(text string)) *KeyboardInput

OnText has fn take the text typed while it has focus, as committed: usually a character at a time, a word or more from an input method or a paste through the keyboard. A new line in it ("\n", sent by some phone keyboards) goes to OnKey as an Enter press instead, and a correction of text fn already got (a phone keyboard's autocorrect) arrives as Backspace presses at OnKey and the corrected text here. It returns k for chaining.

type SubmitMode

type SubmitMode int

SubmitMode selects which key presses submit a field.

const (
	// SubmitDefault submits on Enter in a single-line field; a
	// multiline field inserts a newline and never submits.
	SubmitDefault SubmitMode = iota
	// SubmitEnter submits on Enter, also in a multiline field.
	SubmitEnter
	// SubmitEnterUnlessShift submits on Enter and inserts a newline on
	// Shift+Enter, as chat composers do. On a touch screen the
	// on-screen keyboard's Enter key inserts a newline instead, since
	// phone apps send with a button.
	SubmitEnterUnlessShift
	// SubmitNever never submits; Enter inserts a newline in a
	// multiline field.
	SubmitNever
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL