Documentation
¶
Overview ¶
Package field keeps what a backend reports about one text field the way NSH's platforms do, whatever control edits it: the user's edits and their count, a composition and the value the app sets during one, the selection, keys and maxLength.
Index ¶
- func Replaced(old, text string) (start, end int, insert string)
- func SingleLine(s string) string
- type State
- func (s *State) Compose(composing bool, text, current string) (value string, apply bool)
- func (s *State) Composing() bool
- func (s *State) Edited(text string) bool
- func (s *State) Insert(current string, replaced int, insert string) (kept string, ok, whole bool)
- func (s *State) Key(key string)
- func (s *State) Known() string
- func (s *State) Return(text string, lineBreak bool) (insert, blur bool)
- func (s *State) Selected(r driver.TextRange)
- func (s *State) Selection() driver.TextRange
- func (s *State) SetSelection(r driver.TextRange)
- func (s *State) Value(text string, count uint32) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Replaced ¶
Replaced is what turns old into text, in UTF-16 units, the offsets UIKit's and AppKit's text inputs take: old's units from start to end become insert. A surrogate pair stays whole, and equal texts give an empty range at old's end.
func SingleLine ¶
SingleLine replaces line breaks with spaces, as a single-line field holds them.
Types ¶
type State ¶
type State struct {
ID driver.NodeID
// Events is the field's mask (ItemEvents); Config its last ItemInput.
Events driver.EventMask
Config driver.InputConfig
Dispatch func(driver.Event)
// Count is the user's edits reported.
Count uint32
// contains filtered or unexported fields
}
State is the reporting side of one text field. Backends call it from their main thread as the control changes, and it dispatches the events the field's mask asks for.
func (*State) Compose ¶
Compose records the input method's composition (composing false once it ended) and reports a change. When it ends, it returns a value the app set meanwhile for the backend to set, provided no edit came since and current, the field's text, is what the engine knows.
func (*State) Edited ¶
Edited reports the user's edit leaving text in the field, unless the engine already knows it holds text. It returns whether it reported.
func (*State) Insert ¶
Insert answers whether the user's edit replacing replaced UTF-16 units of current with insert may happen, as the platforms' should-change callbacks ask: it reports the key and returns the part of insert MaxLength leaves room for, with line breaks made spaces in a single line. ok is false when nothing of a non-empty insert fits, and whole whether kept is insert as it came.
func (*State) Return ¶
Return decides what Return does: true when the backend lets the control insert a line break, else it has reported the key and the submit and returns whether to blur. lineBreak is a modifier held (Shift, Option, Alt) that breaks the line of a multiline field that submits.
func (*State) Selected ¶
Selected reports the selection the user left, in UTF-16 units, if it moved.
func (*State) SetSelection ¶
SetSelection records a selection the app set, which is not reported.