pub struct Density { /* private fields */ }Expand description
Re-export the UI crate so applications can depend on a single crate. The device pixel grid a layout measures against: how many device pixels a layout point is worth, and how the platform converts a text size.
This is Compose’s Density, and local_density is its LocalDensity.
Read it in a composable through density, which subscribes to the
composition local rather than to process-wide state, so a subtree given its
own density recomposes only what read it. Tests and goldens construct one
directly so a measurement does not depend on the machine it runs on.
Implementations§
Source§impl Density
impl Density
Sourcepub fn from_host() -> Density
pub fn from_host() -> Density
The grid the host installed on this shell.
This is the composition local’s default, not the way a composable should
read the density – use density for that, so a subtree provided its
own grid is honoured.
Sourcepub fn new(density: f32, font_scale: f32) -> Density
pub fn new(density: f32, font_scale: f32) -> Density
A grid stated outright, for a test or a golden. The setting is taken as a plain multiplier, which is what it is wherever the platform reports no conversion of its own.
Sourcepub fn with_curve(density: f32, font_scale: FontScaleCurve) -> Density
pub fn with_curve(density: f32, font_scale: FontScaleCurve) -> Density
A grid whose text size follows the platform’s own Sp conversion rather
than a multiplier. See crate::font_scale.
Sourcepub fn font_scale(self) -> f32
pub fn font_scale(self) -> f32
The user’s text size setting.
Sourcepub fn font_scale_curve(self) -> FontScaleCurve
pub fn font_scale_curve(self) -> FontScaleCurve
The conversion the platform performs for a size in Sp.
Sourcepub fn dp(self, value: f32) -> f32
pub fn dp(self, value: f32) -> f32
Dp.roundToPx(), expressed back in points: a dp length snapped to the
whole device pixel Compose would give it.
Sourcepub fn sp(self, value: f32) -> f32
pub fn sp(self, value: f32) -> f32
A text size in scale-independent pixels, snapped the same way.
Anything that must not move when the user changes their text size is
measured with Density::dp instead — that is the whole difference
between the two.
Sourcepub fn round(self, value: f32) -> f32
pub fn round(self, value: f32) -> f32
A length snapped to the nearest whole device pixel, exact halves up.
Sourcepub fn ceil(self, value: f32) -> f32
pub fn ceil(self, value: f32) -> f32
A length snapped up to a whole device pixel.
This is what a line box does with its own height, and what a container does with a content size it must not clip.
Sourcepub fn centre(self, available: f32, content: f32) -> f32
pub fn centre(self, available: f32, content: f32) -> f32
Centres content in available the way Compose does: on a whole pixel.
Arrangement.Center measures every child in whole pixels and rounds the
leading gap before placing any of them, so a column whose content is an
odd number of pixels tall starts on a pixel boundary rather than across
one. Halving in floats instead is the single easiest way to soften every
edge in a row.
Trait Implementations§
impl Copy for Density
impl StructuralPartialEq for Density
Auto Trait Implementations§
impl Freeze for Density
impl RefUnwindSafe for Density
impl Send for Density
impl Sync for Density
impl Unpin for Density
impl UnsafeUnpin for Density
impl UnwindSafe for Density
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.