scrollbar

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package scrollbar is the scroll logic of the backends that keep scroll offsets of their own: where a scroll view's thumb is, whether a point is on its bar, and where dragging the thumb scrolls to; the offsets its content inset allows; and where a snapping view settles after a wheel or a thumb drag. The backends show a bar while its scroll view moves, while the pointer is over it, or while its thumb is dragged. macOS takes the motion too (motion.go): the rubber band, eased snaps, the indicator's geometry and fade, and trackpad events shown in step with the display.

Index

Constants

View Source
const (
	// Animation is how long animated scrolls and springs back take.
	Animation = 300 * time.Millisecond
	// IndicatorHold is how long the indicator stays after the last
	// scroll; it then fades out in IndicatorFade.
	IndicatorHold = 700 * time.Millisecond
	IndicatorFade = 300 * time.Millisecond
	// IndicatorMargin keeps the indicator off the ends of the viewport.
	IndicatorMargin driver.Points = 2
)
View Source
const (
	// Thickness is the thumb's, Inset its distance from the edge.
	Thickness driver.Points = 6
	Inset     driver.Points = 3
	// MinLength is the shortest a thumb gets on long content.
	MinLength driver.Points = 24
	// Grab is the width of the strip along the edge where a press takes
	// the bar.
	Grab driver.Points = 12
)
View Source
const TouchSlop driver.Points = 10

TouchSlop is how far a finger moves before it drags a scroll view.

View Source
const WheelIdle = 150 * time.Millisecond

WheelIdle is how long after its last turn a mouse wheel has settled.

View Source
const WheelSnap = 0.6

WheelSnap is the speed (points per millisecond) a settled wheel snaps with: fast enough to move on to the next snap point that way, as NSH's desktops do.

Variables

This section is empty.

Functions

func Along

Along returns p's coordinate along the view's axis.

func Bounce

func Bounce(velocity float32, t time.Duration) (driver.Points, bool)

Bounce returns how far past an edge content that hit it at velocity is t later, as macOS's and iOS's glides bounce: a critically damped spring that starts at that velocity and comes back to the edge. It reports whether the content is back.

func Clamp

func Clamp(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point) driver.Point

Clamp returns offset within the offsets a scroll view of size frame showing content takes: from minus its leading content inset to the end of the content and its trailing inset.

func ClampRefreshing added in v0.2.0

func ClampRefreshing(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, refreshing bool) driver.Point

ClampRefreshing clamps a resting offset after a configuration or layout change, retaining the refresh room. Explicit scroll commands and reports to the engine use Clamp's ordinary content bounds instead.

func Dragged

func Dragged(raw, lo, hi, dim driver.Points, bounces bool) driver.Points

Dragged returns where a gesture that took the offset to raw puts it, with lo and hi the offsets it rests within, in a viewport dim long: past them it rubber-bands when bounces, and stops otherwise.

func EaseOut

func EaseOut(t float64) float64

EaseOut returns the cubic ease out at t, from 0 to 1.

func Indicator

func Indicator(viewport, total, offset driver.Points) (start, length driver.Points, ok bool)

Indicator returns where the indicator starts along a viewport of that length showing total points from offset (0 at the start of total) and how long it is, or false when everything fits. Pulled past an edge, it shrinks, as on iOS.

func IndicatorAlpha

func IndicatorAlpha(since time.Duration) float32

IndicatorAlpha returns the indicator's opacity since it last showed.

func KeepStart

func KeepStart(old, inset driver.Edges, offset driver.Point) driver.Point

KeepStart returns where a view at offset goes when its content inset changes from old to inset: one resting at its start stays at the start, showing the inset, as on NSH's other backends.

func Limits

func Limits(c *driver.ScrollConfig, frame, content driver.Size, refreshing bool) (lo, hi driver.Points)

Limits returns the offsets along its axis a view of size frame showing content rests within: from its leading content inset to the end of the content and its trailing inset, with the refresh room above the content while it refreshes.

func Pulled

func Pulled(c *driver.ScrollConfig, offset driver.Point) driver.Points

Pulled returns how far offset is pulled past the top of a vertical view: what values bound to its pull follow.

func Refreshes

func Refreshes(c *driver.ScrollConfig, offset driver.Point, refreshing bool) bool

Refreshes reports whether a view let go at offset refreshes: it is refreshable, not refreshing yet, and pulled past its threshold.

func RestInset added in v0.2.0

func RestInset(c *driver.ScrollConfig, refreshing bool) driver.Edges

RestInset is the leading inset used to keep a resting view at its start across configuration changes, including the room held by a local refresh that the engine may not have confirmed yet.

func RevealDelta

func RevealDelta(start, end, viewport driver.Points) driver.Points

RevealDelta returns how far a scroll view moves along its axis so that the span from start to end, in its viewport, shows within the viewport with a margin; the start wins when the span does not fit.

func Rubber

func Rubber(over, dim driver.Points) driver.Points

Rubber returns how far content dragged over points past an edge of a viewport dim long moves: iOS's rubber band.

func SetAlong

func SetAlong(c *driver.ScrollConfig, p *driver.Point, v driver.Points)

SetAlong sets p's coordinate along the view's axis to v.

func Settle

func Settle(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, velocity float32) (driver.Point, bool)

Settle returns where a snapping or paging scroll view at offset comes to rest when the user lets it go at velocity (points per millisecond along its axis), and false when it does not snap.

func SnapDuration

func SnapDuration(distance driver.Points, velocity float32) time.Duration

SnapDuration returns how long an eased move by distance takes when it starts at velocity: ease out starts at three times its mean speed, which then matches the release, within 180 to 600 ms; a move against the release takes Animation. Nothing to move takes no time.

Types

type Bar

type Bar struct {
	Horizontal bool
	// Frame is the scroll view's size, Content its content's and Offset
	// how far the content is scrolled.
	Frame, Content driver.Size
	Offset         driver.Point
	// Inset is the content inset, which scrolls as part of the content.
	Inset driver.Edges
}

Bar is a scroll view's scroll bar.

func (Bar) Contains

func (b Bar) Contains(p driver.Point) bool

Contains reports whether p, in the scroll view, is on the bar: in the strip along its edge, while there is something to scroll.

func (Bar) Indicator

func (b Bar) Indicator() (rect driver.Bounds, travel driver.Points, ok bool)

Indicator returns the overlay indicator's rectangle in the scroll view, how far it travels along its track, and false when the content fits. It is macOS's: IndicatorMargin at each end, no shorter than indicatorMin, and shrinking while the content is pulled past an edge.

func (Bar) Press

func (b Bar) Press(p driver.Point) Drag

Press starts dragging the bar from p, in the scroll view. Off the thumb, the thumb first jumps to center under p.

func (Bar) PressIndicator

func (b Bar) PressIndicator(p driver.Point) Drag

PressIndicator starts dragging the overlay indicator of Indicator from p, in the scroll view. Off the thumb, the thumb first jumps to center under p.

func (Bar) Thumb

func (b Bar) Thumb() (driver.Bounds, bool)

Thumb returns the thumb's rectangle in the scroll view, or false when the content fits and there is nothing to scroll.

type Drag

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

Drag follows the pointer pressing a bar.

func (Drag) Offset

func (d Drag) Offset(p driver.Point) driver.Point

Offset returns where the content scrolls to with the pointer at p, in the scroll view, clamped to what it can show.

func (*Drag) Shift

func (d *Drag) Shift(by driver.Points)

Shift moves the drag along with the core moving the offset by d along the axis (ItemScrollBy), so it continues from the content it was on.

type Motion

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

Motion is where a released view goes along its axis: an eased move to a point, or a glide that slows by the view's deceleration.

func Release

func Release(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, velocity float32, lo, hi driver.Points, now time.Time) Motion

Release returns how a view of size frame showing content, let go at offset with velocity, comes to rest: back to its edge when past one, to its snap point, or gliding. lo and hi are Limits'.

func (*Motion) At

func (m *Motion) At(now time.Time) (driver.Points, bool)

At returns where the view is at now, and whether it came to rest. A glide bounces at the edge it reaches, or stops there when the view does not bounce.

func (*Motion) Moves

func (m *Motion) Moves() bool

Moves reports whether the motion goes anywhere.

type Resampler

type Resampler struct {

	// Interval is the time between events, smoothed.
	Interval time.Duration
	// contains filtered or unexported fields
}

Resampler shows where trackpad events put an offset in step with the display. Events come at about the display's rate but not in step with it: applied as they come, some frames move twice and some not at all, and a steady scroll judders. Each event records the offset at its time; each frame shows the path one event interval back, interpolated, so every frame moves by what that interval did.

func (*Resampler) Active

func (r *Resampler) Active() bool

Active reports whether events wait to be shown.

func (*Resampler) Goal

func (r *Resampler) Goal() (driver.Points, bool)

Goal returns where the newest event put the offset.

func (*Resampler) Push

func (r *Resampler) Push(at time.Duration, pos, shown driver.Points)

Push records that an event at at put the offset at pos; shown is the offset showing, where the motion starts an interval before the first event.

func (*Resampler) Reset

func (r *Resampler) Reset()

Reset forgets the events.

func (*Resampler) Sample

func (r *Resampler) Sample(t time.Duration) (driver.Points, bool)

Sample returns the offset at t, dropping the events before it, and whether t is past the newest event.

func (*Resampler) Shift

func (r *Resampler) Shift(d driver.Points)

Shift moves the recorded offsets by d, as the core moves the content.

type TouchDrag

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

TouchDrag follows a finger on a scroll view from where it went down.

func NewTouchDrag

func NewTouchDrag(at driver.Point, from driver.Points, now time.Time) *TouchDrag

NewTouchDrag starts following a finger down at at on a view whose offset along its axis is from.

func (*TouchDrag) Claimed

func (d *TouchDrag) Claimed() bool

Claimed reports whether the drag took the finger.

func (*TouchDrag) Claims

func (d *TouchDrag) Claims(c *driver.ScrollConfig, at driver.Point) bool

Claims reports whether a finger now at at drags the view: moved past TouchSlop along its axis, and more along it than across. Once it does, the drag starts from where the finger is, so the content does not jump.

func (*TouchDrag) Move

Move records the finger at at and returns the offset it asks along the axis, before any rubber band.

func (*TouchDrag) Refreshes added in v0.2.0

func (d *TouchDrag) Refreshes(c *driver.ScrollConfig, refreshing bool) bool

Refreshes reports whether releasing the finger refreshes, using the pull before rubber banding so the threshold does not depend on the viewport's size or whether the content bounces.

func (*TouchDrag) Velocity

func (d *TouchDrag) Velocity(c *driver.ScrollConfig) float32

Velocity returns the offset's speed along the axis as the finger lifts, in points per millisecond: the finger's, reversed.

type Velocity

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

Velocity follows a pointer's positions for its speed over the last 100 ms.

func (*Velocity) Add

func (v *Velocity) Add(at time.Duration, p driver.Point)

Add records that the pointer is at p at time at.

func (*Velocity) Reset

func (v *Velocity) Reset()

Reset forgets the positions.

func (*Velocity) Speed

func (v *Velocity) Speed() (x, y float32)

Speed returns the pointer's velocity in points per millisecond, zero after a pause.

type Wheel

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

Wheel follows the wheel turns on a snapping scroll view until they settle.

func (*Wheel) Settled

func (w *Wheel) Settled(now time.Time) (velocity float32, ok bool)

Settled reports whether the turns stopped by now; it then forgets them, and returns the speed to snap with in the wheel's direction.

func (*Wheel) Turn

func (w *Wheel) Turn(now time.Time, d driver.Points)

Turn records a turn moving the offset by d along the view's axis.

func (*Wheel) Turning

func (w *Wheel) Turning() bool

Turning reports whether turns came within WheelIdle of now.

Jump to

Keyboard shortcuts

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