textinput

package
v2.7.2 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(x, y int) (states chan State, close func())

Start starts text inputting. Start returns a channel to send the state repeatedly, and a function to end the text inputting.

Start is the low-level API. For most use cases, Field is easier to use.

Start returns nil and nil if the current environment doesn't support this package.

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() (start, end 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 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.

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() (start, end int)

Selection returns the current selection range in bytes.

func (*Field) SetSelection added in v2.7.0

func (f *Field) SetSelection(start, end int)

SetSelection sets the selection range.

func (*Field) SetTextAndSelection added in v2.7.0

func (f *Field) SetTextAndSelection(text string, selectionStart, selectionEnd 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.

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.

Jump to

Keyboard shortcuts

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