Skip to main content

ScrollPhysics

Struct ScrollPhysics 

Source
pub struct ScrollPhysics {
Show 18 fields pub offset_y: f32, pub velocity_y: f32, pub offset_x: f32, pub velocity_x: f32, pub state: ScrollState, pub content_height: f32, pub viewport_height: f32, pub content_width: f32, pub viewport_width: f32, pub config: ScrollConfig, pub scrollbar_state: ScrollbarState, pub scrollbar_opacity: f32, pub area_hovered: bool, pub idle_time: f32, pub thumb_drag_start_y: f32, pub thumb_drag_start_x: f32, pub thumb_drag_start_scroll_y: f32, pub thumb_drag_start_scroll_x: f32, /* private fields */
}
Expand description

Internal physics state for scroll animation

Fields§

§offset_y: f32

Current vertical scroll offset (negative = scrolled down)

§velocity_y: f32

Current vertical velocity (pixels per second)

§offset_x: f32

Current horizontal scroll offset (negative = scrolled right)

§velocity_x: f32

Current horizontal velocity (pixels per second)

§state: ScrollState

Current FSM state

§content_height: f32

Content height (calculated from children)

§viewport_height: f32

Viewport height

§content_width: f32

Content width (calculated from children)

§viewport_width: f32

Viewport width

§config: ScrollConfig

Configuration

§scrollbar_state: ScrollbarState

Current scrollbar interaction state

§scrollbar_opacity: f32

Current scrollbar opacity (0.0 to 1.0, animated)

§area_hovered: bool

Whether the scroll area is being hovered

§idle_time: f32

Time accumulator since last scroll activity (seconds)

§thumb_drag_start_y: f32

Vertical scrollbar thumb drag start position (mouse Y)

§thumb_drag_start_x: f32

Horizontal scrollbar thumb drag start position (mouse X)

§thumb_drag_start_scroll_y: f32

Scroll offset at drag start (Y)

§thumb_drag_start_scroll_x: f32

Scroll offset at drag start (X)

Implementations§

Source§

impl ScrollPhysics

Source

pub fn new(config: ScrollConfig) -> ScrollPhysics

Create new physics with given config

Source

pub fn with_scheduler( config: ScrollConfig, scheduler: &Arc<Mutex<AnimationScheduler>>, ) -> ScrollPhysics

Create new physics with scheduler for animation-driven bounce

Source

pub fn set_scheduler(&mut self, scheduler: &Arc<Mutex<AnimationScheduler>>)

Set the animation scheduler (for spring-based bounce animation)

Source

pub fn min_offset_y(&self) -> f32

Maximum vertical scroll offset (0 = top edge)

Source

pub fn max_offset_y(&self) -> f32

Minimum vertical scroll offset (negative, at bottom edge)

Source

pub fn min_offset_x(&self) -> f32

Maximum horizontal scroll offset (0 = left edge)

Source

pub fn max_offset_x(&self) -> f32

Minimum horizontal scroll offset (negative, at right edge)

Source

pub fn is_overscrolling_y(&self) -> bool

Check if currently overscrolling vertically (past bounds)

Source

pub fn is_overscrolling_x(&self) -> bool

Check if currently overscrolling horizontally (past bounds)

Source

pub fn is_overscrolling(&self) -> bool

Check if currently overscrolling in any direction

Source

pub fn overscroll_amount_y(&self) -> f32

Get amount of vertical overscroll (positive at top, negative at bottom)

Source

pub fn overscroll_amount_x(&self) -> f32

Get amount of horizontal overscroll (positive at left, negative at right)

Source

pub fn apply_scroll_delta(&mut self, delta_x: f32, delta_y: f32)

Apply scroll delta (from user input)

Note: On macOS, the system already applies momentum physics to scroll events, so we don’t need to track velocity or apply our own momentum. We just apply the delta directly with bounds clamping.

When bouncing, we ignore momentum scroll events - the spring animation takes over and drives the position back to bounds.

Source

pub fn apply_touch_scroll_delta( &mut self, delta_x: f32, delta_y: f32, current_time: f64, )

Apply scroll delta from touch input with velocity tracking

This is used on mobile platforms where we need to track velocity ourselves for momentum scrolling (unlike macOS which provides it).

current_time is in milliseconds (from elapsed_ms()).

Source

pub fn on_scroll_end(&mut self)

Called when scroll gesture ends - start momentum/bounce

Source

pub fn on_gesture_end(&mut self)

Called when scroll gesture ends (finger lifted from trackpad)

If overscrolling, start bounce immediately for snappy feedback. The user expects the elastic snap-back to begin the moment they release.

Source

pub fn tick(&mut self, dt: f32) -> bool

Update scroll offsets from animation scheduler springs

Returns true if still animating, false if settled. This reads spring values from the AnimationScheduler which ticks them on a background thread at 120fps.

dt is delta time in seconds since last tick.

Source

pub fn is_animating(&self) -> bool

Check if animation is active

Source

pub fn set_direction(&mut self, direction: ScrollDirection)

Set the scroll direction

Source

pub fn scroll_to_animated(&mut self, target_x: f32, target_y: f32)

Animate scroll to a target offset using spring physics

This provides smooth animated scrolling instead of instant jumps. The spring configuration uses a snappy feel for quick but smooth transitions.

Source

pub fn on_area_hover_enter(&mut self)

Called when scroll area is hovered

Source

pub fn on_area_hover_leave(&mut self)

Called when scroll area hover ends

Source

pub fn on_scrollbar_track_hover(&mut self)

Called when scrollbar track is hovered

Source

pub fn on_scrollbar_thumb_hover(&mut self)

Called when scrollbar thumb is hovered

Source

pub fn on_scrollbar_hover_leave(&mut self)

Called when scrollbar hover ends (mouse leaves track/thumb)

Source

pub fn on_scrollbar_drag_start(&mut self, mouse_x: f32, mouse_y: f32)

Called when scrollbar thumb drag starts

§Arguments
  • mouse_x - Current mouse X position
  • mouse_y - Current mouse Y position
Source

pub fn on_scrollbar_drag(&mut self, mouse_x: f32, mouse_y: f32) -> (f32, f32)

Called during scrollbar thumb drag

§Arguments
  • mouse_x - Current mouse X position
  • mouse_y - Current mouse Y position
§Returns

New scroll offset (x, y) that should be applied

Source

pub fn on_scrollbar_drag_end(&mut self)

Called when scrollbar thumb drag ends

Source

pub fn on_scroll_activity(&mut self)

Called when scroll activity occurs (shows scrollbar in Auto mode)

Source

pub fn tick_scrollbar(&mut self, dt: f32) -> bool

Tick scrollbar animation (call from main tick)

§Arguments
  • dt - Delta time in seconds
§Returns

true if scrollbar animation is still active

Source

pub fn thumb_dimensions_y(&self) -> (f32, f32)

Calculate thumb dimensions for vertical scrollbar

§Returns

(thumb_height, thumb_y_position) in pixels

Source

pub fn thumb_dimensions_x(&self) -> (f32, f32)

Calculate thumb dimensions for horizontal scrollbar

§Returns

(thumb_width, thumb_x_position) in pixels

Source

pub fn can_scroll_y(&self) -> bool

Check if content is scrollable vertically

Source

pub fn can_scroll_x(&self) -> bool

Check if content is scrollable horizontally

Source

pub fn hit_test_scrollbar( &self, local_x: f32, local_y: f32, ) -> ScrollbarHitResult

Hit test a point against the scrollbar

Takes coordinates relative to the scroll container (local space). Returns what part of the scrollbar (if any) the point is over.

Source

pub fn on_scrollbar_pointer_down(&mut self, local_x: f32, local_y: f32) -> bool

Handle pointer down on scrollbar

Returns true if the event was handled (pointer was over scrollbar).

Source

pub fn on_scrollbar_pointer_move( &mut self, local_x: f32, local_y: f32, ) -> Option<(f32, f32)>

Handle pointer move during scrollbar drag

Returns Some((new_offset_x, new_offset_y)) if dragging, None otherwise.

Source

pub fn on_scrollbar_pointer_up(&mut self)

Handle pointer up during scrollbar drag

Source

pub fn scrollbar_render_info(&self) -> ScrollbarRenderInfo

Get current scrollbar render info

Trait Implementations§

Source§

impl Default for ScrollPhysics

Source§

fn default() -> ScrollPhysics

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> NodeState for T
where T: Send + 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get self as Any for downcasting
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get self as mutable Any for downcasting
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,