Documentation ¶
Overview ¶
Package textinput provides a text-inputting controller. This package is experimental and the API might be changed in the future.
This package is supported by macOS and Web browsers so far.
Index ¶
- func Start(x, y int) (states chan State, close func())
- type Field
- func (f *Field) Blur()
- func (f *Field) CompositionSelection() (start, end int, ok bool)
- func (f *Field) Focus()
- func (f *Field) HandleInput(x, y int) (handled bool, err error)
- func (f *Field) IsFocused() bool
- func (f *Field) Selection() (start, end int)
- func (f *Field) SetSelection(start, end int)
- func (f *Field) SetTextAndSelection(text string, selectionStart, selectionEnd int)
- func (f *Field) Text() string
- func (f *Field) TextForRendering() string
- type State
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Field ¶ added in v2.7.0
type Field struct {
// contains filtered or unexported fields
}
Field is a region accepting text inputting with IME.
Field is not focused by default. You have to call Focus when you start text inputting.
Field is a wrapper of the low-level API like Start.
For an actual usage, see the examples "textinput".
func (*Field) CompositionSelection ¶ added in v2.7.0
CompositionSelection returns the current composition selection in bytes if a text is composited. If a text is not composited, this returns 0s and false. The returned values indicate relative positions in bytes where the current composition text's start is 0.
func (*Field) Focus ¶ added in v2.7.0
func (f *Field) Focus()
Focus focuses the field. A Field has to be focused to start text inputting.
There can be only one Field that is focused at the same time. When Focus is called and there is already a focused field, Focus removes the focus of that.
func (*Field) HandleInput ¶ added in v2.7.0
HandleInput updates the field state. HandleInput must be called every tick, i.e., every Update, when Field is focused. HandleInput takes a position where an IME window is shown if needed.
HandleInput returns whether the text inputting is handled or not. If HandleInput returns true, a Field user should not handle further input events.
HandleInput returns an error when handling input causes an error.
func (*Field) SetSelection ¶ added in v2.7.0
SetSelection sets the selection range.
func (*Field) SetTextAndSelection ¶ added in v2.7.0
SetTextAndSelection sets the text and the selection range.
func (*Field) Text ¶ added in v2.7.0
Text returns the current text. The returned value doesn't include compositing texts.
func (*Field) TextForRendering ¶ added in v2.7.0
TextForRendering returns the text for rendering. The returned value includes compositing texts.
type State ¶
type State struct { // Text represents the current inputting text. Text string // CompositionSelectionStartInBytes represents the start position of the selection in bytes. CompositionSelectionStartInBytes int // CompositionSelectionStartInBytes represents the end position of the selection in bytes. CompositionSelectionEndInBytes int // Committed reports whether the current Text is the settled text. Committed bool // Error is an error that happens during text inputting. Error error }
State represents the current state of text inputting.
State is the low-level API. For most use cases, Field is easier to use.