input

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DeltaPixel = 0
	DeltaLine  = 1
	DeltaPage  = 2
)
View Source
const (
	KeyLocationStandard = 0
	KeyLocationLeft     = 1
	KeyLocationRight    = 2
	KeyLocationNumpad   = 3
)
View Source
const (
	MouseNone   = MouseButton(-1)
	MouseLeft   = MouseButton(0)
	MouseRight  = MouseButton(2)
	MouseMiddle = MouseButton(1)
)

Variables

This section is empty.

Functions

func ApplyTextEditsInRange

func ApplyTextEditsInRange(value string, selectionStart, selectionEnd, maxRunes int, multiline bool, edits []TextEdit) (string, int, int)

Types

type Dispatch

type Dispatch struct {
	Event   Event
	Phase   Phase
	Handled bool
}

func (*Dispatch) Consume

func (d *Dispatch) Consume()

type Event

type Event struct {
	// File is set for EventFilesDropped. One event is emitted per dropped file.
	File        string
	Text        string
	Composition TextComposition
	Selection   TextSelection
	WheelY      float64
	Y           float64
	DeltaX      float64
	DeltaY      float64
	WheelX      float64
	Seq         uint64
	X           float64
	Key         KeyCode
	Button      MouseButton
	Command     TextCommand
	Kind        EventKind
}

Event is the normalized, ordered input stream produced by a window.

The platform boundary uses a tagged value so keyboard, pointer, and text events retain their relative order. Gameplay and UI events should continue to use typed ECS messages.

type EventKind

type EventKind uint8

EventKind identifies one normalized platform input event.

const (
	EventKeyDown EventKind = iota + 1
	EventKeyUp
	EventTextInput
	EventTextComposition
	EventTextCommand
	EventTextSelection
	EventMouseDown
	EventMouseUp
	EventMouseMove
	EventMouseWheel
	EventTouchStart
	EventTouchMove
	EventTouchEnd
	// EventFilesDropped reports one file dropped onto the window.
	EventFilesDropped
)

type KeyCode

type KeyCode int
const (
	KeySpace        KeyCode = 32
	KeyApostrophe   KeyCode = 222
	KeyComma        KeyCode = 188
	KeyMinus        KeyCode = 189
	KeyPeriod       KeyCode = 190
	KeySlash        KeyCode = 191
	KeyNum0         KeyCode = 48
	KeyNum1         KeyCode = 49
	KeyNum2         KeyCode = 50
	KeyNum3         KeyCode = 51
	KeyNum4         KeyCode = 52
	KeyNum5         KeyCode = 53
	KeyNum6         KeyCode = 54
	KeyNum7         KeyCode = 55
	KeyNum8         KeyCode = 56
	KeyNum9         KeyCode = 57
	KeySemicolon    KeyCode = 186
	KeyEqual        KeyCode = 187
	KeyA            KeyCode = 65
	KeyB            KeyCode = 66
	KeyC            KeyCode = 67
	KeyD            KeyCode = 68
	KeyE            KeyCode = 69
	KeyF            KeyCode = 70
	KeyG            KeyCode = 71
	KeyH            KeyCode = 72
	KeyI            KeyCode = 73
	KeyJ            KeyCode = 74
	KeyK            KeyCode = 75
	KeyL            KeyCode = 76
	KeyM            KeyCode = 77
	KeyN            KeyCode = 78
	KeyO            KeyCode = 79
	KeyP            KeyCode = 80
	KeyQ            KeyCode = 81
	KeyR            KeyCode = 82
	KeyS            KeyCode = 83
	KeyT            KeyCode = 84
	KeyU            KeyCode = 85
	KeyV            KeyCode = 86
	KeyW            KeyCode = 87
	KeyX            KeyCode = 88
	KeyY            KeyCode = 89
	KeyZ            KeyCode = 90
	KeyLeftBracket  KeyCode = 219
	KeyBackslash    KeyCode = 220
	KeyRightBracket KeyCode = 221
	KeyGraveAccent  KeyCode = 192
	KeyWorld1       KeyCode = -iota - 1
	KeyWorld2       KeyCode = -iota - 1
	KeyEscape       KeyCode = 27
	KeyEnter        KeyCode = 13
	KeyTab          KeyCode = 9
	KeyBackspace    KeyCode = 8
	KeyInsert       KeyCode = -iota - 1
	KeyDelete       KeyCode = 46
	KeyRight        KeyCode = 39
	KeyLeft         KeyCode = 37
	KeyDown         KeyCode = 40
	KeyUp           KeyCode = 38
	KeyPageUp       KeyCode = -iota - 1
	KeyPageDown     KeyCode = -iota - 1
	KeyHome         KeyCode = -iota - 1
	KeyEnd          KeyCode = -iota - 1
	KeyCapsLock     KeyCode = 20
	KeyScrollLock   KeyCode = -iota - 1
	KeyNumLock      KeyCode = -iota - 1
	KeyPrintScreen  KeyCode = -iota - 1
	KeyPause        KeyCode = -iota - 1
	KeyF1           KeyCode = 112
	KeyF2           KeyCode = 113
	KeyF3           KeyCode = 114
	KeyF4           KeyCode = 115
	KeyF5           KeyCode = 116
	KeyF6           KeyCode = 117
	KeyF7           KeyCode = 118
	KeyF8           KeyCode = 119
	KeyF9           KeyCode = 120
	KeyF10          KeyCode = 121
	KeyF11          KeyCode = 122
	KeyF12          KeyCode = 123
	KeyF13          KeyCode = -iota - 1
	KeyF14          KeyCode = -iota - 1
	KeyF15          KeyCode = -iota - 1
	KeyF16          KeyCode = -iota - 1
	KeyF17          KeyCode = -iota - 1
	KeyF18          KeyCode = -iota - 1
	KeyF19          KeyCode = -iota - 1
	KeyF20          KeyCode = -iota - 1
	KeyF21          KeyCode = -iota - 1
	KeyF22          KeyCode = -iota - 1
	KeyF23          KeyCode = -iota - 1
	KeyF24          KeyCode = -iota - 1
	KeyF25          KeyCode = -iota - 1
	KeyKP0          KeyCode = -iota - 1
	KeyKP1          KeyCode = -iota - 1
	KeyKP2          KeyCode = -iota - 1
	KeyKP3          KeyCode = -iota - 1
	KeyKP4          KeyCode = -iota - 1
	KeyKP5          KeyCode = -iota - 1
	KeyKP6          KeyCode = -iota - 1
	KeyKP7          KeyCode = -iota - 1
	KeyKP8          KeyCode = -iota - 1
	KeyKP9          KeyCode = -iota - 1
	KeyKPDecimal    KeyCode = -iota - 1
	KeyKPDivide     KeyCode = -iota - 1
	KeyKPMultiply   KeyCode = -iota - 1
	KeyKPSubtract   KeyCode = -iota - 1
	KeyKPAdd        KeyCode = -iota - 1
	KeyKPEnter      KeyCode = -iota - 1
	KeyKPEqual      KeyCode = -iota - 1
	KeyLeftShift    KeyCode = 340
	KeyLeftControl  KeyCode = 341
	KeyLeftAlt      KeyCode = 342
	KeyLeftSuper    KeyCode = 91
	KeyRightShift   KeyCode = 344
	KeyRightControl KeyCode = 345
	KeyRightAlt     KeyCode = 346
	KeyRightSuper   KeyCode = 93
	KeyMenu         KeyCode = -iota - 1
)

TODO: s defined as -iota-1 need to be set to a valid positive value that matches the keyCode

Key generated by browsers. -iota-1 is used as a temporary solution to have unique but invalid values.
KeySee https://developer.mozilla.org/en-US/docs/Web/API/boardEvent/keyCode.

type Modifiers

type Modifiers uint8

Modifiers records the modifier keys held at a key press.

const (
	ModifierControl Modifiers = 1 << iota
	ModifierSuper
	ModifierShift
	ModifierAlt
)

type MouseButton

type MouseButton int8

type Phase

type Phase uint8
const (
	PhaseGlobal Phase = iota
	PhaseGUI
	PhaseShortcut
	PhaseUnhandled
)

type Pointer

type Pointer struct {
	X, Y           float32
	PressX, PressY float32
	DeltaX, DeltaY float32
	WheelX, WheelY float32
	Device         PointerDevice
	Down           bool
	Pressed        bool
	Released       bool
}

type PointerDevice

type PointerDevice uint8
const (
	PointerDeviceNone PointerDevice = iota
	PointerDeviceMouse
	PointerDeviceTouch
)

type State

type State struct {
	// contains filtered or unexported fields
}

func NewState

func NewState() *State

func (*State) AppendTextEdits

func (s *State) AppendTextEdits(dst []TextEdit) []TextEdit

AppendTextEdits appends this frame's effective text edits to dst.

func (*State) ApplyEvent

func (s *State) ApplyEvent(event Event)

ApplyEvent derives the queryable input state from one normalized event.

func (*State) ApplyTextComposition

func (s *State) ApplyTextComposition(event TextComposition)

func (*State) ApplyTextEditsInRange

func (s *State) ApplyTextEditsInRange(value string, selectionStart, selectionEnd, maxRunes int, multiline bool, edits []TextEdit) (string, int, int)

ApplyTextEditsInRange applies edits through the State's reusable piece tree. Keeping the buffer on the active input session avoids rebuilding a rune slice for every key press.

func (*State) ApplyTextSelection

func (s *State) ApplyTextSelection(selection TextSelection)

func (*State) BlurTextInput

func (s *State) BlurTextInput()

func (*State) ClipboardText

func (s *State) ClipboardText() (string, bool)

func (*State) CommitText

func (s *State) CommitText(text string)

func (*State) Composing

func (s *State) Composing() bool

func (*State) CompositionHandledKey

func (s *State) CompositionHandledKey() bool

func (*State) CompositionText

func (s *State) CompositionText() string

func (*State) ConsumeEvent

func (s *State) ConsumeEvent(sequence uint64)

ConsumeEvent prevents later input stages from handling the same event.

func (*State) ConsumePointerWheel

func (s *State) ConsumePointerWheel()

func (*State) CopyFrom

func (s *State) CopyFrom(source *State)

CopyFrom reuses storage for an isolated snapshot of keyboard and pointer state.

func (*State) DrainEvents

func (s *State) DrainEvents() []Event

DrainEvents returns events in platform arrival order. The returned slice is owned by the caller until the next Enqueue call.

func (*State) EndFrame

func (s *State) EndFrame()

func (*State) Enqueue

func (s *State) Enqueue(event Event)

Enqueue records a normalized platform event for the next input stage.

func (*State) EventConsumed

func (s *State) EventConsumed(sequence uint64) bool

func (*State) FocusTextInput

func (s *State) FocusTextInput(kind TextInputKind, multiline bool, initialValue string)

func (*State) HasPendingEvents

func (s *State) HasPendingEvents() bool

func (*State) KeyHeld

func (s *State) KeyHeld(key KeyCode) bool

func (*State) KeyModifiers

func (s *State) KeyModifiers(key KeyCode) Modifiers

KeyModifiers returns the modifiers held when key was pressed this frame. Later modifier presses or releases do not change the recorded chord.

func (*State) KeyPressed

func (s *State) KeyPressed(key KeyCode) bool

func (*State) KeyPressedDuringComposition

func (s *State) KeyPressedDuringComposition(key KeyCode) bool

func (*State) KeyReleased

func (s *State) KeyReleased(key KeyCode) bool

func (*State) MouseHeld

func (s *State) MouseHeld(button MouseButton) bool

func (*State) MousePressed

func (s *State) MousePressed(button MouseButton) bool

func (*State) MouseReleased

func (s *State) MouseReleased(button MouseButton) bool

func (*State) MoveMouse

func (s *State) MoveMouse(x, y float64)

func (*State) Pointer

func (s *State) Pointer() Pointer

func (*State) PointerHeld

func (s *State) PointerHeld() bool

func (*State) PointerPressed

func (s *State) PointerPressed() bool

func (*State) PointerReleased

func (s *State) PointerReleased() bool

func (*State) PressKey

func (s *State) PressKey(key KeyCode)

func (*State) PressMouse

func (s *State) PressMouse(button MouseButton, x, y float64)

func (*State) PushTextCommand

func (s *State) PushTextCommand(command TextCommand)

func (*State) ReleaseKey

func (s *State) ReleaseKey(key KeyCode)

func (*State) ReleaseMouse

func (s *State) ReleaseMouse(button MouseButton, x, y float64)

func (*State) ScrollMouse

func (s *State) ScrollMouse(xoff, yoff float64)

func (*State) SetClipboard

func (s *State) SetClipboard(write func(string) bool, read func() (string, bool))

func (*State) SetClipboardText

func (s *State) SetClipboardText(text string) bool

func (*State) SetTextInputCaret

func (s *State) SetTextInputCaret(caret TextInputRect)

func (*State) SetTextInputSelection

func (s *State) SetTextInputSelection(start, end int)

func (*State) TextEdits

func (s *State) TextEdits() []TextEdit

func (*State) TextInputConfig

func (s *State) TextInputConfig() TextInputConfig

func (*State) TextSelection

func (s *State) TextSelection() (TextSelection, bool)

func (*State) TouchEnd

func (s *State) TouchEnd(x, y float64)

func (*State) TouchMove

func (s *State) TouchMove(x, y float64)

func (*State) TouchStart

func (s *State) TouchStart(x, y float64)

type TextBuffer

type TextBuffer struct {
	piecetree.Tree
	// contains filtered or unexported fields
}

TextBuffer owns a document's piece tree and reusable input scratch space. Keep one per editor document; String snapshots are immutable. Do not copy it.

func (*TextBuffer) ApplyEdits

func (b *TextBuffer) ApplyEdits(value piecetree.Snapshot, start, end, maxRunes int, multiline bool, edits []TextEdit) (piecetree.Snapshot, int, int)

ApplyEdits publishes immutable pieces without materializing the document.

func (*TextBuffer) ApplySnapshot

func (b *TextBuffer) ApplySnapshot(value string, start, oldEnd, newEnd int)

ApplySnapshot commits an external edit without allocating another full copy. The range must describe all differences from the current document.

func (*TextBuffer) ApplyTextEditsInRange

func (b *TextBuffer) ApplyTextEditsInRange(value string, start, end, maxRunes int, multiline bool, edits []TextEdit) (string, int, int)

ApplyTextEditsInRange uses rune selections and returns one cached snapshot after applying the entire batch to the tree.

func (*TextBuffer) ChangedRange

func (b *TextBuffer) ChangedRange(before, after string) (start, oldEnd, newEnd, prefixRunes int, ok bool)

ChangedRange reports the batch's byte delta without comparing document-sized snapshots. It is valid only for the exact before/after pair of the last edit.

func (*TextBuffer) Matches

func (b *TextBuffer) Matches(value string) bool

func (*TextBuffer) MatchesSnapshot

func (b *TextBuffer) MatchesSnapshot(value piecetree.Snapshot) bool

func (*TextBuffer) ReplaceBytes

func (b *TextBuffer) ReplaceBytes(start, end int, text string)

ReplaceBytes applies an external byte-range edit and caches its snapshot.

func (*TextBuffer) Snapshot

func (b *TextBuffer) Snapshot() piecetree.Snapshot

Snapshot returns the current immutable version, independent of future edits.

func (*TextBuffer) SnapshotChangedRange

func (b *TextBuffer) SnapshotChangedRange(before, after piecetree.Snapshot) (start, oldEnd, newEnd, prefixRunes int, ok bool)

func (*TextBuffer) String

func (b *TextBuffer) String() string

func (*TextBuffer) Sync

func (b *TextBuffer) Sync(value string)

Sync installs an external snapshot only when the document has changed.

func (*TextBuffer) SyncSnapshot

func (b *TextBuffer) SyncSnapshot(value piecetree.Snapshot)

type TextCommand

type TextCommand uint8
const (
	TextCommandBackspace TextCommand = iota + 1
	TextCommandEnter
)

type TextComposition

type TextComposition struct {
	Text   string
	Active bool
}

type TextEdit

type TextEdit struct {
	Text              string
	SelectionStart    int
	SelectionEnd      int
	Command           TextCommand
	DuringComposition bool
	HasSelection      bool
}

type TextInputConfig

type TextInputConfig struct {
	InitialValue   string
	Revision       uint64
	SelectionStart int
	SelectionEnd   int
	Caret          TextInputRect
	Kind           TextInputKind
	Active         bool
	Multiline      bool
}

func (TextInputConfig) Value

func (c TextInputConfig) Value() uint64

type TextInputKind

type TextInputKind uint8
const (
	TextInputText TextInputKind = iota
	TextInputDecimal
	TextInputInteger
)

type TextInputRect

type TextInputRect struct {
	X      float32
	Y      float32
	Width  float32
	Height float32
}

type TextSelection

type TextSelection struct {
	Start int
	End   int
}

Jump to

Keyboard shortcuts

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