events

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: BSD-3-Clause Imports: 9 Imported by: 35

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ScrollWheelSpeed controls how fast the scroll wheel moves (typically
	// interpreted as pixels per wheel step).
	// This is also in core.DeviceSettings and updated from there
	ScrollWheelSpeed = float32(1)
)
View Source
var TraceEventCompression = false

TraceEventCompression can be set to true to see when events are being compressed to eliminate laggy behavior.

View Source
var TraceWindowPaint = false

TraceWindowPaint prints out a . for each WindowPaint event, - for other window events, and * for mouse move events. Makes it easier to see what is going on in the overall flow.

Functions

This section is empty.

Types

type Base

type Base struct {
	// Typ is the type of event, returned as Type()
	Typ Types

	// Flags records event boolean state, using atomic flag operations
	Flags EventFlags

	// GenTime records the time when the event was first generated, using more
	// efficient nptime struct
	GenTime nptime.Time

	// Key Modifiers present when event occurred: for Key, Mouse, Touch events
	Mods key.Modifiers

	// Where is the window-based position in raw display dots
	// (pixels) where event took place.
	Where image.Point

	// Start is the window-based starting position in raw display dots
	// (pixels) where event started.
	Start image.Point

	// Prev is the window-based previous position in raw display dots
	// (pixels) -- e.g., for mouse dragging.
	Prev image.Point

	// StTime is the starting time, using more efficient nptime struct
	StTime nptime.Time

	// PrvTime is the time of the previous event, using more efficient nptime struct
	PrvTime nptime.Time

	// LocalOffset is the offset subtracted from original window coordinates
	// to compute the local coordinates.
	LocalOffset image.Point

	// WhereLocal is the local position, which can be adjusted from the window pos
	// via SubLocalOffset based on a local top-left coordinate for a region within
	// the window.
	WhereLocal image.Point

	// StartLocal is the local starting position
	StartLocal image.Point

	// PrevLocal is the local previous position
	PrevLocal image.Point

	// Button is the mouse button being pressed or released, for relevant events.
	Button Buttons

	// Rune is the meaning of the key event as determined by the
	// operating system. The mapping is determined by system-dependent
	// current layout, modifiers, lock-states, etc.
	Rune rune

	// Code is the identity of the physical key relative to a notional
	// "standard" keyboard, independent of current layout, modifiers,
	// lock-states, etc
	Code key.Codes

	// todo: add El info
	Data any
}

Base is the base type for events. It is designed to support most event types so no further subtypes are needed.

func (*Base) AsBase

func (ev *Base) AsBase() *Base

func (*Base) ClearHandled

func (ev *Base) ClearHandled()

func (Base) Clone

func (ev Base) Clone() Event

func (Base) HasAllModifiers

func (ev Base) HasAllModifiers(mods ...enums.BitFlag) bool

HasAllModifiers tests whether all of given modifier(s) were set

func (Base) HasAnyModifier

func (ev Base) HasAnyModifier(mods ...enums.BitFlag) bool

func (Base) HasPos

func (ev Base) HasPos() bool

func (*Base) Init

func (ev *Base) Init()

func (Base) IsHandled

func (ev Base) IsHandled() bool

func (Base) IsSame

func (ev Base) IsSame(oth Event) bool

func (Base) IsUnique

func (ev Base) IsUnique() bool

func (Base) KeyChord

func (ev Base) KeyChord() key.Chord

KeyChord returns a string representation of the keyboard event suitable for keyboard function maps, etc. Printable runes are sent directly, and non-printable ones are converted to their corresponding code names without the "Code" prefix.

func (Base) KeyCode

func (ev Base) KeyCode() key.Codes

func (Base) KeyRune

func (ev Base) KeyRune() rune

func (Base) LocalOff

func (ev Base) LocalOff() image.Point

func (Base) Modifiers

func (ev Base) Modifiers() key.Modifiers

Modifiers returns the modifier keys present at time of event

func (Base) MouseButton

func (ev Base) MouseButton() Buttons

MouseButton is the mouse button being pressed or released, for relevant events.

func (Base) NeedsFocus

func (ev Base) NeedsFocus() bool

func (Base) NewFromClone

func (ev Base) NewFromClone(typ Types) Event

func (Base) OnWinFocus

func (ev Base) OnWinFocus() bool

func (Base) Pos

func (ev Base) Pos() image.Point

func (Base) PrevDelta

func (ev Base) PrevDelta() image.Point

func (Base) PrevPos

func (ev Base) PrevPos() image.Point

func (Base) PrevTime

func (ev Base) PrevTime() time.Time

func (Base) SelectMode

func (ev Base) SelectMode() SelectModes

SelectMode returns the selection mode based on given modifiers on event

func (*Base) SetHandled

func (ev *Base) SetHandled()

func (*Base) SetLocalOff

func (ev *Base) SetLocalOff(off image.Point)

func (*Base) SetModifiers

func (ev *Base) SetModifiers(mods ...enums.BitFlag)

SetModifiers sets the bitflags based on a list of key.Modifiers

func (*Base) SetTime

func (ev *Base) SetTime()

SetTime sets the event time to Now

func (*Base) SetUnique

func (ev *Base) SetUnique()

func (Base) SincePrev

func (ev Base) SincePrev() time.Duration

func (Base) SinceStart

func (ev Base) SinceStart() time.Duration

func (Base) StartDelta

func (ev Base) StartDelta() image.Point

func (Base) StartPos

func (ev Base) StartPos() image.Point

func (Base) StartTime

func (ev Base) StartTime() time.Time

func (Base) String

func (ev Base) String() string

func (Base) Time

func (ev Base) Time() time.Time

func (Base) Type

func (ev Base) Type() Types

func (Base) WindowPos

func (ev Base) WindowPos() image.Point

func (Base) WindowPrevPos

func (ev Base) WindowPrevPos() image.Point

func (Base) WindowStartPos

func (ev Base) WindowStartPos() image.Point

type Buttons

type Buttons int32 //enums:enum

Buttons is a mouse button.

const (
	NoButton Buttons = iota
	Left
	Middle
	Right
)
const ButtonsN Buttons = 4

ButtonsN is the highest valid value for type Buttons, plus one.

func ButtonsValues

func ButtonsValues() []Buttons

ButtonsValues returns all possible values for the type Buttons.

func (Buttons) Desc

func (i Buttons) Desc() string

Desc returns the description of the Buttons value.

func (Buttons) Int64

func (i Buttons) Int64() int64

Int64 returns the Buttons value as an int64.

func (Buttons) MarshalText

func (i Buttons) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Buttons) SetInt64

func (i *Buttons) SetInt64(in int64)

SetInt64 sets the Buttons value from an int64.

func (*Buttons) SetString

func (i *Buttons) SetString(s string) error

SetString sets the Buttons value from its string representation, and returns an error if the string is invalid.

func (Buttons) String

func (i Buttons) String() string

String returns the string representation of this Buttons value.

func (*Buttons) UnmarshalText

func (i *Buttons) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Buttons) Values

func (i Buttons) Values() []enums.Enum

Values returns all possible values for the type Buttons.

type CustomEvent

type CustomEvent struct {
	Base

	// set to true if position is available
	PosAvail bool
}

CustomEvent is a user-specified event that can be sent and received as needed, and contains a Data field for arbitrary data, and optional position and focus parameters

func (CustomEvent) HasPos

func (ce CustomEvent) HasPos() bool

func (CustomEvent) String

func (ce CustomEvent) String() string

type Deque

type Deque struct {
	Back  []Event // FIFO.
	Front []Event // LIFO.

	Mu   sync.Mutex
	Cond sync.Cond // Cond.L is lazily initialized to &Deque.Mu.
}

Dequer is an infinitely buffered double-ended queue of events. If an event is not marked as Unique, and the last event in the queue is of the same type, then the new one replaces the last one. This automatically implements event compression to manage the common situation where event processing is slower than event generation, such as with Mouse movement and Paint events. The zero value is usable, but a Deque value must not be copied.

func (*Deque) LockAndInit

func (q *Deque) LockAndInit()

func (*Deque) NextEvent

func (q *Deque) NextEvent() Event

NextEvent returns the next event in the deque. It blocks until such an event has been sent.

func (*Deque) PollEvent

func (q *Deque) PollEvent() (Event, bool)

PollEvent returns the next event in the deque if available, and returns true. If none are available, it returns false immediately.

func (*Deque) Send

func (q *Deque) Send(ev Event)

Send adds an event to the end of the deque, replacing the last of the same type unless marked as Unique. They are returned by NextEvent in FIFO order.

func (*Deque) SendFirst

func (q *Deque) SendFirst(ev Event)

SendFirst adds an event to the start of the deque. They are returned by NextEvent in LIFO order, and have priority over events sent via Send. This is typically reserved for window events.

type DragDrop

type DragDrop struct {
	Base

	// When event is received by target, DropMod indicates the suggested modifier
	// action associated with the drop (affected by holding down modifier
	// keys), suggesting what to do with the dropped item, where appropriate.
	// Receivers can ignore or process in their own relevant way as needed,
	// BUT it is essential to update the event with the actual type of Mod
	// action taken, because the event will be sent back to the source with
	// this Mod as set by the receiver.  The main consequence is that a
	// DropMove requires the drop source to delete itself once the event has
	// been received, otherwise it (typically) doesn't do anything, so just
	// be careful about that particular case.
	DropMod DropMods

	// Data contains the data from the Source of the drag,
	// typically a mimedata encoded representation.
	Data any

	// Source of the drop, only available for internal DND actions.
	// If it is an external drop, this will be nil.
	Source any

	// Target of the drop -- receiver of an accepted drop should set this to
	// itself, so Source (if internal) can see who got it
	Target any
}

DragDrop represents the drag-and-drop Drop event

func NewDragDrop

func NewDragDrop(typ Types, mdrag *Mouse) *DragDrop

func NewExternalDrop

func NewExternalDrop(typ Types, but Buttons, where image.Point, mods key.Modifiers, data any) *DragDrop

func (*DragDrop) DefaultMod

func (e *DragDrop) DefaultMod()

DefaultMod sets the default DropMod modifier action based on modifier keys

func (*DragDrop) HasPos

func (ev *DragDrop) HasPos() bool

func (*DragDrop) String

func (ev *DragDrop) String() string

type DropMods

type DropMods int32 //enums:enum -trim-prefix Drop

DropMods indicates the modifier associated with the drop action (affected by holding down modifier keys), suggesting what to do with the dropped item, where appropriate

const (
	NoDropMod DropMods = iota

	// Copy is the default and implies data is just copied -- receiver can do
	// with it as they please and source does not need to take any further
	// action
	DropCopy

	// Move is signaled with a Shift or Meta key (by default) and implies that
	// the source should delete itself when it receives the DropFromSource event
	// action with this Mod value set -- receiver must update the Mod to
	// reflect actual action taken, and be particularly careful with this one
	DropMove

	// Link can be any other kind of alternative action -- link is applicable
	// to files (symbolic link)
	DropLink

	// Ignore means that the receiver chose to not process this drop
	DropIgnore
)
const DropModsN DropMods = 5

DropModsN is the highest valid value for type DropMods, plus one.

func DefaultModBits

func DefaultModBits(mods key.Modifiers) DropMods

DefaultModBits returns the default DropMod modifier action based on modifier keys

func DropModsValues

func DropModsValues() []DropMods

DropModsValues returns all possible values for the type DropMods.

func (DropMods) Desc

func (i DropMods) Desc() string

Desc returns the description of the DropMods value.

func (DropMods) Int64

func (i DropMods) Int64() int64

Int64 returns the DropMods value as an int64.

func (DropMods) MarshalText

func (i DropMods) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*DropMods) SetInt64

func (i *DropMods) SetInt64(in int64)

SetInt64 sets the DropMods value from an int64.

func (*DropMods) SetString

func (i *DropMods) SetString(s string) error

SetString sets the DropMods value from its string representation, and returns an error if the string is invalid.

func (DropMods) String

func (i DropMods) String() string

String returns the string representation of this DropMods value.

func (*DropMods) UnmarshalText

func (i *DropMods) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (DropMods) Values

func (i DropMods) Values() []enums.Enum

Values returns all possible values for the type DropMods.

type Event

type Event interface {
	fmt.Stringer

	// Type returns the type of event associated with given event
	Type() Types

	// AsBase returns this event as a Base event type,
	// which is used for most Event types.
	AsBase() *Base

	// IsUnique returns true if this event must always be sent,
	// even if the last event sent is of the same type.
	// This is true for Key, MouseButton,
	// Otherwise, events of the same type are compressed
	// such that if the last one written to the queue is of
	// the same type, it is replaced instead of adding a new one.
	IsUnique() bool

	// NeedsFocus this event goes to current focus widget
	NeedsFocus() bool

	// HasPos returns true if the event has a window position where it takes place
	HasPos() bool

	// WindowPos returns the original window-based position in raw display dots
	// (pixels) where event took place.
	WindowPos() image.Point

	// SetLocalOff sets the offset subtracted from window-based positions
	// to compute Local versions of positions, which are updated.
	SetLocalOff(off image.Point)

	// LocalOff returns the offset subtracted from window-based positions
	// to compute Local versions of positions.
	LocalOff() image.Point

	// Pos returns the local position, which is adjusted from the WindowPos
	// via SubLocalOffset based on a local top-left coordinate for a region
	// within the window.
	Pos() image.Point

	// WindowStartPos returns the starting (MouseDown) window-based position.
	WindowStartPos() image.Point

	// StartPos returns the starting (MouseDown) local position
	StartPos() image.Point

	// StartDelta returns Pos - Start
	StartDelta() image.Point

	// WindowPrevPos returns the previous (MouseMove/Drag) window-based position.
	WindowPrevPos() image.Point

	// PrevPos returns the previous (MouseMove/Drag) local position
	PrevPos() image.Point

	// PrevDelta returns Pos - Prev
	PrevDelta() image.Point

	// Time returns the time at which the event was generated, in UnixNano nanosecond units
	Time() time.Time

	// StartTime returns time of StartPos (MouseDown),
	// or other starting time of relevance to the event.
	StartTime() time.Time

	// SinceStart returns Time().Sub(StartTime()) -- duration since Start
	SinceStart() time.Duration

	// PrevTime returns time of PrevPos (MouseMove),
	// or other earlier time of relevance to the event.
	PrevTime() time.Time

	// SincePrev returns Time().Sub(PrevTime()) -- duration since Prev
	SincePrev() time.Duration

	// IsHandled returns whether this event has already been processed
	// Event handling checks this and terminates processing if
	// SetHandled has been called.
	IsHandled() bool

	// SetHandled marks the event as having been processed,
	// so no further processing occurs.  This can accomplish
	// the same effect as PreventDefault function in JavaScript.
	SetHandled()

	// ClearHandled marks the event as no longer having been processed,
	// meaning that it will be processed by future event handlers.
	// This reverses the effects of [Event.SetHandled].
	ClearHandled()

	// Init sets the time to now, and any other initialization.
	// Done just prior to event Send.
	Init()

	// Clone returns a duplicate of this event with the basic event parameters
	// copied (specialized Event types have their own CloneX methods)
	// and the Handled flag is reset.  This is suitable for repurposing.
	Clone() Event

	// NewFromClone returns a duplicate of this event with the basic event parameters
	// copied, and type set to given type.  The resulting type is ready for sending.
	NewFromClone(typ Types) Event

	// SetTime sets the event time to Now
	SetTime()

	// IsSame returns true if the current event is the same as other.
	// Checks Type and, where relevant, Action.
	IsSame(oth Event) bool

	// MouseButton is the mouse button being pressed or released, for relevant events.
	MouseButton() Buttons

	// SelectMode returns the selection mode based on given modifiers on event
	SelectMode() SelectModes

	// Modifiers returns the modifier keys present at time of event
	Modifiers() key.Modifiers

	// HasAllModifiers tests whether all of given modifier(s) were set
	HasAllModifiers(mods ...enums.BitFlag) bool

	// HasAnyModifier testes whether any of the given modifiers were set
	HasAnyModifier(mods ...enums.BitFlag) bool

	// Rune is the meaning of the key event as determined by the
	// operating system. The mapping is determined by system-dependent
	// current layout, modifiers, lock-states, etc.
	KeyRune() rune

	// Code is the identity of the physical key relative to a notional
	// "standard" keyboard, independent of current layout, modifiers,
	// lock-states, etc
	//
	// For standard key codes, its value matches USB HID key codes.
	// Compare its value to uint32-typed constants in this package, such
	// as CodeLeftShift and CodeEscape.
	//
	// Pressing the regular '2' key and number-pad '2' key (with Num-Lock)
	// generate different Codes (but the same Rune).
	KeyCode() key.Codes

	// KeyChord returns a string representation of the keyboard event suitable for
	// keyboard function maps, etc. Printable runes are sent directly, and
	// non-printable ones are converted to their corresponding code names without
	// the "Code" prefix.
	KeyChord() key.Chord
}

Event is the interface for system GUI events. also includes Stringer to get a string description of the event

type EventFlags

type EventFlags int64 //enums:bitflag

EventFlags encode boolean event properties

const (
	// Handled indicates that the event has been handled
	Handled EventFlags = iota

	// EventUnique indicates that the event is Unique and not
	// to be compressed with like events.
	Unique
)
const EventFlagsN EventFlags = 2

EventFlagsN is the highest valid value for type EventFlags, plus one.

func EventFlagsValues

func EventFlagsValues() []EventFlags

EventFlagsValues returns all possible values for the type EventFlags.

func (EventFlags) BitIndexString

func (i EventFlags) BitIndexString() string

BitIndexString returns the string representation of this EventFlags value if it is a bit index value (typically an enum constant), and not an actual bit flag value.

func (EventFlags) Desc

func (i EventFlags) Desc() string

Desc returns the description of the EventFlags value.

func (EventFlags) HasFlag

func (i EventFlags) HasFlag(f enums.BitFlag) bool

HasFlag returns whether these bit flags have the given bit flag set.

func (EventFlags) Int64

func (i EventFlags) Int64() int64

Int64 returns the EventFlags value as an int64.

func (EventFlags) MarshalText

func (i EventFlags) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*EventFlags) SetFlag

func (i *EventFlags) SetFlag(on bool, f ...enums.BitFlag)

SetFlag sets the value of the given flags in these flags to the given value.

func (*EventFlags) SetInt64

func (i *EventFlags) SetInt64(in int64)

SetInt64 sets the EventFlags value from an int64.

func (*EventFlags) SetString

func (i *EventFlags) SetString(s string) error

SetString sets the EventFlags value from its string representation, and returns an error if the string is invalid.

func (*EventFlags) SetStringOr

func (i *EventFlags) SetStringOr(s string) error

SetStringOr sets the EventFlags value from its string representation while preserving any bit flags already set, and returns an error if the string is invalid.

func (EventFlags) String

func (i EventFlags) String() string

String returns the string representation of this EventFlags value.

func (*EventFlags) UnmarshalText

func (i *EventFlags) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (EventFlags) Values

func (i EventFlags) Values() []enums.Enum

Values returns all possible values for the type EventFlags.

type Key

type Key struct {
	Base
}

events.Key is a low-level immediately generated key event, tracking press and release of keys -- suitable for fine-grained tracking of key events -- see also events.Key for events that are generated only on key press, and that include the full chord information about all the modifier keys that were present when a non-modifier key was released

func NewKey

func NewKey(typ Types, rn rune, code key.Codes, mods key.Modifiers) *Key

func (*Key) HasPos

func (ev *Key) HasPos() bool

func (*Key) NeedsFocus

func (ev *Key) NeedsFocus() bool

func (*Key) String

func (ev *Key) String() string

type Listeners

type Listeners map[Types][]func(ev Event)

Listeners registers lists of event listener functions to receive different event types. Listeners are closure methods with all context captured. Functions are called in *reverse* order of when they are added: First In, Last Called, so that "base" functions are typically added first, and then can be overridden by later-added ones. Call SetHandled() on the event to stop further propagation.

func (*Listeners) Add

func (ls *Listeners) Add(typ Types, fun func(e Event))

Add adds a listener for the given type to the end of the current stack such that it will be called before everything else already on the stack.

func (*Listeners) Call

func (ls *Listeners) Call(ev Event, shouldContinue ...func() bool)

Call calls all functions for given event. It goes in reverse order so the last functions added are the first called and it stops when the event is marked as Handled. This allows for a natural and optional override behavior, as compared to requiring more complex priority-based mechanisms. Also, it takes an optional function that it calls before each event handler is run, returning if it returns false.

func (*Listeners) CopyFromExtra

func (ls *Listeners) CopyFromExtra(fr Listeners)

CopyFromExtra copies additional listeners from given source beyond those present in the receiver.

func (*Listeners) HandlesEventType added in v0.1.4

func (ls *Listeners) HandlesEventType(typ Types) bool

HandlesEventType returns true if this listener handles the given event type.

func (*Listeners) Init

func (ls *Listeners) Init()

Init ensures that the map is constructed.

type Mouse

type Mouse struct {
	Base
}

Mouse is a basic mouse event for all mouse events except Scroll

func NewMouse

func NewMouse(typ Types, but Buttons, where image.Point, mods key.Modifiers) *Mouse

func NewMouseDrag

func NewMouseDrag(but Buttons, where, prev, start image.Point, mods key.Modifiers) *Mouse

func NewMouseMove

func NewMouseMove(but Buttons, where, prev image.Point, mods key.Modifiers) *Mouse

func (Mouse) HasPos

func (ev Mouse) HasPos() bool

func (*Mouse) String

func (ev *Mouse) String() string

type MouseScroll

type MouseScroll struct {
	Mouse

	// Delta is the amount of scrolling in each axis
	Delta math32.Vector2
}

MouseScroll is for mouse scrolling, recording the delta of the scroll

func NewScroll

func NewScroll(where image.Point, delta math32.Vector2, mods key.Modifiers) *MouseScroll

func (*MouseScroll) String

func (ev *MouseScroll) String() string

type OSEvent

type OSEvent struct {
	Base
}

OSEvent reports an OS level event

func NewOSEvent

func NewOSEvent(typ Types) *OSEvent

func (*OSEvent) String

func (ev *OSEvent) String() string

type OSFiles

type OSFiles struct {
	OSEvent

	// Files are a list of files to open
	Files []string
}

osevent.OpenFilesEvent is for OS open files action to open given files

func NewOSFiles

func NewOSFiles(typ Types, files []string) *OSFiles

type SelectModes

type SelectModes int32 //enums:enum

SelectModes interprets the modifier keys to determine what type of selection mode to use. This is also used for selection actions and has modes not directly activated by modifier keys.

const (
	// SelectOne selects a single item, and is the default when no modifier key
	// is pressed
	SelectOne SelectModes = iota

	// ExtendContinuous, activated by Shift key, extends the selection to
	// select a continuous region of selected items, with no gaps
	ExtendContinuous

	// ExtendOne, activated by Control or Meta / Command, extends the
	// selection by adding the one additional item just clicked on, creating a
	// potentially discontinuous set of selected items
	ExtendOne

	// NoSelect means do not update selection -- this is used programmatically
	// and not available via modifier key
	NoSelect

	// Unselect means unselect items -- this is used programmatically
	// and not available via modifier key -- typically ExtendOne will
	// unselect if already selected
	Unselect

	// SelectQuiet means select without doing other updates or signals -- for
	// bulk updates with a final update at the end -- used programmatically
	SelectQuiet

	// UnselectQuiet means unselect without doing other updates or signals -- for
	// bulk updates with a final update at the end -- used programmatically
	UnselectQuiet
)
const SelectModesN SelectModes = 7

SelectModesN is the highest valid value for type SelectModes, plus one.

func SelectModeBits

func SelectModeBits(mods key.Modifiers) SelectModes

SelectModeBits returns the selection mode based on given modifiers bitflags

func SelectModesValues

func SelectModesValues() []SelectModes

SelectModesValues returns all possible values for the type SelectModes.

func (SelectModes) Desc

func (i SelectModes) Desc() string

Desc returns the description of the SelectModes value.

func (SelectModes) Int64

func (i SelectModes) Int64() int64

Int64 returns the SelectModes value as an int64.

func (SelectModes) MarshalText

func (i SelectModes) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*SelectModes) SetInt64

func (i *SelectModes) SetInt64(in int64)

SetInt64 sets the SelectModes value from an int64.

func (*SelectModes) SetString

func (i *SelectModes) SetString(s string) error

SetString sets the SelectModes value from its string representation, and returns an error if the string is invalid.

func (SelectModes) String

func (i SelectModes) String() string

String returns the string representation of this SelectModes value.

func (*SelectModes) UnmarshalText

func (i *SelectModes) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (SelectModes) Values

func (i SelectModes) Values() []enums.Enum

Values returns all possible values for the type SelectModes.

type Sequence

type Sequence int64

Sequence identifies a sequence of touch events.

type Source added in v0.1.1

type Source struct {
	// Deque is the event queue
	Deque Deque

	// flag for ignoring mouse events when disabling mouse movement
	ResettingPos bool

	// Last has the prior state for key variables
	Last SourceState

	// PaintCount is used for printing paint events as .
	PaintCount int
}

Source is a source of events that manages the event construction and sending process for its parent window. It caches state as needed to generate derived events such as MouseDrag.

func (*Source) Custom added in v0.1.1

func (es *Source) Custom(data any)

func (*Source) DropExternal added in v0.1.1

func (es *Source) DropExternal(where image.Point, md mimedata.Mimes)

DropExternal creates and sends a Drop event with given values

func (*Source) Key added in v0.1.1

func (es *Source) Key(typ Types, rn rune, code key.Codes, mods key.Modifiers)

SendKey processes a basic key event and sends it

func (*Source) KeyChord added in v0.1.1

func (es *Source) KeyChord(rn rune, code key.Codes, mods key.Modifiers)

KeyChord processes a basic KeyChord event and sends it

func (*Source) Magnify added in v0.1.1

func (es *Source) Magnify(scaleFactor float32, where image.Point)

Magnify creates and sends a TouchMagnify event with the given values.

func (*Source) MouseButton added in v0.1.1

func (es *Source) MouseButton(typ Types, but Buttons, where image.Point, mods key.Modifiers)

MouseButton creates and sends a mouse button event with given values

func (*Source) MouseMove added in v0.1.1

func (es *Source) MouseMove(where image.Point)

MouseMove creates and sends a mouse move or drag event with given values

func (*Source) Scroll added in v0.1.1

func (es *Source) Scroll(where image.Point, delta math32.Vector2)

Scroll creates and sends a scroll event with given values

func (*Source) Touch added in v0.1.1

func (es *Source) Touch(typ Types, seq Sequence, where image.Point)

Touch creates and sends a touch event with the given values. It also creates and sends a corresponding mouse event.

func (*Source) Window added in v0.1.1

func (es *Source) Window(act WinActions)

func (*Source) WindowPaint added in v0.1.1

func (es *Source) WindowPaint()

func (*Source) WindowResize added in v0.1.1

func (es *Source) WindowResize()

type SourceState added in v0.1.1

type SourceState struct {
	// last mouse button event type (down or up)
	MouseButtonType Types

	// last mouse button
	MouseButton Buttons

	// time of MouseDown
	MouseDownTime nptime.Time

	// position at MouseDown
	MouseDownPos image.Point

	// position of mouse from move events
	MousePos image.Point

	// time of last move
	MouseMoveTime nptime.Time

	// keyboard modifiers (Shift, Alt, etc)
	Mods key.Modifiers

	// Key event code
	Key key.Codes
}

SourceState tracks basic event state over time to enable recognition and full data for generating events.

type Touch

type Touch struct {
	Base

	// Sequence is the sequence number. The same number is shared by all events
	// in a sequence. A sequence begins with a single Begin, is followed by
	// zero or more Moves, and ends with a single End. A Sequence
	// distinguishes concurrent sequences but its value is subsequently reused.
	Sequence Sequence
}

Touch is a touch event.

func NewTouch

func NewTouch(typ Types, seq Sequence, where image.Point) *Touch

NewTouch creates a new touch event from the given values.

func (*Touch) HasPos

func (ev *Touch) HasPos() bool

func (*Touch) String

func (ev *Touch) String() string

type TouchMagnify

type TouchMagnify struct {
	Touch
	// the multiplicative scale factor relative to the previous
	// zoom of the screen
	ScaleFactor float32
}

TouchMagnify is a touch magnification (scaling) gesture event. It is the event struct corresponding to events of type Magnify.

func NewMagnify

func NewMagnify(scaleFactor float32, where image.Point) *TouchMagnify

NewMagnify creates a new TouchMagnify event based on the given multiplicative scale factor.

type Types

type Types int32 //enums:enum

Types determines the type of GUI event, and also the level at which one can select which events to listen to. The type should include both the source / nature of the event and the "action" type of the event (e.g., MouseDown, MouseUp are separate event types). The standard [JavaScript Event](https://developer.mozilla.org/en-US/docs/Web/Events) provide the basis for most of the event type names and categories. Most events use the same Base type and only need to set relevant fields and the type. Unless otherwise noted, all events are marked as Unique, meaning they are always sent. Non-Unique events are subject to compression, where if the last event added (and not yet processed and therefore removed from the queue) is of the same type then it is replaced with the new one, instead of adding.

const (
	// zero value is an unknown type
	UnknownType Types = iota

	// MouseDown happens when a mouse button is pressed down.
	// See MouseButton() for which.
	// See Click for a synthetic event representing a MouseDown
	// followed by MouseUp on the same element with Left (primary)
	// mouse button. Often that is the most useful.
	MouseDown

	// MouseUp happens when a mouse button is released.
	// See MouseButton() for which.
	MouseUp

	// MouseMove is always sent when the mouse is moving but no
	// button is down, even if there might be other higher-level events too.
	// These can be numerous and thus it is typically more efficient
	// to listen to other events derived from this.
	// Not unique, and Prev position is updated during compression.
	MouseMove

	// MouseDrag is always sent when the mouse is moving and there
	// is a button down, even if there might be other higher-level
	// events too.
	// The start pos indicates where (and when) button first was pressed.
	// Not unique and Prev position is updated during compression.
	MouseDrag

	// Click represents a MouseDown followed by MouseUp
	// in sequence on the same element, with the Left (primary) button.
	// This is the typical event for most basic user interaction.
	Click

	// DoubleClick represents two Click events in a row in rapid
	// succession.
	DoubleClick

	// TripleClick represents three Click events in a row in rapid
	// succession.
	TripleClick

	// ContextMenu represents a MouseDown/Up event with the
	// Right mouse button (which is also activated by
	// Control key + Left Click).
	ContextMenu

	// LongPressStart is when the mouse has been relatively stable
	// after MouseDown on an element for a minimum duration (500 msec default).
	LongPressStart

	// LongPressEnd is sent after LongPressStart when the mouse has
	// gone up, moved sufficiently, left the current element,
	// or another input event has happened.
	LongPressEnd

	// MouseEnter is when the mouse enters the bounding box
	// of a new element.  It is used for setting the Hover state,
	// and can trigger cursor changes.
	// See DragEnter for alternative case during Drag events.
	MouseEnter

	// MouseLeave is when the mouse leaves the bounding box
	// of an element, that previously had a MouseEnter event.
	// Given that elements can have overlapping bounding boxes
	// (e.g., child elements within a container), it is not the case
	// that a MouseEnter on a child triggers a MouseLeave on
	// surrounding containers.
	// See DragLeave for alternative case during Drag events.
	MouseLeave

	// LongHoverStart is when the mouse has been relatively stable
	// after MouseEnter on an element for a minimum duration
	// (500 msec default).
	// This triggers the LongHover state typically used for Tooltips.
	LongHoverStart

	// LongHoverEnd is after LongHoverStart when the mouse has
	// moved sufficiently, left the current element,
	// or another input event has happened,
	// thereby terminating the LongHover state.
	LongHoverEnd

	// DragStart is at the start of a drag-n-drop event sequence, when
	// a Draggable element is Active and a sufficient distance of
	// MouseDrag events has occurred to engage the DragStart event.
	DragStart

	// DragMove is for a MouseDrag event during the drag-n-drop sequence.
	// Usually don't need to listen to this one.  MouseDrag is also sent.
	DragMove

	// DragEnter is like MouseEnter but after a DragStart during a
	// drag-n-drop sequence.  MouseEnter is not sent in this case.
	DragEnter

	// DragLeave is like MouseLeave but after a DragStart during a
	// drag-n-drop sequence.  MouseLeave is not sent in this case.
	DragLeave

	// Drop is sent when an item being Dragged is dropped on top of a
	// target element. The event struct should be DragDrop.
	Drop

	// DropDeleteSource is sent to the source Drag element if the
	// Drag-n-Drop event is a Move type, which requires deleting
	// the source element.  The event struct should be DragDrop.
	DropDeleteSource

	// SlideStart is for a Slideable element when Active and a
	// sufficient distance of MouseDrag events has occurred to
	// engage the SlideStart event.  Sets the Sliding state.
	SlideStart

	// SlideMove is for a Slideable element after SlideStart
	// is being dragged via MouseDrag events.
	SlideMove

	// SlideStop is when the mouse button is released on a Slideable
	// element being dragged via MouseDrag events.  This typically
	// also accompanied by a Changed event for the new slider value.
	SlideStop

	// Scroll is for scroll wheel or other scrolling events (gestures).
	// These are not unique and Delta is updated during compression.
	Scroll

	// KeyDown is when a key is pressed down.
	// This provides fine-grained data about each key as it happens.
	// KeyChord is recommended for a more complete Key event.
	KeyDown

	// KeyUp is when a key is released.
	// This provides fine-grained data about each key as it happens.
	// KeyChord is recommended for a more complete Key event.
	KeyUp

	// KeyChord is only generated when a non-modifier key is released,
	// and it also contains a string representation of the full chord,
	// suitable for translation into keyboard commands, emacs-style etc.
	// It can be somewhat delayed relative to the KeyUp.
	KeyChord

	// TouchStart is when a touch event starts, for the low-level touch
	// event processing.  TouchStart also activates MouseDown, Scroll,
	// Magnify, or Rotate events depending on gesture recognition.
	TouchStart

	// TouchEnd is when a touch event ends, for the low-level touch
	// event processing.  TouchEnd also activates MouseUp events
	// depending on gesture recognition.
	TouchEnd

	// TouchMove is when a touch event moves, for the low-level touch
	// event processing.  TouchMove also activates MouseMove, Scroll,
	// Magnify, or Rotate events depending on gesture recognition.
	TouchMove

	// Magnify is a touch-based magnify event (e.g., pinch)
	Magnify

	// Rotate is a touch-based rotate event.
	Rotate

	// Select is sent for any direction of selection change
	// on (or within if relevant) a Selectable element.
	// Typically need to query the element(s) to determine current
	// selection state.
	Select

	// Focus is sent when Focsable element receives Focus
	Focus

	// FocusLost is sent when Focsable element loses Focus
	FocusLost

	// Change is when a value represented by the element has been changed
	// by the user and committed (for example, someone has typed text in a
	// textfield and then pressed enter). This is *not* triggered when
	// the value has not been committed; see [Input] for that.
	// This is for Editable, Checkable, and Slidable items.
	Change

	// Input is when a value represented by the element has changed, but
	// has not necessarily been committed (for example, this triggers each
	// time someone presses a key in a text field). This *is* triggered when
	// the value has not been committed; see [Change] for a version that only
	// occurs when the value is committed.
	// This is for Editable, Checkable, and Slidable items.
	Input

	// Show is sent to widgets when their Scene is first shown to the user
	// in its final form. Listening to this event enables widgets to perform
	// initial one-time activities on startup, in the context of a fully
	// rendered display. This is guaranteed to only happen once per widget
	// per Scene.
	Show

	// Close is sent to widgets when their Scene is being closed. This is an
	// opportunity to save unsaved edits, for example. This is guaranteed to
	// only happen once per widget per Scene.
	Close

	// Window reports on changes in the window position,
	// visibility (iconify), focus changes, screen update, and closing.
	// These are only sent once per event (Unique).
	Window

	// WindowResize happens when the window has been resized,
	// which can happen continuously during a user resizing
	// episode.  These are not Unique events, and are compressed
	// to minimize lag.
	WindowResize

	// WindowPaint is sent continuously at FPS frequency
	// (60 frames per second by default) to drive updating check
	// on the window.  It is not unique, will be compressed
	// to keep pace with updating.
	WindowPaint

	// OS is an operating system generated event (app level typically)
	OS

	// OSOpenFiles is an event telling app to open given files
	OSOpenFiles

	// Custom is a user-defined event with a data any field
	Custom
)
const TypesN Types = 46

TypesN is the highest valid value for type Types, plus one.

func TypesValues

func TypesValues() []Types

TypesValues returns all possible values for the type Types.

func (Types) Desc

func (i Types) Desc() string

Desc returns the description of the Types value.

func (Types) Int64

func (i Types) Int64() int64

Int64 returns the Types value as an int64.

func (Types) IsDrag

func (tp Types) IsDrag() bool

IsDrag returns true if event type is a Drag type

func (Types) IsKey

func (tp Types) IsKey() bool

IsKey returns true if event type is a Key type

func (Types) IsMouse

func (tp Types) IsMouse() bool

IsMouse returns true if event type is a Mouse type

func (Types) IsSlide

func (tp Types) IsSlide() bool

IsSlide returns true if event type is a Slide type

func (Types) IsTouch

func (tp Types) IsTouch() bool

IsTouch returns true if event type is a Touch type

func (Types) IsWindow

func (tp Types) IsWindow() bool

IsWindow returns true if event type is a Window type

func (Types) MarshalText

func (i Types) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*Types) SetInt64

func (i *Types) SetInt64(in int64)

SetInt64 sets the Types value from an int64.

func (*Types) SetString

func (i *Types) SetString(s string) error

SetString sets the Types value from its string representation, and returns an error if the string is invalid.

func (Types) String

func (i Types) String() string

String returns the string representation of this Types value.

func (*Types) UnmarshalText

func (i *Types) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (Types) Values

func (i Types) Values() []enums.Enum

Values returns all possible values for the type Types.

type WinActions

type WinActions int32 //enums:enum -trim-prefix Win

WinActions is the action taken on the window by the user.

const (
	// NoWinAction is the zero value for special types (Resize, Paint)
	NoWinAction WinActions = iota

	// WinClose means that the window is about to close, but has not yet closed.
	WinClose

	// WinMinimize means that the window has been iconified / miniaturized / is no
	// longer visible.
	WinMinimize

	// WinMove means that the window was moved but NOT resized or changed in any
	// other way -- does not require a redraw, but anything tracking positions
	// will want to update.
	WinMove

	// WinFocus indicates that the window has been activated for receiving user
	// input.
	WinFocus

	// WinFocusLost indicates that the window is no longer activated for
	// receiving input.
	WinFocusLost

	// WinShow is for the WindowShow event -- sent by the system shortly
	// after the window has opened, to ensure that full rendering
	// is completed with the proper size, and to trigger one-time actions such as
	// configuring the main menu after the window has opened.
	WinShow

	// ScreenUpdate occurs when any of the screen information is updated
	// This event is sent to the first window on the list of active windows
	// and it should then perform any necessary updating
	ScreenUpdate
)
const WinActionsN WinActions = 8

WinActionsN is the highest valid value for type WinActions, plus one.

func WinActionsValues

func WinActionsValues() []WinActions

WinActionsValues returns all possible values for the type WinActions.

func (WinActions) Desc

func (i WinActions) Desc() string

Desc returns the description of the WinActions value.

func (WinActions) Int64

func (i WinActions) Int64() int64

Int64 returns the WinActions value as an int64.

func (WinActions) MarshalText

func (i WinActions) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface.

func (*WinActions) SetInt64

func (i *WinActions) SetInt64(in int64)

SetInt64 sets the WinActions value from an int64.

func (*WinActions) SetString

func (i *WinActions) SetString(s string) error

SetString sets the WinActions value from its string representation, and returns an error if the string is invalid.

func (WinActions) String

func (i WinActions) String() string

String returns the string representation of this WinActions value.

func (*WinActions) UnmarshalText

func (i *WinActions) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface.

func (WinActions) Values

func (i WinActions) Values() []enums.Enum

Values returns all possible values for the type WinActions.

type WindowEvent

type WindowEvent struct {
	Base

	// Action taken on the window -- what has changed.
	// Window state fields have current values.
	Action WinActions
}

WindowEvent reports on actions taken on a window. The system.Window Flags and other state information will always be updated prior to this event being sent, so those should be consulted directly for the new current state.

func NewWindow

func NewWindow(act WinActions) *WindowEvent

func NewWindowPaint

func NewWindowPaint() *WindowEvent

func NewWindowResize

func NewWindowResize() *WindowEvent

func (*WindowEvent) HasPos

func (ev *WindowEvent) HasPos() bool

func (*WindowEvent) String

func (ev *WindowEvent) String() string

Directories

Path Synopsis
Package key defines an event for physical keyboard keys, for the Cogent Core GUI system.
Package key defines an event for physical keyboard keys, for the Cogent Core GUI system.

Jump to

Keyboard shortcuts

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