Skip to main content

Module scrolling

Module scrolling 

Source
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.
ScrollRoom
Whether a vertically scrollable region can still absorb wheel motion in the direction the user is scrolling.
ScrollbarTokens
The crate’s scrollbar policy, replaceable before any window renders.
WheelAccelerator
Cadence-based wheel accelerator over discrete line notches.

Enums§

ScrollbarPlacement
Where a scrollbar sits relative to the content it scrolls.
ScrollbarVisibility
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 List element 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_sensitivity convention.
WHEEL_SENSITIVITY
Base multiplier applied to wheel line deltas, matching Zed’s editor scroll_sensitivity default of 1.0.