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: f32Current vertical scroll offset (negative = scrolled down)
velocity_y: f32Current vertical velocity (pixels per second)
offset_x: f32Current horizontal scroll offset (negative = scrolled right)
velocity_x: f32Current horizontal velocity (pixels per second)
state: ScrollStateCurrent FSM state
content_height: f32Content height (calculated from children)
viewport_height: f32Viewport height
content_width: f32Content width (calculated from children)
viewport_width: f32Viewport width
config: ScrollConfigConfiguration
scrollbar_state: ScrollbarStateCurrent scrollbar interaction state
scrollbar_opacity: f32Current scrollbar opacity (0.0 to 1.0, animated)
area_hovered: boolWhether the scroll area is being hovered
idle_time: f32Time accumulator since last scroll activity (seconds)
thumb_drag_start_y: f32Vertical scrollbar thumb drag start position (mouse Y)
thumb_drag_start_x: f32Horizontal scrollbar thumb drag start position (mouse X)
thumb_drag_start_scroll_y: f32Scroll offset at drag start (Y)
thumb_drag_start_scroll_x: f32Scroll offset at drag start (X)
Implementations§
Source§impl ScrollPhysics
impl ScrollPhysics
Sourcepub fn new(config: ScrollConfig) -> ScrollPhysics
pub fn new(config: ScrollConfig) -> ScrollPhysics
Create new physics with given config
Sourcepub fn with_scheduler(
config: ScrollConfig,
scheduler: &Arc<Mutex<AnimationScheduler>>,
) -> ScrollPhysics
pub fn with_scheduler( config: ScrollConfig, scheduler: &Arc<Mutex<AnimationScheduler>>, ) -> ScrollPhysics
Create new physics with scheduler for animation-driven bounce
Sourcepub fn set_scheduler(&mut self, scheduler: &Arc<Mutex<AnimationScheduler>>)
pub fn set_scheduler(&mut self, scheduler: &Arc<Mutex<AnimationScheduler>>)
Set the animation scheduler (for spring-based bounce animation)
Sourcepub fn min_offset_y(&self) -> f32
pub fn min_offset_y(&self) -> f32
Maximum vertical scroll offset (0 = top edge)
Sourcepub fn max_offset_y(&self) -> f32
pub fn max_offset_y(&self) -> f32
Minimum vertical scroll offset (negative, at bottom edge)
Sourcepub fn min_offset_x(&self) -> f32
pub fn min_offset_x(&self) -> f32
Maximum horizontal scroll offset (0 = left edge)
Sourcepub fn max_offset_x(&self) -> f32
pub fn max_offset_x(&self) -> f32
Minimum horizontal scroll offset (negative, at right edge)
Sourcepub fn is_overscrolling_y(&self) -> bool
pub fn is_overscrolling_y(&self) -> bool
Check if currently overscrolling vertically (past bounds)
Sourcepub fn is_overscrolling_x(&self) -> bool
pub fn is_overscrolling_x(&self) -> bool
Check if currently overscrolling horizontally (past bounds)
Sourcepub fn is_overscrolling(&self) -> bool
pub fn is_overscrolling(&self) -> bool
Check if currently overscrolling in any direction
Sourcepub fn overscroll_amount_y(&self) -> f32
pub fn overscroll_amount_y(&self) -> f32
Get amount of vertical overscroll (positive at top, negative at bottom)
Sourcepub fn overscroll_amount_x(&self) -> f32
pub fn overscroll_amount_x(&self) -> f32
Get amount of horizontal overscroll (positive at left, negative at right)
Sourcepub fn apply_scroll_delta(&mut self, delta_x: f32, delta_y: f32)
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.
Sourcepub fn apply_touch_scroll_delta(
&mut self,
delta_x: f32,
delta_y: f32,
current_time: f64,
)
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()).
Sourcepub fn on_scroll_end(&mut self)
pub fn on_scroll_end(&mut self)
Called when scroll gesture ends - start momentum/bounce
Sourcepub fn on_gesture_end(&mut self)
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.
Sourcepub fn tick(&mut self, dt: f32) -> bool
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.
Sourcepub fn is_animating(&self) -> bool
pub fn is_animating(&self) -> bool
Check if animation is active
Sourcepub fn set_direction(&mut self, direction: ScrollDirection)
pub fn set_direction(&mut self, direction: ScrollDirection)
Set the scroll direction
Sourcepub fn scroll_to_animated(&mut self, target_x: f32, target_y: f32)
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.
Sourcepub fn on_area_hover_enter(&mut self)
pub fn on_area_hover_enter(&mut self)
Called when scroll area is hovered
Sourcepub fn on_area_hover_leave(&mut self)
pub fn on_area_hover_leave(&mut self)
Called when scroll area hover ends
Sourcepub fn on_scrollbar_track_hover(&mut self)
pub fn on_scrollbar_track_hover(&mut self)
Called when scrollbar track is hovered
Sourcepub fn on_scrollbar_thumb_hover(&mut self)
pub fn on_scrollbar_thumb_hover(&mut self)
Called when scrollbar thumb is hovered
Sourcepub fn on_scrollbar_hover_leave(&mut self)
pub fn on_scrollbar_hover_leave(&mut self)
Called when scrollbar hover ends (mouse leaves track/thumb)
Sourcepub fn on_scrollbar_drag_start(&mut self, mouse_x: f32, mouse_y: f32)
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 positionmouse_y- Current mouse Y position
Sourcepub fn on_scrollbar_drag_end(&mut self)
pub fn on_scrollbar_drag_end(&mut self)
Called when scrollbar thumb drag ends
Sourcepub fn on_scroll_activity(&mut self)
pub fn on_scroll_activity(&mut self)
Called when scroll activity occurs (shows scrollbar in Auto mode)
Sourcepub fn tick_scrollbar(&mut self, dt: f32) -> bool
pub fn tick_scrollbar(&mut self, dt: f32) -> bool
Sourcepub fn thumb_dimensions_y(&self) -> (f32, f32)
pub fn thumb_dimensions_y(&self) -> (f32, f32)
Calculate thumb dimensions for vertical scrollbar
§Returns
(thumb_height, thumb_y_position) in pixels
Sourcepub fn thumb_dimensions_x(&self) -> (f32, f32)
pub fn thumb_dimensions_x(&self) -> (f32, f32)
Calculate thumb dimensions for horizontal scrollbar
§Returns
(thumb_width, thumb_x_position) in pixels
Sourcepub fn can_scroll_y(&self) -> bool
pub fn can_scroll_y(&self) -> bool
Check if content is scrollable vertically
Sourcepub fn can_scroll_x(&self) -> bool
pub fn can_scroll_x(&self) -> bool
Check if content is scrollable horizontally
Sourcepub fn hit_test_scrollbar(
&self,
local_x: f32,
local_y: f32,
) -> ScrollbarHitResult
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.
Sourcepub fn on_scrollbar_pointer_down(&mut self, local_x: f32, local_y: f32) -> bool
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).
Sourcepub fn on_scrollbar_pointer_move(
&mut self,
local_x: f32,
local_y: f32,
) -> Option<(f32, f32)>
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.
Sourcepub fn on_scrollbar_pointer_up(&mut self)
pub fn on_scrollbar_pointer_up(&mut self)
Handle pointer up during scrollbar drag
Sourcepub fn scrollbar_render_info(&self) -> ScrollbarRenderInfo
pub fn scrollbar_render_info(&self) -> ScrollbarRenderInfo
Get current scrollbar render info
Trait Implementations§
Source§impl Default for ScrollPhysics
impl Default for ScrollPhysics
Source§fn default() -> ScrollPhysics
fn default() -> ScrollPhysics
Auto Trait Implementations§
impl Freeze for ScrollPhysics
impl RefUnwindSafe for ScrollPhysics
impl Send for ScrollPhysics
impl Sync for ScrollPhysics
impl Unpin for ScrollPhysics
impl UnsafeUnpin for ScrollPhysics
impl UnwindSafe for ScrollPhysics
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.