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 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 Limits(c *driver.ScrollConfig, frame, content driver.Size, refreshing bool) (lo, hi driver.Points)
- func Pulled(c *driver.ScrollConfig, offset driver.Point) driver.Points
- func Refreshes(c *driver.ScrollConfig, offset driver.Point, refreshing bool) bool
- 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
- type Bar
- type Drag
- type Motion
- type Resampler
- type TouchDrag
- type Velocity
- type Wheel
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 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 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 ¶
Pulled returns how far offset is pulled past the top of a vertical view: what values bound to its pull follow.
func Refreshes ¶
Refreshes reports whether a view let go at offset refreshes: it is refreshable, not refreshing yet, and pulled past its threshold.
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.
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 ¶
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 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 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 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.
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.