mouse

package
v0.0.0-...-b5b2f04 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: Apache-2.0 Imports: 3 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClickEventType = events.NewType("Click")
View Source
var MouseEventType = events.NewType("Mouse")
View Source
var PressEventType = events.NewType("MousePress")
View Source
var ScrollEventType = events.NewType("Scroll")
View Source
var UpEventType = events.NewType("MouseUp")

Functions

func ClickListener

func ClickListener(handler func(ClickEvent)) (events.Type, events.Handler)

ClickListener returns an events.Listener that will call the given handler on click events.

func EventListener

func EventListener(handler func(Event)) (events.Type, events.Handler)

EventListener returns an events.Listener that will call the given handler on mouse events.

func PressListener

func PressListener(handler func(Event)) (events.Type, events.Handler)

PressListener returns an events.Listener that will call the given handler on mouse press events.

func ScrollListener

func ScrollListener(handler func(ev ScrollEvent)) (events.Type, events.Handler)

func UpListener

func UpListener(handler func(Event)) (events.Type, events.Handler)

UpListener returns an events.Listener that will call the given handler on mouse up events.

Types

type ButtonMask

type ButtonMask int16

ButtonMask is a mask of mouse buttons and wheel events. Mouse button presses are normally delivered as both press and release events. Mouse wheel events are normally just single impulse events. Windows supports up to eight separate buttons, but XTerm can only support mouse buttons 1-3. Its not unheard of for terminals to support only one or two buttons (think Macs). Old terminals, and true emulations (such as vt100) won't support mice at all, of course.

const (
	Button1 ButtonMask = 1 << iota // Usually the left (primary) mouse button.
	Button2                        // Usually the right (secondary) mouse button.
	Button3                        // Usually the middle mouse button.
	Button4                        // Often a side button (thumb/next).
	Button5                        // Often a side button (thumb/prev).
	Button6
	Button7
	Button8
	ButtonNone ButtonMask = 0 // No button.

	ButtonPrimary   = Button1
	ButtonSecondary = Button2
	ButtonMiddle    = Button3
)

These are the actual button values. Note that tcell version 1.x reversed buttons two and three on *nix based terminals. We use button 1 as the primary, and button 2 as the secondary, and button 3 (which is often missing) as the middle.

type ClickEvent

type ClickEvent struct {
	Event
	MousePress Event
}

ClickEvent define an event triggered by a primary mouse click, that is a mouse press followed by a mouse up (positions can differ). Unlike mouse up event, click events is dispatched to target at mouse press position.

func NewClick

func NewClick(pos geometry.Vec2D, buttons ButtonMask, mods keypress.ModMask, mousePress Event) ClickEvent

NewClick returns a new click event.

type Event

type Event struct {
	events.Event
	// Mouse absolute position.
	AbsPosition geometry.Vec2D
	// Position relative to element position.
	RelPosition geometry.Vec2D
	// List of buttons that were pressed.
	Buttons ButtonMask
	// Modifiers is the modifiers that were present with the key press. Note
	// that not all platforms and terminals support this equally well, and some
	// cases we will not not know for sure. Hence, applications should avoid
	// using this in most circumstances.
	Modifiers keypress.ModMask
}

Event is a generic mouse event. A mouse event can be of events.Type:

* MousePress

* MouseUp

func NewEvent

func NewEvent(pos geometry.Vec2D, buttons ButtonMask, mods keypress.ModMask) Event

NewEvent returns a new mouse event.

func NewPress

func NewPress(pos geometry.Vec2D, buttons ButtonMask, mods keypress.ModMask) Event

NewPress returns a new mouse press event.

func NewUp

func NewUp(pos geometry.Vec2D, buttons ButtonMask, mods keypress.ModMask) Event

NewUp returns a new mouse up event.

type ScrollDirection

type ScrollDirection int8
const (
	ScrollUp ScrollDirection = iota
	ScrollDown
	ScrollLeft
	ScrollRight
)

type ScrollEvent

type ScrollEvent struct {
	Event
	ScrollDirection
}

ScrollEvent is a mouse event triggered on mouse scroll. It supports horizontal and vertical scroll.

func NewScroll

func NewScroll(pos geometry.Vec2D, modifiers keypress.ModMask, direction ScrollDirection) ScrollEvent

func (ScrollEvent) Horizontal

func (se ScrollEvent) Horizontal() bool

func (ScrollEvent) Vertical

func (se ScrollEvent) Vertical() bool

Jump to

Keyboard shortcuts

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