layout

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func VScroller

func VScroller(props VScrollerProps) *dom.Node

VScroller creates a vertical scrolling container that shows a sliding window of children starting from BeginIndex and fitting within the specified Height. It includes headers at the top and bottom indicating items outside the visible area. The SelectedIndex ensures the selected item is always visible.

Types

type SliceVerticalResult

type SliceVerticalResult struct {
	BeginIndex          int  // The begin index (inclusive) for slicing
	EndIndex            int  // The end index (exclusive) for slicing
	ShowTopIndicator    bool // Whether to show "items above" indicator
	ShowBottomIndicator bool // Whether to show "items below" indicator
	ItemsAbove          int  // Number of items above the visible range
	ItemsBelow          int  // Number of items below the visible range
}

SliceVerticalResult contains the result of vertical slicing calculation

func SliceVertical

func SliceVertical(nodes []*dom.Node, selectedIndex int, height int, sliceStart int) SliceVerticalResult

SliceVertical calculates which nodes fit within the given height, accounting for scroll indicators. It returns a struct with all the information needed to render the visible portion with indicators. The function automatically reserves space for top/bottom indicators when needed.

Parameters:

  • nodes: The list of all nodes
  • selectedIndex: The currently selected item index (must be visible)
  • height: The total available height
  • sliceStart: Current slice start position (preserves window frame, 0 if unknown)

The function ensures selectedIndex is visible, adjusting the visible window as needed. It uses sliceStart as the initial beginIndex to preserve the window position.

type VScrollerProps

type VScrollerProps struct {
	Children           []*dom.Node
	Height             int
	SelectedIndex      int       // The currently selected/focused item index
	SliceStart         int       // Current slice start position (preserves window frame)
	OnSliceStartChange func(int) // Callback to update slice start when it changes (nil if not needed)
}

Jump to

Keyboard shortcuts

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