Expand description
Scroll behavior primitives: wheel acceleration and middle-click autoscroll.
These are behaviors, not components: they own no rendering and no theme. Applications (or composite components) drive them from ordinary GPUI input events and apply the returned distances to whatever scroll position they manage. This mirrors how Zed’s own editor handles the wheel — discrete line notches are scaled by a sensitivity multiplier while trackpad pixel deltas pass through untouched — and adds Windows-convention cadence acceleration on top for fast successive scrolling.
§Wheel acceleration
use gpui_ai::scrolling::{WheelAccelerator, LINE_HEIGHT_PX};
use gpui::{px, Pixels};
let mut wheel = WheelAccelerator::new();
// One notch of a conventional wheel; negative dy scrolls down.
let boost = wheel.line_notch(-1.0, false);
assert!(boost > px(0.) && boost <= px((3.0 - 1.0) * LINE_HEIGHT_PX));
// Trackpad pixel deltas never enter the accelerator: the application
// forwards them straight to its scroll position, unaccelerated.§Middle-click autoscroll
use gpui_ai::scrolling::Autoscroll;
use gpui::{point, px, Pixels};
let mut session = Autoscroll::start(point(px(300.), px(200.)));
session.track(point(px(300.), px(270.)));
// Pointer 70 px below the anchor at ~16 ms/frame:
let distance = session.tick(0.016);
assert!(distance > Pixels::ZERO);Structs§
- Autoscroll
- Middle-click autoscroll session anchored to a window position.
- Scroll
Room - Whether a vertically scrollable region can still absorb wheel motion in the direction the user is scrolling.
- Scrollbar
Tokens - The crate’s scrollbar policy, replaceable before any window renders.
- Wheel
Accelerator - Cadence-based wheel accelerator over discrete line notches.
Enums§
- Scrollbar
Placement - Where a scrollbar sits relative to the content it scrolls.
- Scrollbar
Visibility - When a scrollable surface shows its scrollbar.
Constants§
- AUTOSCROLL_
FULL_ SPEED_ DISTANCE_ PX - Pointer distance from the anchor at which autoscroll reaches full speed.
- LINE_
HEIGHT_ PX - Pixels assumed per scroll line when converting line deltas to distances,
matching gpui’s
Listelement conversion. - MAX_
AUTOSCROLL_ SPEED_ PX_ PER_ SEC - Maximum autoscroll speed in pixels per second at or beyond full distance.
- WHEEL_
ACCEL_ DECAY_ SECONDS - Seconds without a notch after which cadence decays back to rest.
- WHEEL_
ACCEL_ MAX_ MULTIPLIER - Peak wheel acceleration multiplier once cadence saturates.
- WHEEL_
ACCEL_ NOTCHES_ TO_ FULL - Consecutive same-direction notches before acceleration reaches full strength. Windows conventions ramp over a handful of notches.
- WHEEL_
FAST_ SENSITIVITY - Multiplier applied to wheel line deltas while Alt is held, matching Zed’s
editor
fast_scroll_sensitivityconvention. - WHEEL_
SENSITIVITY - Base multiplier applied to wheel line deltas, matching Zed’s editor
scroll_sensitivitydefault of 1.0.