scrollview

package
v1.164.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetEdgeFadeEnabled added in v1.164.0

func SetEdgeFadeEnabled(enabled bool)

SetEdgeFadeEnabled controls edge fades for existing and future scrollviews.

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 New

func New(opts ...Option) *Model

New creates a new scrollview with the given options.

func (*Model) ClearScrollbarPointer added in v1.164.0

func (m *Model) ClearScrollbarPointer()

ClearScrollbarPointer resets presentation and releases capture on a surface that is no longer receiving input.

func (*Model) ContentWidth

func (m *Model) ContentWidth() int

ContentWidth returns the width available for content text.

func (*Model) EnsureLineVisible

func (m *Model) EnsureLineVisible(line int)

EnsureLineVisible scrolls minimally to bring a line into the viewport. Works before [SetContent] — only needs [SetSize].

func (*Model) EnsureRangeVisible

func (m *Model) EnsureRangeVisible(startLine, endLine int)

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

func (m *Model) IsDragging() bool

IsDragging returns whether the scrollbar thumb is being dragged.

func (*Model) LineDown

func (m *Model) LineDown()

func (*Model) LineUp

func (m *Model) LineUp()

func (*Model) NeedsScrollbar

func (m *Model) NeedsScrollbar() bool

NeedsScrollbar returns true if content is taller than the viewport.

func (*Model) PageDown

func (m *Model) PageDown()

func (*Model) PageUp

func (m *Model) PageUp()

func (*Model) ReservedCols

func (m *Model) ReservedCols() int

ReservedCols returns columns reserved for gap + scrollbar.

func (*Model) RevealScrollbar added in v1.164.0

func (m *Model) RevealScrollbar() tea.Cmd

RevealScrollbar is called by owners when user input moves their viewport.

func (*Model) ScrollBy

func (m *Model) ScrollBy(delta int)

ScrollBy adjusts the scroll offset by delta lines.

func (*Model) ScrollOffset

func (m *Model) ScrollOffset() int

ScrollOffset returns the current scroll offset.

func (*Model) ScrollToBottom

func (m *Model) ScrollToBottom()

func (*Model) ScrollToTop

func (m *Model) ScrollToTop()

func (*Model) ScrollbarX

func (m *Model) ScrollbarX() int

ScrollbarX returns the absolute screen X of the scrollbar column.

func (*Model) SetAnimationRuntime added in v1.164.0

func (m *Model) SetAnimationRuntime(clock *animation.Runtime)

SetAnimationRuntime binds scrollbar animation to the owning program's clock. Without a clock, hover and capture are painted immediately.

func (*Model) SetContent

func (m *Model) SetContent(lines []string, totalHeight int)

SetContent provides the full content buffer and total height. totalHeight may be >= len(lines) for callers that render rows separately. The lines slice must not be mutated in place after being passed here; callers rebuild a fresh slice when content changes.

func (*Model) SetContentWithTrailingSlack added in v1.164.0

func (m *Model) SetContentWithTrailingSlack(lines []string, contentHeight, trailingSlack int)

SetContentWithTrailingSlack adds scrollable blank rows below the content. Those rows keep their scroll geometry but do not trigger a bottom fade.

func (*Model) SetPosition

func (m *Model) SetPosition(x, y int)

SetPosition sets the absolute screen position (for mouse hit-testing).

func (*Model) SetPositionAndReconcileScrollbar added in v1.164.0

func (m *Model) SetPositionAndReconcileScrollbar(x, y int) bool

SetPositionAndReconcileScrollbar places a viewport during rendering and reports whether its scrollbar must be repainted. With no tick chain to animate a layout change, settled opacity follows the final pointer geometry.

func (*Model) SetScrollOffset

func (m *Model) SetScrollOffset(offset int)

SetScrollOffset sets the scroll offset, clamped when content dimensions are known.

func (*Model) SetScrollbarPointer added in v1.164.0

func (m *Model) SetScrollbarPointer(x, y int) tea.Cmd

SetScrollbarPointer observes motion without taking mouse capture. Negative coordinates clear hover, for example when another surface takes focus.

func (*Model) SetSize

func (m *Model) SetSize(width, height int)

SetSize sets the total width and height of the scrollable region.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (handled bool, cmd tea.Cmd)

Update handles mouse (scrollbar click/drag/wheel) and keyboard scroll events. Returns handled=true when the event was consumed.

func (*Model) UpdateMouse

func (m *Model) UpdateMouse(msg tea.Msg) (handled bool, cmd tea.Cmd)

UpdateMouse delegates mouse events to the scrollbar. Low-level alternative to [Update].

func (*Model) UpdateScrollbarAnimation added in v1.164.0

func (m *Model) UpdateScrollbarAnimation(tick animation.TickMsg)

UpdateScrollbarAnimation paints a new opacity only on accepted shared ticks.

func (*Model) View

func (m *Model) View() string

View renders the scrollable region with automatic content slicing.

func (*Model) ViewWithLines

func (m *Model) ViewWithLines(visibleLines []string) string

ViewWithLines renders pre-sliced visible lines with the scrollbar.

func (*Model) ViewWithPaddedLines added in v1.128.0

func (m *Model) ViewWithPaddedLines(visibleLines []string) string

ViewWithPaddedLines renders pre-sliced lines that are already exactly ContentWidth columns wide. It skips ANSI/grapheme measurement and wrapping; callers must uphold the width contract.

func (*Model) ViewWithRestyledLines added in v1.95.0

func (m *Model) ViewWithRestyledLines(visibleLines []string) string

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

func (m *Model) VisibleHeight() int

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

func WithReserveScrollbarSpace(v bool) Option

WithReserveScrollbarSpace always reserves gap+scrollbar columns, preventing layout shifts.

func WithWheelStep

func WithWheelStep(n int) Option

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.

Jump to

Keyboard shortcuts

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