mouse

package
v0.74.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package mouse provides mouse interaction infrastructure with hit region testing, click/double-click detection, drag tracking, and scroll event handling for TUI components.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionType

type ActionType int

ActionType represents the type of mouse action detected.

const (
	ActionNone ActionType = iota
	ActionClick
	ActionDoubleClick
	ActionScrollUp
	ActionScrollDown
	ActionScrollLeft  // Shift+scroll up = scroll left
	ActionScrollRight // Shift+scroll down = scroll right
	ActionDrag
	ActionDragEnd
	ActionHover
)

type ClickResult

type ClickResult struct {
	Region        *Region
	IsDoubleClick bool
}

ClickResult represents the result of processing a click event.

type Handler

type Handler struct {
	HitMap *HitMap
	// contains filtered or unexported fields
}

Handler combines a HitMap with mouse state tracking for drag and double-click detection.

func NewHandler

func NewHandler() *Handler

NewHandler creates a new mouse handler.

func (*Handler) Clear

func (h *Handler) Clear()

Clear resets the handler state and clears the hit map.

func (*Handler) DragDelta

func (h *Handler) DragDelta(x, y int) (dx, dy int)

DragDelta returns the X and Y movement since drag started.

func (*Handler) DragRegion

func (h *Handler) DragRegion() string

DragRegion returns the region ID being dragged.

func (*Handler) DragStartValue

func (h *Handler) DragStartValue() int

DragStartValue returns the initial value when the drag started.

func (*Handler) EndDrag

func (h *Handler) EndDrag()

EndDrag stops tracking the drag operation.

func (*Handler) HandleClick

func (h *Handler) HandleClick(x, y int) ClickResult

HandleClick processes a mouse click and returns the hit region. Tracks click timing for double-click detection.

func (*Handler) HandleMouse

func (h *Handler) HandleMouse(msg tea.MouseMsg) MouseAction

HandleMouse is a convenience method for processing tea.MouseMsg events. Returns the action to take based on the mouse event.

func (*Handler) IsDragging

func (h *Handler) IsDragging() bool

IsDragging returns true if a drag operation is in progress.

func (*Handler) StartDrag

func (h *Handler) StartDrag(x, y int, regionID string, startValue int)

StartDrag begins tracking a drag operation.

type HitMap

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

HitMap tracks hit regions for mouse click detection.

func NewHitMap

func NewHitMap() *HitMap

NewHitMap creates a new empty HitMap.

func (*HitMap) Add

func (h *HitMap) Add(id string, rect Rect, data any)

Add adds a new region to the hit map.

func (*HitMap) AddRect

func (h *HitMap) AddRect(id string, x, y, w, height int, data any)

AddRect adds a region using individual coordinates.

func (*HitMap) Clear

func (h *HitMap) Clear()

Clear removes all regions from the hit map.

func (*HitMap) Regions

func (h *HitMap) Regions() []Region

Regions returns a copy of all registered regions (for testing).

func (*HitMap) Test

func (h *HitMap) Test(x, y int) *Region

Test returns the first region containing the point, or nil if none.

type MouseAction

type MouseAction struct {
	Type   ActionType
	Region *Region
	X, Y   int
	Delta  int // Scroll delta
	DragDX int // Drag delta X
	DragDY int // Drag delta Y
}

MouseAction represents a processed mouse event.

type Rect

type Rect struct {
	X, Y, W, H int
}

Rect represents a rectangular region.

func (Rect) Contains

func (r Rect) Contains(x, y int) bool

Contains returns true if the point (x, y) is within the rectangle.

type Region

type Region struct {
	ID   string
	Rect Rect
	Data any
}

Region is a named rectangular hit region with associated data.

Jump to

Keyboard shortcuts

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