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
- type ActionType
- type ClickResult
- type Handler
- func (h *Handler) Clear()
- func (h *Handler) DragDelta(x, y int) (dx, dy int)
- func (h *Handler) DragRegion() string
- func (h *Handler) DragStartValue() int
- func (h *Handler) EndDrag()
- func (h *Handler) HandleClick(x, y int) ClickResult
- func (h *Handler) HandleMouse(msg tea.MouseMsg) MouseAction
- func (h *Handler) IsDragging() bool
- func (h *Handler) StartDrag(x, y int, regionID string, startValue int)
- type HitMap
- type MouseAction
- type Rect
- type Region
Constants ¶
const WheelScrollLines = 3
WheelScrollLines is how many lines one physical wheel notch scrolls. Vertical wheel actions report Delta in lines, not notches, so a consumer that needs the notch count — anything translating back into wheel events, such as forwarding to a terminal application — has to divide by this.
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 ActionTripleClick ActionScrollUp ActionScrollDown ActionScrollLeft // Shift+scroll up = scroll left ActionScrollRight // Shift+scroll down = scroll right ActionDrag ActionDragEnd ActionHover )
type ClickResult ¶
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 (*Handler) Clear ¶
func (h *Handler) Clear()
Clear resets the handler state and clears the hit map.
func (*Handler) DragRegion ¶
DragRegion returns the ID of the region the in-progress drag STARTED in (the drag source), not the region currently under the cursor. It is empty once EndDrag has run; consumers that need the source at drag-end time should read MouseAction.DragStartID, which survives the reset.
func (*Handler) DragStartValue ¶
DragStartValue returns the initial value when the drag started.
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 ¶
IsDragging returns true if a drag operation is in progress.
type HitMap ¶
type HitMap struct {
// contains filtered or unexported fields
}
HitMap tracks hit regions for mouse click detection.
type MouseAction ¶
type MouseAction struct {
Type ActionType
Region *Region
X, Y int
// Delta is the scroll amount in lines for vertical wheel actions and in
// columns for horizontal ones. See WheelScrollLines to recover notches.
Delta int
DragDX int // Drag delta X
DragDY int // Drag delta Y
// DragStartID is the ID of the region the drag started in, for
// ActionDrag/ActionDragEnd. Region, for those two actions, is the region
// currently under the cursor (the drop target), which is usually a
// different region entirely.
DragStartID string
Shift bool
Alt bool
}
MouseAction represents a processed mouse event.