Documentation
¶
Overview ¶
Package scroll provides viewport and scrollbar primitives.
Index ¶
- type Controller
- type FixedHeightIndex
- type Orientation
- type ScrollBehavior
- type ScrollPolicy
- type Scrollbar
- type ScrollbarChars
- type Viewport
- func (v *Viewport) Content() runtime.Widget
- func (v *Viewport) ContentSize() runtime.Size
- func (v *Viewport) MaxOffset() image.Point
- func (v *Viewport) Offset() image.Point
- func (v *Viewport) PageBy(pages int)
- func (v *Viewport) ScrollBy(dx, dy int)
- func (v *Viewport) ScrollTo(x, y int)
- func (v *Viewport) ScrollToEnd()
- func (v *Viewport) ScrollToStart()
- func (v *Viewport) SetContent(content runtime.Widget)
- func (v *Viewport) SetContentSize(size runtime.Size)
- func (v *Viewport) SetOffset(x, y int)
- func (v *Viewport) SetOnChange(fn func(offset image.Point, content runtime.Size, view runtime.Size))
- func (v *Viewport) SetViewSize(size runtime.Size)
- func (v *Viewport) ViewSize() runtime.Size
- func (v *Viewport) VisibleRect() runtime.Rect
- type VirtualContent
- type VirtualHeightFunc
- type VirtualIndexer
- type VirtualItemFunc
- type VirtualList
- func (v *VirtualList) EnsureVisible(index int)
- func (v *VirtualList) GetVisibleRange() (start, end int)
- func (v *VirtualList) IndexForOffset(offset int) int
- func (v *VirtualList) InvalidateHeights()
- func (v *VirtualList) ItemAt(index int) any
- func (v *VirtualList) ItemCount() int
- func (v *VirtualList) ItemHeight(index int) int
- func (v *VirtualList) MaxOffset() int
- func (v *VirtualList) Offset() int
- func (v *VirtualList) OffsetForIndex(index int) int
- func (v *VirtualList) RenderItem(index int, ctx runtime.RenderContext)
- func (v *VirtualList) ScrollBy(delta int)
- func (v *VirtualList) ScrollToIndex(index int)
- func (v *VirtualList) ScrollToOffset(pixels int)
- func (v *VirtualList) SelectedIndex() int
- func (v *VirtualList) SetItemAt(fn VirtualItemFunc)
- func (v *VirtualList) SetItemCount(count int)
- func (v *VirtualList) SetItemHeight(height int)
- func (v *VirtualList) SetItemHeightFunc(fn VirtualHeightFunc)
- func (v *VirtualList) SetOnSelection(fn func(index int))
- func (v *VirtualList) SetOverscan(count int)
- func (v *VirtualList) SetRenderItem(fn VirtualRenderFunc)
- func (v *VirtualList) SetSelected(index int)
- func (v *VirtualList) SetViewportHeight(height int)
- func (v *VirtualList) TotalHeight() int
- type VirtualRenderFunc
- type VirtualSizer
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 ¶
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 ¶
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 ¶
NewViewport creates a viewport.
func (*Viewport) ContentSize ¶
ContentSize returns the content size.
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 ¶
SetContent assigns the content widget.
func (*Viewport) SetContentSize ¶
SetContentSize updates the content size and clamps the 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 ¶
SetViewSize updates the view size and clamps the offset.
func (*Viewport) VisibleRect ¶
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 ¶
VirtualHeightFunc returns the height for an item index.
type VirtualIndexer ¶
VirtualIndexer optionally provides fast offset/index mapping.
type VirtualItemFunc ¶
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.