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
- func Along(c *driver.ScrollConfig, p driver.Point) driver.Points
- func Bounce(velocity float32, t time.Duration) (driver.Points, bool)
- func Clamp(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point) driver.Point
- func ClampRefreshing(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, ...) driver.Point
- func ClampZoomOffset(c *driver.ScrollConfig, frame, content driver.Size, p driver.Point, z float64) driver.Point
- func ContentAt(offset, focus driver.Point, z float64) driver.Point
- func Dragged(raw, lo, hi, dim driver.Points, bounces bool) driver.Points
- func EaseOut(t float64) float64
- func Indicator(viewport, total, offset driver.Points) (start, length driver.Points, ok bool)
- func IndicatorAlpha(since time.Duration) float32
- func KeepStart(old, inset driver.Edges, offset driver.Point) driver.Point
- func LimitZoom(c *driver.ScrollConfig, scale float64, rubber bool) float64
- func Limits(c *driver.ScrollConfig, frame, content driver.Size, refreshing bool) (lo, hi driver.Points)
- func OffsetFor(content, focus driver.Point, z float64) driver.Point
- func Pulled(c *driver.ScrollConfig, offset driver.Point) driver.Points
- func RebaseOffset(config *driver.ScrollConfig, offset, delta driver.Point, ...) driver.Point
- func Refreshes(c *driver.ScrollConfig, offset driver.Point, refreshing bool) bool
- func Report(sink EventSink, event driver.Event, frameWanted bool)
- func Rest(animator *driver.Animator, id driver.NodeID, report, startClock func())
- func RestInset(c *driver.ScrollConfig, refreshing bool) driver.Edges
- func RevealDelta(start, end, viewport driver.Points) driver.Points
- func Rubber(over, dim driver.Points) driver.Points
- func SetAlong(c *driver.ScrollConfig, p *driver.Point, v driver.Points)
- func Settle(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, ...) (driver.Point, bool)
- func SnapDuration(distance driver.Points, velocity float32) time.Duration
- func WheelZoom(current, deltaY float64) float64
- func ZoomAxisLimits(c *driver.ScrollConfig, frame, content driver.Size, z float64, horizontal bool) (lo, hi driver.Points)
- type Bar
- type Drag
- type EventSink
- type InterruptHost
- type Motion
- type OffsetAnimation
- type Resampler
- type SettleHost
- type StickyBindings
- type StickyCells
- type TouchDrag
- func (d *TouchDrag) Claimed() bool
- func (d *TouchDrag) Claims(c *driver.ScrollConfig, at driver.Point) bool
- func (d *TouchDrag) Move(c *driver.ScrollConfig, at driver.Point, now time.Time) driver.Points
- func (d *TouchDrag) Refreshes(c *driver.ScrollConfig, refreshing bool) bool
- func (d *TouchDrag) Velocity(c *driver.ScrollConfig) float32
- type TouchHost
- type TouchSession
- type TouchView
- type Velocity
- type Wheel
- type ZoomEase
Constants ¶
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 )
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 )
const TouchSlop driver.Points = 10
TouchSlop is how far a finger moves before it drags a scroll view.
const WheelIdle = 150 * time.Millisecond
WheelIdle is how long after its last turn a mouse wheel has settled.
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 Bounce ¶
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 ¶
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 ClampZoomOffset ¶
func ClampZoomOffset(c *driver.ScrollConfig, frame, content driver.Size, p driver.Point, z float64) driver.Point
ClampZoomOffset clamps offset p to both axes' limits at zoom z.
func ContentAt ¶
ContentAt returns the unzoomed content point at viewport point focus, given offset and zoom z.
func Dragged ¶
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 Indicator ¶
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 ¶
IndicatorAlpha returns the indicator's opacity since it last showed.
func KeepStart ¶
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 LimitZoom ¶
func LimitZoom(c *driver.ScrollConfig, scale float64, rubber bool) float64
LimitZoom keeps scale within c's zoom limits, rubber-banding past them while rubber is true unless NoBouncesZoom is set.
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 OffsetFor ¶
OffsetFor returns the offset that places unzoomed content point c at viewport point focus at zoom z.
func Pulled ¶
Pulled returns how far offset is pulled past the top of a vertical view: what values bound to its pull follow.
func RebaseOffset ¶
func RebaseOffset(config *driver.ScrollConfig, offset, delta driver.Point, moving *OffsetAnimation, drag *Drag) driver.Point
RebaseOffset carries a scroll or thumb drag along with an unclamped ItemScrollBy, so a change above the viewport preserves the content in view.
func Refreshes ¶
Refreshes reports whether a view let go at offset refreshes: it is refreshable, not refreshing yet, and pulled past its threshold.
func Rest ¶
Rest reports a scroll's end before starting the snapping diff clamps that follow it. The clock runs only while their animator has work.
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 ¶
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 ¶
Rubber returns how far content dragged over points past an edge of a viewport dim long moves: iOS's rubber band.
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 ¶
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.
func WheelZoom ¶
WheelZoom scales current by a Ctrl+wheel delta in points (positive delta zooms out, negative delta zooms in, matching web's wheel zoom).
func ZoomAxisLimits ¶
func ZoomAxisLimits(c *driver.ScrollConfig, frame, content driver.Size, z float64, horizontal bool) (lo, hi driver.Points)
ZoomAxisLimits returns the offset limits along one axis for a zooming scroll view of viewport frame and unzoomed content size at zoom z. When CenterContent is set and the zoomed content plus insets fits inside the viewport, lo and hi both equal the offset that centers it.
Types ¶
type Bar ¶
type Bar struct {
Horizontal bool
// RTL places a vertical scroll bar on the left edge instead of the right.
RTL 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 ¶
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 ¶
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 ¶
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 ¶
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.
type Drag ¶
type Drag struct {
// contains filtered or unexported fields
}
Drag follows the pointer pressing a bar.
type EventSink ¶
EventSink queues scroll reports either on their own or with a frame already requested by the app.
type InterruptHost ¶
type InterruptHost struct {
Momentum bool
ClearAnimation func()
Gliding bool
ClearGlide func()
Event func(driver.EventKind)
AfterGlide func()
}
InterruptHost ends scroll animation and glide state before a new input. Native wheel ownership and refresh indicators stay in the callbacks.
func (InterruptHost) Interrupt ¶
func (host InterruptHost) Interrupt()
Interrupt preserves the order of momentum reports and native cleanup.
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'.
type OffsetAnimation ¶
OffsetAnimation is a scroll toward an offset. A user snap ends momentum when it finishes. The toolkit chooses the timing curve.
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) Push ¶
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.
type SettleHost ¶
type SettleHost struct {
Scroll func(driver.Point)
Animate func(driver.Point)
Event func(driver.EventKind)
Rest func()
}
SettleHost applies a snap through the backend's scrolling and animation paths. The callbacks run synchronously in the order the scroll reports.
func (SettleHost) Settle ¶
func (h SettleHost) Settle(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, velocity float32, reduceMotion bool)
Settle snaps a released view or reports its rest. The backend owns the animation curve and reports momentum's end when that animation finishes.
type StickyBindings ¶
type StickyBindings[V comparable] map[V]driver.NodeID
StickyBindings tracks scroll views with sticky cells whose insets are animated. Tracking the view as well as its ID detects replacement views.
func (StickyBindings[V]) Repin ¶
func (bound StickyBindings[V]) Repin(lookup func(driver.NodeID) V, pin func(V))
Repin replaces each tracked view's current shifts and drops views that no longer occupy their IDs.
func (*StickyBindings[V]) Replace ¶
func (bound *StickyBindings[V]) Replace(v V, id driver.NodeID, current *StickyCells, cells StickyCells, place func(driver.NodeID, driver.Point), pin func(V))
Replace restores the previous cells, tracks the new bindings and pins the new cells.
type StickyCells ¶
type StickyCells []driver.StickyCell
StickyCells holds the cells pinned by one scroll view.
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 ¶
NewTouchDrag starts following a finger down at at on a view whose offset along its axis is from.
func (*TouchDrag) Claims ¶
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.
type TouchHost ¶
type TouchHost[V comparable] struct { State func(V) TouchView Interrupt func(V) Begin func(V, bool) Move func(V, driver.Point) Show func(V) Blocked bool }
TouchHost keeps native press cancellation, scrolling and indicators in the backend while TouchSession owns which scroll view takes a finger.
type TouchSession ¶
type TouchSession[V comparable] struct { Taken V Drag *TouchDrag Braked bool // contains filtered or unexported fields }
TouchSession follows the scroll views under one finger, innermost first.
func NewTouchSession ¶
func NewTouchSession[V comparable](under []V, at driver.Point, now time.Time, host TouchHost[V]) *TouchSession[V]
NewTouchSession brakes ongoing motion and skips views that cannot scroll. under is the outermost-first hit-test result.
func (*TouchSession[V]) Move ¶
func (session *TouchSession[V]) Move(at driver.Point, now time.Time, host TouchHost[V]) (handled, keep bool)
Move returns whether the finger was handled and whether to keep its session. Braking makes the finger the scroll view's immediately; otherwise a pan may win before the drag crosses its slop.
type TouchView ¶
type TouchView struct {
Config *driver.ScrollConfig
Offset driver.Point
Frame, Content driver.Size
Deleted, Moving bool
Refreshing bool
}
TouchView is the state needed to arbitrate and move a desktop touch drag.
type Velocity ¶
type Velocity struct {
// contains filtered or unexported fields
}
Velocity follows a pointer's positions for its speed over the last 100 ms.
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 ¶
Settled reports whether the turns stopped by now; it then forgets them, and returns the speed to snap with in the wheel's direction.
type ZoomEase ¶
ZoomEase interpolates a scroll view's zoom from Scale to Target while keeping unzoomed content point moving from From to To at viewport Focus.
func NewZoomEase ¶
func NewZoomEase(c *driver.ScrollConfig, frame, content driver.Size, offset driver.Point, zoom float64, targetContent, focus driver.Point, targetZoom float64) (ZoomEase, driver.Point, bool)
NewZoomEase builds a ZoomEase from current (offset, zoom) to targetZoom with content point c placed at viewport focus. It returns ok=false when the view is already within half a point and 1e-3 scale of the target.