Skip to Content
Onevra

ScrollView

A scrolling container, vertical, horizontal or both, with MyGo's scroll bars.

Loading the live example…

scroll_view.go
import (
	"fmt"

	"github.com/egoist/mygo/ui"
	"github.com/oneo-me/onevra/source/components"
)

type scrollers struct{}

func (scrollers) View(c *ui.Context) {
	t := c.Theme()
	frame := func(e ui.Element) ui.Element {
		return e.Radius(t.Radius).Background(t.Surface).Border(1, t.Border)
	}
	ui.Row(c).Gap(16).Wrap().Justify(ui.Center).Children(func() {
		frame(components.ScrollView(c, components.ScrollViewOptions{}).Width(220).Height(200)).
			Padding(t.Space(3)).Gap(t.Space(2)).Children(func() {
			for i := 1; i <= 20; i++ {
				components.Text(c, fmt.Sprintf("Row %d", i)).Shrink(0)
			}
		})
		frame(components.ScrollView(c, components.ScrollViewOptions{Axes: components.ScrollHorizontal}).
			Width(220).Height(200)).Padding(t.Space(3)).Gap(t.Space(2)).Children(func() {
			for i := 1; i <= 8; i++ {
				ui.Column(c).Width(90).FillHeight().Shrink(0).Center().Radius(t.Radius).
					Background(t.SurfaceHover).Children(func() {
					components.Text(c, fmt.Sprintf("Card %d", i))
				})
			}
		})
	})
}
Source

Give a scroll view a size, or let it fill a bounded parent. Vertical and two-way views arrange children in a column, and horizontal views in a row. ScrollbarInsets moves the scroll bar track independently of the content's padding, which helps when a bar floats over an edge.

Let a scroll view reach the edges of the surface it scrolls within, and pad its content instead: an inset view clips scroll bars and gestures before they reach the edge.

API

ScrollView

func ScrollView(c *ui.Context, options ScrollViewOptions) ui.Element

ScrollView creates a scroll container using MyGo's layout, clipping, input and scroll state. Give it a size or Fill/Grow within a bounded parent. Vertical and both-axis views arrange children in a column; horizontal views arrange them in a row. Column/Row on the returned element can override this arrangement without changing the scrolling axes.

ScrollbarInsets on the returned element sets top, right, bottom and left track insets in DIPs (CSS shorthand), independently of content padding:

ScrollView(c, ScrollViewOptions{}).Fill().ScrollbarInsets(48, 0, 16)

TrackScroll accepts application-owned ui.ScrollState. MyGo owns scrollbar appearance and visibility: overflowing axes show bars on hover or while dragging, with color and width from the frame theme. Independent visibility and per-view color/width overrides are not supported by the upstream API.

pkg.go.dev

ScrollViewOptions

ScrollViewOptions configures a ScrollView.

Prop

Type

pkg.go.dev

ScrollAxes

type ScrollAxes uint8

ScrollAxes selects the directions in which a ScrollView can scroll.

const (
	ScrollVertical ScrollAxes = iota
	ScrollHorizontal
	ScrollBoth
)
pkg.go.dev
Edit this page on GitHub

On this page