Documentation
¶
Overview ¶
Package scrollview provides a composable scrollable view that pairs content with a fixed-position scrollbar.
Simple path: call Model.Update + Model.View. Advanced path (custom scroll management): use Model.UpdateMouse, Model.SetScrollOffset, and Model.ViewWithLines.
Index ¶
- type Model
- func (m *Model) ContentWidth() int
- func (m *Model) EnsureLineVisible(line int)
- func (m *Model) EnsureRangeVisible(startLine, endLine int)
- func (m *Model) IsDragging() bool
- func (m *Model) LineDown()
- func (m *Model) LineUp()
- func (m *Model) NeedsScrollbar() bool
- func (m *Model) PageDown()
- func (m *Model) PageUp()
- func (m *Model) ReservedCols() int
- func (m *Model) ScrollBy(delta int)
- func (m *Model) ScrollOffset() int
- func (m *Model) ScrollToBottom()
- func (m *Model) ScrollToTop()
- func (m *Model) ScrollbarX() int
- func (m *Model) SetContent(lines []string, totalHeight int)
- func (m *Model) SetPosition(x, y int)
- func (m *Model) SetScrollOffset(offset int)
- func (m *Model) SetSize(width, height int)
- func (m *Model) Update(msg tea.Msg) (handled bool, cmd tea.Cmd)
- func (m *Model) UpdateMouse(msg tea.Msg) (handled bool, cmd tea.Cmd)
- func (m *Model) View() string
- func (m *Model) ViewWithLines(visibleLines []string) string
- func (m *Model) ViewWithRestyledLines(visibleLines []string) string
- func (m *Model) VisibleHeight() int
- type Option
- type ScrollKeyMap
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 a composable scrollable view that owns a scrollbar and ensures fixed-width rendering.
func (*Model) ContentWidth ¶
ContentWidth returns the width available for content text.
func (*Model) EnsureLineVisible ¶
EnsureLineVisible scrolls minimally to bring a line into the viewport. Works before [SetContent] — only needs [SetSize].
func (*Model) EnsureRangeVisible ¶
EnsureRangeVisible scrolls minimally to bring lines startLine..endLine into the view. If the range is taller than the view, the start is prioritized.
func (*Model) IsDragging ¶
IsDragging returns whether the scrollbar thumb is being dragged.
func (*Model) NeedsScrollbar ¶
NeedsScrollbar returns true if content is taller than the viewport.
func (*Model) ReservedCols ¶
ReservedCols returns columns reserved for gap + scrollbar.
func (*Model) ScrollOffset ¶
ScrollOffset returns the current scroll offset.
func (*Model) ScrollToBottom ¶
func (m *Model) ScrollToBottom()
func (*Model) ScrollToTop ¶
func (m *Model) ScrollToTop()
func (*Model) ScrollbarX ¶
ScrollbarX returns the absolute screen X of the scrollbar column.
func (*Model) SetContent ¶
SetContent provides the full content buffer and total height. totalHeight may be >= len(lines) for virtual blank lines (e.g. bottomSlack). The lines slice must not be mutated in place after being passed here; callers rebuild a fresh slice when content changes.
func (*Model) SetPosition ¶
SetPosition sets the absolute screen position (for mouse hit-testing).
func (*Model) SetScrollOffset ¶
SetScrollOffset sets the scroll offset, clamped when content dimensions are known.
func (*Model) Update ¶
Update handles mouse (scrollbar click/drag/wheel) and keyboard scroll events. Returns handled=true when the event was consumed.
func (*Model) UpdateMouse ¶
UpdateMouse delegates mouse events to the scrollbar. Low-level alternative to [Update].
func (*Model) ViewWithLines ¶
ViewWithLines renders pre-sliced visible lines with the scrollbar.
func (*Model) ViewWithRestyledLines ¶ added in v1.95.0
ViewWithRestyledLines is like Model.ViewWithLines for callers whose visibleLines are sliced from the content set via Model.SetContent at the current scroll offset (possibly restyled, e.g. selection or hover highlights). Unchanged lines reuse memoized width lookups in compose; restyled lines are re-measured.
func (*Model) VisibleHeight ¶
VisibleHeight returns the viewport height in lines.
type Option ¶
type Option func(*Model)
func WithKeyMap ¶
func WithKeyMap(km *ScrollKeyMap) Option
WithKeyMap sets keyboard bindings for scroll actions. Pass nil to disable.
func WithReserveScrollbarSpace ¶
WithReserveScrollbarSpace always reserves gap+scrollbar columns, preventing layout shifts.
func WithWheelStep ¶
WithWheelStep sets lines scrolled per wheel tick (default 2).
type ScrollKeyMap ¶
type ScrollKeyMap struct {
Up key.Binding // optional — leave unset for list dialogs that use up/down for selection
Down key.Binding
PageUp key.Binding
PageDown key.Binding
Top key.Binding // home
Bottom key.Binding // end
}
ScrollKeyMap defines which keys trigger scroll actions.
func DefaultScrollKeyMap ¶
func DefaultScrollKeyMap() *ScrollKeyMap
DefaultScrollKeyMap returns a key map with page-up/down and home/end. Up/Down are intentionally unbound so list dialogs can use them for selection.
func ReadOnlyScrollKeyMap ¶
func ReadOnlyScrollKeyMap() *ScrollKeyMap
ReadOnlyScrollKeyMap returns a key map where up/down/j/k also scroll.