Documentation
¶
Index ¶
- type AutofillKind
- type Input
- func (i *Input) Autocorrect(on bool) *Input
- func (i *Input) Autofill(kind AutofillKind) *Input
- func (i *Input) Blur()
- func (i *Input) CanRedo() bool
- func (i *Input) CanUndo() bool
- func (i *Input) Caret() int
- func (i *Input) CaretRect() image.Rectangle
- func (i *Input) ChangeText(s string)
- func (i *Input) Focus()
- func (i *Input) Focused() bool
- func (i *Input) InsertText(s string)
- func (i *Input) Invalid(message string) *Input
- func (i *Input) KeepsKeyboard(p image.Point) bool
- func (i *Input) Keyboard(k Keyboard) *Input
- func (i *Input) Label(label string) *Input
- func (i *Input) Layout(gtx layout.Context) layout.Dimensions
- func (i *Input) Lines(min, max int) *Input
- func (i *Input) MaxLength(n int) *Input
- func (i *Input) Misspellings() []spellcheck.Misspelling
- func (i *Input) Multiline(on bool) *Input
- func (i *Input) OnBlur(fn func()) *Input
- func (i *Input) OnChange(fn func(text string)) *Input
- func (i *Input) OnFocus(fn func()) *Input
- func (i *Input) OnKeys(fn func(e key.Event), names ...key.Name) *Input
- func (i *Input) OnPaste(fn func(pasteText func())) *Input
- func (i *Input) Password(on bool) *Input
- func (i *Input) Placeholder(s string) *Input
- func (i *Input) ReadOnly(on bool) *Input
- func (i *Input) Redo()
- func (i *Input) Required(on bool) *Input
- func (i *Input) SelectAll()
- func (i *Input) Selection() (start, end int)
- func (i *Input) SetCaret(pos int)
- func (i *Input) SetSelection(start, end int)
- func (i *Input) SetText(s string)
- func (i *Input) SpellCheck(on bool) *Input
- func (i *Input) SpellLanguage(tag string) *Input
- func (i *Input) Styles(st styles.Styles) *Input
- func (i *Input) Submit(fn func(text string)) *Input
- func (i *Input) SubmitOn(m SubmitMode) *Input
- func (i *Input) SubmitText()
- func (i *Input) Text() string
- func (i *Input) Undo()
- type Keyboard
- type KeyboardInput
- func (k *KeyboardInput) Autocorrect(on bool) *KeyboardInput
- func (k *KeyboardInput) Blur()
- func (k *KeyboardInput) Caret(r image.Rectangle) *KeyboardInput
- func (k *KeyboardInput) Composition() string
- func (k *KeyboardInput) Content(content elements.Element) *KeyboardInput
- func (k *KeyboardInput) Focus()
- func (k *KeyboardInput) Focused() bool
- func (k *KeyboardInput) KeepsKeyboard(p image.Point) bool
- func (k *KeyboardInput) Keyboard(kb Keyboard) *KeyboardInput
- func (k *KeyboardInput) Label(label string) *KeyboardInput
- func (k *KeyboardInput) Layout(gtx layout.Context) layout.Dimensions
- func (k *KeyboardInput) OnBlur(fn func()) *KeyboardInput
- func (k *KeyboardInput) OnFocus(fn func()) *KeyboardInput
- func (k *KeyboardInput) OnKey(fn func(e key.Event) bool, names ...key.Name) *KeyboardInput
- func (k *KeyboardInput) OnText(fn func(text string)) *KeyboardInput
- type SubmitMode
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 (*Input) Autocorrect ¶
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) Caret ¶
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 ¶
CaretRect is where the caret was last drawn, in the window: for a popover that follows it, such as mention suggestions.
func (*Input) ChangeText ¶
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) InsertText ¶
InsertText replaces the selection (or inserts at the caret) with s and invokes OnChange, as typing would.
func (*Input) Invalid ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
Multiline lets the field hold several lines; Enter inserts a newline instead of submitting (see SubmitOn). It returns i for chaining.
func (*Input) OnBlur ¶
OnBlur sets a handler called when the field loses keyboard focus. It returns i for chaining.
func (*Input) OnChange ¶
OnChange sets the handler invoked after every edit. It returns i for chaining.
func (*Input) OnFocus ¶
OnFocus sets a handler called when the field gains keyboard focus. It returns i for chaining.
func (*Input) OnKeys ¶
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 ¶
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 ¶
Password masks the content with bullets and asks touch devices for the password keyboard. It returns i for chaining.
func (*Input) Placeholder ¶
Placeholder replaces the text shown while the field is empty. It returns i for chaining.
func (*Input) ReadOnly ¶
ReadOnly makes the content selectable but not editable. It returns i for chaining.
func (*Input) Required ¶
Required marks the field as one that must be filled: screen readers say so. It returns i for chaining.
func (*Input) Selection ¶
Selection returns the selected runes as [start, end), start <= end; start == end is the caret alone.
func (*Input) SetCaret ¶
SetCaret moves the caret to pos runes from the start, clamped to the content, and clears the selection.
func (*Input) SetSelection ¶
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 ¶
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 ¶
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 ¶
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 ¶
Styles replaces the field's styles, from the next frame, keeping its text and focus. It returns i for chaining.
func (*Input) Submit ¶
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.
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 ¶
func (k *KeyboardInput) Caret(r image.Rectangle) *KeyboardInput
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 )