Skip to content

Scroll: scrolling containers

Build scrolling containers with Scroll. This page includes a runnable example, all props, and behavior constraints.

Complete example

Complete environment setup first. Copy this complete main.go and run go run ..

go
package main

import (
	"github.com/dxui-org/dxui"
	"log"
)

func main() {
	offset := dxui.Point{}
	app := dxui.NewApp(dxui.AppOptions{
		Title:      "Scroll",
		Width:      640,
		Height:     480,
		Background: dxui.RGBA(248, 250, 252, 255),
	})
	if err := app.Run(func() dxui.View {
		return dxui.Box(
			dxui.BoxProps{
				Gap: 16,
				Style: dxui.Style{
					Padding: dxui.Padding(24),
				},
			},
			dxui.Scroll(
				dxui.ScrollProps{
					Style: dxui.Style{
						Height: dxui.Px(240),
						Width:  dxui.Px(400),
					},
					Offset:    dxui.Some(offset),
					OnScroll:  dxui.Assign(&offset),
					Scrollbar: dxui.ScrollbarAlways,
				},
				dxui.Box(
					dxui.BoxProps{
						Gap: 12,
					},
					dxui.Label("Top"),
					dxui.Box(dxui.BoxProps{
						Style: dxui.Style{
							Height: dxui.Px(600),
							Shrink: dxui.NoShrink(),
						},
					}),
					dxui.Label("Bottom"),
				),
			),
		)
	}); err != nil {

		log.Fatal(err)
	}
}

Parameters and API

go
func Scroll(props ScrollProps, child View) View
FieldTypePurpose, defaults, and constraints
KeystringStable unique identity within one parent; empty by default. Use business IDs in dynamic lists, not changing indices.
StyleStyleLocal layout, paint, and text styling; zero uses intrinsic sizes and theme defaults.
TokenComponentTokenComponent theme entry; empty selects its default.
StatesStateStylesPaint patches for actual interaction states; cannot fabricate state or change layout.
PointerPointerBehaviorDefaults to PointerAuto; PointerNone excludes the entire subtree from pointer participation, unlike Disabled.
AxisScrollAxisDefaults to ScrollVertical; children are measured without bounds on enabled axes.
InitialOffsetOption[Point]Optional initial mount offset; later changes do not reset internal position.
OffsetOption[Point]Optional controlled scroll position.
ScrollbarScrollbarPolicyDefaults to ScrollbarAuto; Always always shows, Hidden hides the track but permits scrolling.
OnScrollfunc(Point)Proposes a complete offset; uncontrolled internal scrolling does not depend on this callback.

Behavior and limitations

Exactly one child. Axis defaults to ScrollVertical; ScrollHorizontal/ScrollBoth are available. Children are measured unbounded on enabled axes, so the viewport needs definite dimensions. Unset Offset retains internal state; InitialOffset applies only at first mount. With Some Offset, OnScroll only proposes changes. ScrollbarHidden still permits wheel scrolling. Nested scrollers pass remaining delta at boundaries. No inertia or smooth scrolling; ordinary Scroll mounts all content.

All components share identity, style, and pointer rules. See full declarations for referenced enums, structs, and comments. Running examples explains build verification.