scroll

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package scroll provides viewport and scrollbar primitives.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Controller

type Controller interface {
	ScrollBy(dx, dy int)
	ScrollTo(x, y int)
	PageBy(pages int)
	ScrollToStart()
	ScrollToEnd()
}

Controller provides scroll control for widgets.

type FixedHeightIndex

type FixedHeightIndex struct {
	Height int
	Count  func() int
}

FixedHeightIndex provides fast indexing for fixed-height items.

func (FixedHeightIndex) IndexForOffset

func (f FixedHeightIndex) IndexForOffset(offset int) int

IndexForOffset returns the item index for a given offset.

func (FixedHeightIndex) OffsetForIndex

func (f FixedHeightIndex) OffsetForIndex(index int) int

OffsetForIndex returns the offset for the given item index.

func (FixedHeightIndex) TotalHeight

func (f FixedHeightIndex) TotalHeight() int

TotalHeight returns the total height for all items.

type Orientation

type Orientation int

Orientation describes scrollbar orientation.

const (
	Horizontal Orientation = iota
	Vertical
)

type ScrollBehavior

type ScrollBehavior struct {
	Horizontal   ScrollPolicy
	Vertical     ScrollPolicy
	MouseWheel   int
	PageSize     float64
	SmoothScroll bool
}

ScrollBehavior controls scroll policies and interactions.

type ScrollPolicy

type ScrollPolicy int

ScrollPolicy configures when scrollbars appear.

const (
	ScrollAuto ScrollPolicy = iota
	ScrollAlways
	ScrollNever
)

type Scrollbar

type Scrollbar struct {
	Orientation  Orientation
	Track        backend.Style
	Thumb        backend.Style
	MinThumbSize int
	Chars        ScrollbarChars
}

Scrollbar configures scrollbar rendering.

type ScrollbarChars

type ScrollbarChars struct {
	Track rune
	Thumb rune
}

ScrollbarChars defines characters used to render the scrollbar.

func DefaultScrollbarChars

func DefaultScrollbarChars() ScrollbarChars

DefaultScrollbarChars returns ASCII defaults.

type Viewport

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

Viewport tracks the visible region of scrollable content.

func NewViewport

func NewViewport(content runtime.Widget) *Viewport

NewViewport creates a viewport.

func (*Viewport) Content

func (v *Viewport) Content() runtime.Widget

Content returns the content widget.

func (*Viewport) ContentSize

func (v *Viewport) ContentSize() runtime.Size

ContentSize returns the content size.

func (*Viewport) MaxOffset

func (v *Viewport) MaxOffset() image.Point

MaxOffset returns the maximum scrollable offset.

func (*Viewport) Offset

func (v *Viewport) Offset() image.Point

Offset returns the current offset.

func (*Viewport) PageBy

func (v *Viewport) PageBy(pages int)

PageBy scrolls by a number of pages.

func (*Viewport) ScrollBy

func (v *Viewport) ScrollBy(dx, dy int)

ScrollBy adjusts the offset.

func (*Viewport) ScrollTo

func (v *Viewport) ScrollTo(x, y int)

ScrollTo scrolls to absolute coordinates.

func (*Viewport) ScrollToEnd

func (v *Viewport) ScrollToEnd()

ScrollToEnd scrolls to the end of the content.

func (*Viewport) ScrollToStart

func (v *Viewport) ScrollToStart()

ScrollToStart scrolls to the beginning of the content.

func (*Viewport) SetContent

func (v *Viewport) SetContent(content runtime.Widget)

SetContent assigns the content widget.

func (*Viewport) SetContentSize

func (v *Viewport) SetContentSize(size runtime.Size)

SetContentSize updates the content size and clamps the offset.

func (*Viewport) SetOffset

func (v *Viewport) SetOffset(x, y int)

SetOffset sets the scroll offset.

func (*Viewport) SetOnChange

func (v *Viewport) SetOnChange(fn func(offset image.Point, content runtime.Size, view runtime.Size))

SetOnChange sets a callback for offset updates.

func (*Viewport) SetViewSize

func (v *Viewport) SetViewSize(size runtime.Size)

SetViewSize updates the view size and clamps the offset.

func (*Viewport) ViewSize

func (v *Viewport) ViewSize() runtime.Size

ViewSize returns the view size.

func (*Viewport) VisibleRect

func (v *Viewport) VisibleRect() runtime.Rect

VisibleRect returns the visible rectangle within content.

type VirtualContent

type VirtualContent interface {
	ItemCount() int
	ItemHeight(index int) int
	RenderItem(index int, ctx runtime.RenderContext)
	ItemAt(index int) any
}

VirtualContent provides virtualized content rendering.

type VirtualHeightFunc

type VirtualHeightFunc func(index int) int

VirtualHeightFunc returns the height for an item index.

type VirtualIndexer

type VirtualIndexer interface {
	IndexForOffset(offset int) int
	OffsetForIndex(index int) int
}

VirtualIndexer optionally provides fast offset/index mapping.

type VirtualItemFunc

type VirtualItemFunc func(index int) any

VirtualItemFunc returns the item data for an index.

type VirtualList

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

VirtualList provides windowed calculations for large lists. It implements VirtualContent plus optional sizing and indexing helpers.

func NewVirtualList

func NewVirtualList(itemCount int, itemHeight int, render VirtualRenderFunc) *VirtualList

NewVirtualList creates a virtual list with fixed item height.

func (*VirtualList) EnsureVisible

func (v *VirtualList) EnsureVisible(index int)

EnsureVisible scrolls just enough to keep the item fully visible.

func (*VirtualList) GetVisibleRange

func (v *VirtualList) GetVisibleRange() (start, end int)

GetVisibleRange returns the [start, end) item range for the current viewport, including overscan items.

func (*VirtualList) IndexForOffset

func (v *VirtualList) IndexForOffset(offset int) int

IndexForOffset maps a scroll offset to an item index.

func (*VirtualList) InvalidateHeights

func (v *VirtualList) InvalidateHeights()

InvalidateHeights clears cached height data for variable-height lists.

func (*VirtualList) ItemAt

func (v *VirtualList) ItemAt(index int) any

ItemAt returns the item data at the given index.

func (*VirtualList) ItemCount

func (v *VirtualList) ItemCount() int

ItemCount returns the item count.

func (*VirtualList) ItemHeight

func (v *VirtualList) ItemHeight(index int) int

ItemHeight returns the height for the given item index.

func (*VirtualList) MaxOffset

func (v *VirtualList) MaxOffset() int

MaxOffset returns the maximum scrollable offset.

func (*VirtualList) Offset

func (v *VirtualList) Offset() int

Offset returns the current scroll offset.

func (*VirtualList) OffsetForIndex

func (v *VirtualList) OffsetForIndex(index int) int

OffsetForIndex maps an item index to its scroll offset.

func (*VirtualList) RenderItem

func (v *VirtualList) RenderItem(index int, ctx runtime.RenderContext)

RenderItem renders the item at index.

func (*VirtualList) ScrollBy

func (v *VirtualList) ScrollBy(delta int)

ScrollBy scrolls the offset by the provided delta.

func (*VirtualList) ScrollToIndex

func (v *VirtualList) ScrollToIndex(index int)

ScrollToIndex scrolls to the given item index.

func (*VirtualList) ScrollToOffset

func (v *VirtualList) ScrollToOffset(pixels int)

ScrollToOffset scrolls to the given offset.

func (*VirtualList) SelectedIndex

func (v *VirtualList) SelectedIndex() int

SelectedIndex returns the selected index.

func (*VirtualList) SetItemAt

func (v *VirtualList) SetItemAt(fn VirtualItemFunc)

SetItemAt updates the item callback.

func (*VirtualList) SetItemCount

func (v *VirtualList) SetItemCount(count int)

SetItemCount updates the item count and clamps offset/selection.

func (*VirtualList) SetItemHeight

func (v *VirtualList) SetItemHeight(height int)

SetItemHeight sets a fixed item height.

func (*VirtualList) SetItemHeightFunc

func (v *VirtualList) SetItemHeightFunc(fn VirtualHeightFunc)

SetItemHeightFunc sets a variable item height function.

func (*VirtualList) SetOnSelection

func (v *VirtualList) SetOnSelection(fn func(index int))

SetOnSelection updates the selection callback.

func (*VirtualList) SetOverscan

func (v *VirtualList) SetOverscan(count int)

SetOverscan updates the overscan item count.

func (*VirtualList) SetRenderItem

func (v *VirtualList) SetRenderItem(fn VirtualRenderFunc)

SetRenderItem updates the render callback.

func (*VirtualList) SetSelected

func (v *VirtualList) SetSelected(index int)

SetSelected updates the selected index.

func (*VirtualList) SetViewportHeight

func (v *VirtualList) SetViewportHeight(height int)

SetViewportHeight updates the viewport height and clamps the offset.

func (*VirtualList) TotalHeight

func (v *VirtualList) TotalHeight() int

TotalHeight returns the total height for all items.

type VirtualRenderFunc

type VirtualRenderFunc func(index int, selected bool, ctx runtime.RenderContext)

VirtualRenderFunc renders an item at the given index.

type VirtualSizer

type VirtualSizer interface {
	TotalHeight() int
}

VirtualSizer optionally provides total height for virtual content.

Jump to

Keyboard shortcuts

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