textinput

package
v2.9.2 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2025 License: Apache-2.0 Imports: 7 Imported by: 11

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 on Windows, macOS, and Web browsers so far.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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) Blur added in v2.7.0

func (f *Field) Blur()

Blur removes the focus from the field.

func (*Field) CompositionSelection added in v2.7.0

func (f *Field) CompositionSelection() (startInBytes, endInBytes int, ok bool)

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 deprecated added in v2.7.0

func (f *Field) HandleInput(x, y int) (handled bool, err error)

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.

Deprecated: use HandleInputWithBounds instead.

func (*Field) HandleInputWithBounds added in v2.9.0

func (f *Field) HandleInputWithBounds(bounds image.Rectangle) (handled bool, err error)

HandleInputWithBounds updates the field state. HandleInputWithBounds must be called every tick, i.e., every Update, when Field is focused. HandleInputWithBounds takes a character bounds, which decides the position where an IME window is shown if needed. The bounds width doesn't matter very much as long as it is greater than 0. The bounds height should be the text height like a cursor height.

HandleInputWithBounds returns whether the text inputting is handled or not. If HandleInputWithBounds returns true, a Field user should not handle further input events.

HandleInputWithBounds returns an error when handling input causes an error.

func (*Field) IsFocused added in v2.7.0

func (f *Field) IsFocused() bool

IsFocused reports whether the field is focused or not.

func (*Field) Selection added in v2.7.0

func (f *Field) Selection() (startInBytes, endInBytes int)

Selection returns the current selection range in bytes.

func (*Field) SetSelection added in v2.7.0

func (f *Field) SetSelection(startInBytes, endInBytes int)

SetSelection sets the selection range.

func (*Field) SetTextAndSelection added in v2.7.0

func (f *Field) SetTextAndSelection(text string, selectionStartInBytes, selectionEndInBytes int)

SetTextAndSelection sets the text and the selection range.

func (*Field) Text added in v2.7.0

func (f *Field) Text() string

Text returns the current text. The returned value doesn't include compositing texts.

func (*Field) TextForRendering added in v2.7.0

func (f *Field) TextForRendering() string

TextForRendering returns the text for rendering. The returned value includes compositing texts.

func (*Field) UncommittedTextLengthInBytes added in v2.9.0

func (f *Field) UncommittedTextLengthInBytes() int

UncommittedTextLengthInBytes returns the compositing text length in bytes when the field is focused and the text is editing. The uncommitted text range is from the selection start to the selection start + the uncommitted text length. UncommittedTextLengthInBytes returns 0 otherwise.

Jump to

Keyboard shortcuts

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