类型 TextInput

API 文档由 Go 源码生成,内容为英文。

type TextInput struct {
	Bounds   ui.Rect
	FontSize float32
	Color    ui.Color
	MonoFace ui.MonoFace
	// AltSendsEscape asks printable Alt/Option chords on a terminal to arrive as
	// raw key events with the unmodified character in KeyEvent.Text. Terminal
	// encoders can then send the conventional Escape-prefixed Meta sequence.
	// It is ignored for ordinary text fields, and input-method composition keeps
	// ownership of every key until it commits. The native policy is currently
	// implemented on macOS; app.Driver implements it for headless verification.
	AltSendsEscape bool
	// KeyReleases asks a terminal for the whole keyboard as presses and
	// releases: the modifier keys, printable keys (as raw KeyEvents with Text,
	// not text events, unless an input method consumed them) and a KeyEvent
	// with Release set when each key goes up. It is for a terminal that shows
	// another machine's desktop, where a held key or modifier means something
	// there, and for a terminal implementing a keyboard protocol (kitty's
	// progressive enhancement or win32-input-mode). Releases are never delivered to a handler that did not ask, every
	// release matches a press the handler saw, and keys still down when the
	// terminal loses the keyboard or the window loses focus are released
	// first. Committed text from an input method still arrives as text events.
	// Implemented on macOS, Windows and X11, and by app.Driver.
	KeyReleases bool
	// NavigationKeys asks Up, Down, PageUp and PageDown to reach the
	// application as raw ui.KeyEvents while the field is focused, instead
	// of being consumed by the text system or moving its caret. Use it
	// for a search field, combobox or command palette with a dropdown.
	// Cursor placement, selection, Home/End, word navigation and
	// input-method composition remain native. Defaults to the component's
	// declaration (see TextInputContext.NavigationKeys).
	// Honored by the macOS text system and app.Driver; the other platform
	// backends do not consult it yet.
	NavigationKeys bool
	// Editor connects the native text service straight to a text.Editor: the
	// runtime mirrors the editor into the platform and applies every native
	// event to it, so State and OnEvent are ignored. Leave it nil to own the
	// event handling yourself, for example to filter or transform edits.
	Editor  *text.Editor
	State   TextState
	OnEvent func(TextEvent) (TextState, error)
}

TextInput describes one application-owned native editor surface. Bounds are logical window pixels. Bounds, FontSize and Color default to the text geometry the focused component declared (see TextInputContext), which is what keeps the text from jumping when a field gains focus.