hit

package
v1.9.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package hit provides compositor-based mouse hit-testing for the TUI's pages and dialogs. Each clickable region is a lipgloss v2 Layer with an ID placed at its drawn location; lipgloss.Compositor.Hit resolves a point to the top-most region and its bounds, from which a handler derives the in-region offset. This replaces the hand-rolled point-in-rectangle geometry the pages used to keep in sync with the renderer, so a mouse coordinate is hit-tested against the layers once rather than double-managed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Region

func Region(id string, x, y, w, h int) *lipgloss.Layer

Region builds an ID'd layer sized w×h at (x, y). The content is a blank block of exactly that size; only its bounds matter to Compositor.Hit. Width/height below one are clamped to one so a degenerate region still has a hit cell.

Types

type Map

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

Map wraps a lipgloss.Compositor of ID'd region layers. A nil Map (or one built with no regions) simply never hits, so callers need not guard for a page that has not rendered yet.

func New

func New(regions ...*lipgloss.Layer) *Map

New builds a Map from region layers (typically produced by Region). Regions may overlap: a higher Z region wins the hit, so a sub-region (e.g. a history band inside a detail pane) is placed above the pane it sits in.

func (*Map) At

func (m *Map) At(x, y int) (id string, dx, dy int, ok bool)

At hit-tests (x, y) against the map. It returns the ID of the top-most region containing the point and the point's offset within that region (dx, dy from the region's top-left), or ok=false when no region is hit.

func (*Map) Origin

func (m *Map) Origin(id string) (x, y int, ok bool)

Origin returns the top-left (x, y) of the region with the given ID, or ok=false when there is no such region. It lets a test derive a click coordinate from the drawn layout instead of hard-coding one.

Jump to

Keyboard shortcuts

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