Documentation
¶
Overview ¶
Package viewport provides item-aware scrolling over a list of variable-height items separated by gaps.
It is pure math — no rendering, no external dependencies. The consumer provides item heights and gap sizes as int slices, and the viewport handles scroll position, focus tracking, hit testing, and bottom detection.
Index ¶
- type Model
- func (m *Model) AtBottom() bool
- func (m *Model) FocusIdx() int
- func (m *Model) FocusNext()
- func (m *Model) FocusPrev()
- func (m *Model) ItemAtY(y int) (idx, localY int)
- func (m *Model) Len() int
- func (m *Model) Offset() (idx, line int)
- func (m *Model) ScrollBy(lines int)
- func (m *Model) ScrollToBottom()
- func (m *Model) ScrollToTop()
- func (m *Model) SetFocusIdx(idx int)
- func (m *Model) SetHeight(h int)
- func (m *Model) SetItems(heights, gaps []int)
- func (m *Model) SetTrailingHeight(h int)
- func (m *Model) UpdateFocusFromScroll()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is an item-aware viewport that tracks scroll position, focus, and layout over a list of variable-height items.
func (*Model) FocusNext ¶
func (m *Model) FocusNext()
FocusNext moves focus to the next item and scrolls to keep it visible.
func (*Model) FocusPrev ¶
func (m *Model) FocusPrev()
FocusPrev moves focus to the previous item and scrolls to keep it visible.
func (*Model) ItemAtY ¶
ItemAtY maps a viewport-relative Y coordinate to an item index and the Y offset within that item. Returns (-1, -1) if the position is in a gap, above, or below all items.
func (*Model) Offset ¶
Offset returns the current scroll position: the index of the first visible item and the number of lines scrolled into it.
func (*Model) ScrollBy ¶
ScrollBy scrolls by the given number of lines (positive = down, negative = up).
func (*Model) ScrollToBottom ¶
func (m *Model) ScrollToBottom()
ScrollToBottom scrolls so the last item is at the bottom of the viewport.
func (*Model) SetFocusIdx ¶
SetFocusIdx sets the focused item index.
func (*Model) SetItems ¶
SetItems replaces the item heights and gaps. gaps[i] is the number of lines between item i-1 and item i. gaps[0] must be 0 (no gap before the first item). Both slices must have the same length. Invalidates the bottom cache and clamps scroll/focus state.
func (*Model) SetTrailingHeight ¶
SetTrailingHeight sets extra content height below the last item (e.g. a divider or status line). The viewport accounts for this when computing the bottom scroll position.
func (*Model) UpdateFocusFromScroll ¶
func (m *Model) UpdateFocusFromScroll()
UpdateFocusFromScroll sets focus to the first fully visible item.