mechuievent

package
v0.0.0-...-a3e6692 Latest Latest
Warning

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

Go to latest
Published: May 14, 2024 License: CC0-1.0 Imports: 14 Imported by: 0

Documentation

Overview

Package mechuievent collects certain UI events from clients such as keyboard key events, mouse move events, and ShutterbugPixels' overlayer clicks. The semantic meaning of these kinds of events is not known by the client and is determined by the server.

Events from sidebar buttons and sidebar popup panels are dealt with by a different package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEventHandleFunc

func NewEventHandleFunc(
	clr *Collector,
	shutterbugs mechshutterbug.Containser,
) http.HandlerFunc

NewEventHandleFunc creates a HTTP request handler which allows clients to interface with the collector.

The handler upgrades the HTTP request to a websocket and accepts UI events, one per websocket message. The websocket's first ever message should be a valid shutterbug.

Types

type ButtonClick

type ButtonClick struct {
	MechaneButtonEvent
	Shutterbug string
}

ButtonClick event on a mechane-button element from an input source associated with a particular shutterbug.

type ButtonClicks

type ButtonClicks struct {
	*dryad.SyncAwaitSeq[ButtonClick]
}

ButtonClicks is a sequence of click events coming from Mechane buttons.

func NewButtonClicks

func NewButtonClicks() ButtonClicks

NewButtonClicks constructs a new ButtonClicks.

func (ButtonClicks) Extract

func (seq ButtonClicks) Extract(fresh Collections, all Collections)

Extract the Mechane button click events from the given fresh collections.

Of the filtered click events, append those that pass temporal hysteresis checks to the receiver sequence in order from oldest to most recent.

The all collection shall contain and be a superset of the fresh collection.

type Collection

type Collection struct {
	Events     []Event // UI events ordered by time, that is from oldest to youngest.
	Shutterbug string  // The target shutterbug of the UI events.
}

A Collection of ordered UI events from one source.

func (Collection) Copy

func (col Collection) Copy() Collection

Copy the collection.

The slice of events is independent but the events themselves are the same.

type Collections

type Collections map[string]Collection

Collections is a snapshot of the UI events collected in a collector at a particular instant.

Map keys are UI event input sources.

func (Collections) ClearShutterbug

func (cols Collections) ClearShutterbug(shutterbug string)

ClearShutterbug deletes the sources associated with the given shutterbug.

func (Collections) Fresh

func (cols Collections) Fresh(old Collections) Collections

Fresh collected events present in the receiver collections which are not present in the argument older collections.

func (Collections) Sources

func (cols Collections) Sources() dryad.Set[string]

Sources is a set containing all the UI event input sources in the collections.

type Collector

type Collector struct {
	Logger *log.Logger
	// contains filtered or unexported fields
}

A Collector of UI events from various sources.

func NewCollector

func NewCollector(l *log.Logger) *Collector

NewCollector constructs a new Collector.

func (*Collector) ClearShutterbug

func (clr *Collector) ClearShutterbug(shutterbug string) dryad.Set[string]

ClearShutterbug UI events for the given shutterbug and return the sources whose events were cleared.

func (*Collector) Close

func (clr *Collector) Close(reason string)

Close the collector disconnecting and deleting all current sources and rejecting any future attempts to add a new source.

func (*Collector) Collections

func (clr *Collector) Collections() Collections

Collections of the collector.

Map keys are UI event input sources.

func (*Collector) RemoveShutterbug

func (clr *Collector) RemoveShutterbug(shutterbug, reason string)

RemoveShutterbug from the collector and close the associated HTTP request handlers using that shutterbug.

The given reason is sent to clients as the close reason message.

func (*Collector) RemoveSource

func (clr *Collector) RemoveSource(src string, reason string)

RemoveSource from the collector and close the associated HTTP request handler.

The given reason is sent to the client as the close reason message.

func (*Collector) Sources

func (clr *Collector) Sources() dryad.Set[string]

Sources is a set containing all the UI event input sources in the collector.

type Event

type Event struct {
	E interface{} // The keyboard, mouse move, mouse button, and so on UI event.
	T time.Time   // The UTC time of addition to the collection.
}

An Event collected at a certain time.

func (Event) String

func (e Event) String() string

type InOrderEvent

type InOrderEvent[E any] struct {
	E          E
	Shutterbug string
}

type KeyboardEvent

type KeyboardEvent struct {
	AltKey      bool
	CtrlKey     bool
	IsComposing bool
	Key         string // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
	KeyDown     bool   // True for a key down event.
	MetaKey     bool
	Pressed     []string // All the pressed keyboard keys (logically not physically).
	Repeat      bool
	ShiftKey    bool
}

A KeyboardEvent from a keyboard.

func (KeyboardEvent) Modified

func (e KeyboardEvent) Modified() bool

Modified reports whether any modifier key was pressed when the event was created.

type MechaneButtonEvent

type MechaneButtonEvent struct {
	AltKey           bool
	Button           float64
	ClientX, ClientY float64
	CtrlKey          bool
	Detail           int
	EffectName       string
	MetaKey          bool
	ShiftKey         bool
	WindowW, WindowH float64
}

A MechaneButtonEvent from an overlay element.

func (MechaneButtonEvent) Modified

func (e MechaneButtonEvent) Modified() bool

Modified reports whether any modifier key was pressed when the event was created.

type MechaneTextfieldKeyUpOrDownEvent

type MechaneTextfieldKeyUpOrDownEvent struct {
	AltKey      bool
	CtrlKey     bool
	EffectName  string
	IsComposing bool
	Key         string // https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
	KeyDown     bool
	MetaKey     bool
	ShiftKey    bool
	Value       string
}

A MechaneTextfieldKeyUpOrDownEvent from an overlay element.

func (MechaneTextfieldKeyUpOrDownEvent) Modified

Modified reports whether any modifier key was pressed when the event was created.

type MouseButtonEvent

A MouseButtonEvent from a mouse is a mousedown or mouseup event.

func (MouseButtonEvent) Modified

func (e MouseButtonEvent) Modified() bool

Modified reports whether any modifier key was pressed when the event was created.

type MouseMoveEvent

type MouseMoveEvent struct {
	ActiveEditable       bool // True if the hover is on a focused text editing area or similar.
	AltKey               bool
	Buttons              float64 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/buttons
	ClientX, ClientY     float64 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX
	CtrlKey              bool
	MetaKey              bool
	MovementX, MovementY float64 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/movementX
	// The dynamic dimensions of the canvas element/view area, inclusive of
	// scaling, in units of pixels.
	PixelsW, PixelsH             float64
	PixelsOffsetX, PixelsOffsetY float64 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/offsetX
	PointerLock                  bool
	ShiftKey                     bool
	WindowW, WindowH             float64
}

A MouseMoveEvent from a mouse.

func (MouseMoveEvent) Modified

func (e MouseMoveEvent) Modified() bool

Modified reports whether any modifier key was pressed when the event was created.

type MouseWheelEvent

type MouseWheelEvent struct {
	AltKey           bool
	ClientX, ClientY float64 // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent/clientX
	CtrlKey          bool
	DeltaX, DeltaY   float64 // https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event#event_properties
	EffectName       string
	MetaKey          bool
	ShiftKey         bool
	WindowW, WindowH float64
}

A MouseWheelEvent from a mouse wheel.

https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event

type TextfieldKeys

TextfieldKeys is a sequence of key events coming from Mechane textfields.

func NewTextfieldKeys

func NewTextfieldKeys() TextfieldKeys

NewTextfieldKeys constructs a new TextfieldKeys.

func (TextfieldKeys) Extract

func (seq TextfieldKeys) Extract(fresh Collections)

Extract the Mechane textfield key events from the given fresh collections and append them to the receiver sequence in order from oldest to most recent.

type WheelMoves

type WheelMoves struct {
	*dryad.SyncAwaitSeq[InOrderEvent[MouseWheelEvent]]
}

WheelMoves is a sequence of wheel move events.

func NewWheelMoves

func NewWheelMoves() WheelMoves

NewWheelMoves constructs a new WheelMoves.

func (WheelMoves) Extract

func (seq WheelMoves) Extract(fresh Collections)

Extract the Mechane mouse wheel move events from the given fresh collections and append them to the receiver sequence in order from oldest to most recent.

Jump to

Keyboard shortcuts

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