button

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package button implements a state machine that tracks mouse button clicks.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FSM

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

FSM implements a finite-state machine that tracks mouse clicks within an area.

Simplifies tracking of mouse button clicks, i.e. when the caller wants to perform an action only if both the button press and release happen within the specified area.

This object is not thread-safe.

func NewFSM

func NewFSM(button mouse.Button, area image.Rectangle) *FSM

NewFSM creates a new FSM instance that tracks the state of the specified mouse button through button events that fall within the provided area.

func (*FSM) Event

func (fsm *FSM) Event(m *terminalapi.Mouse) (bool, State)

Event is used to forward mouse events to the state machine. Only events related to the button specified on a call to NewFSM are processed.

Returns a bool indicating if an action guarded by the button should be performed and the state of the button after the provided event. The bool is true if the button click should take an effect, i.e. if the FSM saw both the button click and its release.

func (*FSM) UpdateArea

func (fsm *FSM) UpdateArea(area image.Rectangle)

UpdateArea informs FSM of an area change. This method is idempotent.

type State

type State int

State represents the state of the mouse button.

const (
	// Up is the default idle state of the mouse button.
	Up State = iota

	// Down is a state where the mouse button is pressed down and held.
	Down
)

func (State) String

func (s State) String() string

String implements fmt.Stringer()

Jump to

Keyboard shortcuts

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