input

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 6 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 (
	KeySpace        = KeyCode(32)
	KeyApostrophe   = KeyCode(39)
	KeyComma        = KeyCode(44)
	KeyMinus        = KeyCode(45)
	KeyPeriod       = KeyCode(46)
	KeySlash        = KeyCode(47)
	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(59)
	KeyEqual        = KeyCode(61)
	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(91)
	KeyBackslash    = KeyCode(92)
	KeyRightBracket = KeyCode(93)
	KeyGraveAccent  = KeyCode(96)
	KeyWorld1       = KeyCode(161)
	KeyWorld2       = KeyCode(162)
	KeyEscape       = KeyCode(256)
	KeyEnter        = KeyCode(257)
	KeyTab          = KeyCode(258)
	KeyBackspace    = KeyCode(259)
	KeyInsert       = KeyCode(260)
	KeyDelete       = KeyCode(261)
	KeyRight        = KeyCode(262)
	KeyLeft         = KeyCode(263)
	KeyDown         = KeyCode(264)
	KeyUp           = KeyCode(265)
	KeyPageUp       = KeyCode(266)
	KeyPageDown     = KeyCode(267)
	KeyHome         = KeyCode(268)
	KeyEnd          = KeyCode(269)
	KeyCapsLock     = KeyCode(280)
	KeyScrollLock   = KeyCode(281)
	KeyNumLock      = KeyCode(282)
	KeyPrintScreen  = KeyCode(283)
	KeyPause        = KeyCode(284)
	KeyF1           = KeyCode(290)
	KeyF2           = KeyCode(291)
	KeyF3           = KeyCode(292)
	KeyF4           = KeyCode(293)
	KeyF5           = KeyCode(294)
	KeyF6           = KeyCode(295)
	KeyF7           = KeyCode(296)
	KeyF8           = KeyCode(297)
	KeyF9           = KeyCode(298)
	KeyF10          = KeyCode(299)
	KeyF11          = KeyCode(300)
	KeyF12          = KeyCode(301)
	KeyF13          = KeyCode(302)
	KeyF14          = KeyCode(303)
	KeyF15          = KeyCode(304)
	KeyF16          = KeyCode(305)
	KeyF17          = KeyCode(306)
	KeyF18          = KeyCode(307)
	KeyF19          = KeyCode(308)
	KeyF20          = KeyCode(309)
	KeyF21          = KeyCode(310)
	KeyF22          = KeyCode(311)
	KeyF23          = KeyCode(312)
	KeyF24          = KeyCode(313)
	KeyF25          = KeyCode(314)
	KeyKP0          = KeyCode(320)
	KeyKP1          = KeyCode(321)
	KeyKP2          = KeyCode(322)
	KeyKP3          = KeyCode(323)
	KeyKP4          = KeyCode(324)
	KeyKP5          = KeyCode(325)
	KeyKP6          = KeyCode(326)
	KeyKP7          = KeyCode(327)
	KeyKP8          = KeyCode(328)
	KeyKP9          = KeyCode(329)
	KeyKPDecimal    = KeyCode(330)
	KeyKPDivide     = KeyCode(331)
	KeyKPMultiply   = KeyCode(332)
	KeyKPSubtract   = KeyCode(333)
	KeyKPAdd        = KeyCode(334)
	KeyKPEnter      = KeyCode(335)
	KeyKPEqual      = KeyCode(336)
	KeyLeftShift    = KeyCode(340)
	KeyLeftControl  = KeyCode(341)
	KeyLeftAlt      = KeyCode(342)
	KeyLeftSuper    = KeyCode(343)
	KeyRightShift   = KeyCode(344)
	KeyRightControl = KeyCode(345)
	KeyRightAlt     = KeyCode(346)
	KeyRightSuper   = KeyCode(347)
	KeyMenu         = KeyCode(348)
)
View Source
const (
	MouseNone   = MouseButton(-1)
	MouseLeft   = MouseButton(0)
	MouseRight  = MouseButton(1)
	MouseMiddle = MouseButton(2)
)

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 Cursor added in v0.1.4

type Cursor uint8

Cursor is the system pointer shape, independent of keyboard focus.

const (
	CursorDefault Cursor = iota
	CursorText
	CursorPointer
	CursorCrosshair
	CursorMove
	CursorEWResize
	CursorNSResize
	CursorNESWResize
	CursorNWSEResize
	CursorGrab
	CursorGrabbing
	CursorNotAllowed
	CursorWait
	CursorProgress
	CursorHelp
	CursorNone
	CursorVerticalText
	CursorAllScroll
	CursorContextMenu
	CursorCell
	CursorCopy
	CursorAlias
	CursorZoomIn
	CursorZoomOut
)

func ParseCursor added in v0.1.4

func ParseCursor(value string) (Cursor, bool)

ParseCursor resolves CSS cursor keywords to native pointer shapes.

func (Cursor) String added in v0.1.4

func (c Cursor) String() string

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

KeyCode is the canonical desktop key space used inside Onix. Native Windows/Linux key events are normalized to these values by each window backend.

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) Cursor added in v0.1.4

func (s *State) Cursor() Cursor

func (*State) DrainEvents

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

DrainEvents returns events in platform arrival order. The returned slice is borrowed until ReleaseEvents, EndFrame, or 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) ReleaseEvents added in v0.1.6

func (s *State) ReleaseEvents()

ReleaseEvents clears consumed events while preserving events queued since the last drain. Call after processing the borrowed slice.

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) SetCursor added in v0.1.4

func (s *State) SetCursor(cursor Cursor)

SetCursor selects the pointer shape for the current UI hit.

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