pub struct ToolbarScrollHide { /* private fields */ }Expand description
Upstream’s M3EToolbarVisibilityController as a pure value: the scroll
accumulation, clamp, and settle rule an app runs from its own
on_scroll, with the ticker left to the
widget (see the module docs’ scroll-hide section).
offset is always ≤ 0 and clamped into [offset_limit, 0].
use frust_material::{TOOLBAR_HEIGHT, ToolbarScrollHide, TOOLBAR_SCREEN_OFFSET};
// The measured limit is `-(extent + screenOffset)`.
let mut hide = ToolbarScrollHide::for_bar(TOOLBAR_HEIGHT);
assert_eq!(hide.offset_limit(), -(TOOLBAR_HEIGHT + TOOLBAR_SCREEN_OFFSET));
// Scrolling down hides; scrolling back up returns.
hide.scroll(40.0);
assert_eq!(hide.offset(), -40.0);
hide.scroll(-15.0);
assert_eq!(hide.offset(), -25.0);
// A fling past the velocity threshold commits to its direction.
assert!(!hide.settle(400.0));
assert!(hide.is_hidden());Implementations§
Source§impl ToolbarScrollHide
impl ToolbarScrollHide
Sourcepub fn new(exit_extent: f64) -> Self
pub fn new(exit_extent: f64) -> Self
A controller with a fixed exit distance — upstream’s exitExtent,
which pins offsetLimit to -|extent|. A non-finite exit_extent
(NaN or ±∞) degrades to a resting 0.0 exit distance rather than
carrying a non-finite limit into Self::set_offset’s clamp — see
the module docs’ clamp discipline.
Sourcepub fn for_bar(cross_extent: f64) -> Self
pub fn for_bar(cross_extent: f64) -> Self
A controller whose exit distance is measured off the bar — upstream’s
M3EToolbarMeasureSize rule, -(cross_extent + screenOffset). A
non-finite cross_extent degrades the same way Self::new’s own
guard does — this delegates to it, so the guard applies whether the
non-finite value reaches new directly or through here.
Sourcepub fn offset_limit(&self) -> f64
pub fn offset_limit(&self) -> f64
The most negative translation this controller allows.
Sourcepub fn scroll(&mut self, delta: f64)
pub fn scroll(&mut self, delta: f64)
Consume a scroll delta (positive scrolling down) — upstream’s
_updateOffset’s offset -= delta, clamped. A non-finite delta is
ignored rather than propagated into the offset.
Sourcepub fn collapsed_fraction(&self) -> f64
pub fn collapsed_fraction(&self) -> f64
How far hidden the bar is, 0.0 fully visible through 1.0 fully
hidden — upstream’s collapsedFraction.
Whether the bar is fully off-screen — upstream’s isHidden.
Sourcepub fn settle(&mut self, velocity: f64) -> bool
pub fn settle(&mut self, velocity: f64) -> bool
Settle after a fling at velocity (positive scrolling down), reporting
whether the bar ends up visible — upstream’s settle: past
TOOLBAR_SETTLE_VELOCITY the direction of travel wins, otherwise the
nearer end does. Already-settled at either end, nothing moves.
Trait Implementations§
Source§impl Clone for ToolbarScrollHide
impl Clone for ToolbarScrollHide
impl Copy for ToolbarScrollHide
Source§impl Debug for ToolbarScrollHide
impl Debug for ToolbarScrollHide
Source§impl PartialEq for ToolbarScrollHide
impl PartialEq for ToolbarScrollHide
impl StructuralPartialEq for ToolbarScrollHide
Auto Trait Implementations§
impl Freeze for ToolbarScrollHide
impl RefUnwindSafe for ToolbarScrollHide
impl Send for ToolbarScrollHide
impl Sync for ToolbarScrollHide
impl Unpin for ToolbarScrollHide
impl UnsafeUnpin for ToolbarScrollHide
impl UnwindSafe for ToolbarScrollHide
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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.