pub struct AppBarCollapse { /* private fields */ }Expand description
The collapse geometry of one sliver_app_bar configuration: the pure
mapping between an app’s scroll offset, the bar’s collapse fraction, and the
band it occupies.
Every method is clamp-disciplined and NaN-safe — a non-finite input resolves to the resting (expanded) end rather than propagating.
use frust_material::{AppBarCollapse, AppBarDensity, AppBarVariant};
let geometry = AppBarCollapse::new(AppBarVariant::Large, AppBarDensity::Regular, true);
assert_eq!(geometry.expanded_height(), 152.0);
assert_eq!(geometry.collapsed_height(), 64.0);
// A pinned bar bottoms out at its collapsed band, 88px of scroll later.
assert_eq!(geometry.travel(), 88.0);
assert_eq!(geometry.height(0.0), 152.0);
assert_eq!(geometry.height(1.0), 64.0);
assert_eq!(geometry.fraction_for_offset(44.0), 0.5);
// Past the end, and off the map, both clamp.
assert_eq!(geometry.fraction_for_offset(1_000.0), 1.0);
assert_eq!(geometry.fraction_for_offset(f64::NAN), 0.0);Implementations§
Source§impl AppBarCollapse
impl AppBarCollapse
Sourcepub const fn new(
variant: AppBarVariant,
density: AppBarDensity,
pinned: bool,
) -> Self
pub const fn new( variant: AppBarVariant, density: AppBarDensity, pinned: bool, ) -> Self
The geometry of a variant bar at density, bottoming out at its
collapsed band when pinned and at zero height otherwise.
Sourcepub const fn expanded_height(&self) -> f64
pub const fn expanded_height(&self) -> f64
The band at collapse 0.0, in logical px.
Sourcepub const fn collapsed_height(&self) -> f64
pub const fn collapsed_height(&self) -> f64
The collapsed band — the top row’s own height, in logical px. A pinned bar bottoms out here; an unpinned one keeps shrinking past it.
Sourcepub const fn min_height(&self) -> f64
pub const fn min_height(&self) -> f64
The band at collapse 1.0, in logical px: the collapsed band when
pinned, 0.0 otherwise.
Sourcepub fn travel(&self) -> f64
pub fn travel(&self) -> f64
The scroll distance, in logical px, that carries this bar from fully expanded to fully collapsed — never negative.
Sourcepub fn fraction_for_offset(&self, offset: f64) -> f64
pub fn fraction_for_offset(&self, offset: f64) -> f64
The collapse fraction a scroll offset (a ScrollInfo’s
own clamped offset) maps to, in [0, 1].
A bar with no travel at all (AppBarVariant::Small, pinned) reports
1.0 for any positive offset and 0.0 at rest — it has no expanded
state to leave, so the answer is only ever cosmetic.
Sourcepub fn height(&self, collapse: f64) -> f64
pub fn height(&self, collapse: f64) -> f64
The band this bar occupies at collapse fraction collapse, in logical
px — linear between Self::expanded_height and Self::min_height.
Sourcepub fn headline(&self, collapse: f64) -> f64
pub fn headline(&self, collapse: f64) -> f64
How far the headline has collapsed at collapse fraction collapse, in
[0, 1]: 0.0 is the expanded headline (bottom-anchored,
headlineSmall), 1.0 the collapsed one (in the top row, titleLarge).
This is not Self::height’s own fraction: an unpinned bar keeps
shrinking after the headline has fully collapsed, so the headline
saturates first.
Trait Implementations§
Source§impl Clone for AppBarCollapse
impl Clone for AppBarCollapse
impl Copy for AppBarCollapse
Source§impl Debug for AppBarCollapse
impl Debug for AppBarCollapse
Source§impl PartialEq for AppBarCollapse
impl PartialEq for AppBarCollapse
impl StructuralPartialEq for AppBarCollapse
Auto Trait Implementations§
impl Freeze for AppBarCollapse
impl RefUnwindSafe for AppBarCollapse
impl Send for AppBarCollapse
impl Sync for AppBarCollapse
impl Unpin for AppBarCollapse
impl UnsafeUnpin for AppBarCollapse
impl UnwindSafe for AppBarCollapse
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.