[−][src]Struct druid::BoxConstraints
Constraints for layout.
The layout strategy for druid is strongly inspired by Flutter, and this struct is similar to the Flutter BoxConstraints class.
At the moment, it represents simply a minimum and maximum size.
A widget's layout
method should choose an appropriate size that
meets these constraints.
Further, a container widget should compute appropriate constraints for each of its child widgets, and pass those down when recursing.
The constraints are always rounded away from zero to integers to enable pixel perfect layout.
Implementations
impl BoxConstraints
[src]
pub const UNBOUNDED: BoxConstraints
[src]
An unbounded box constraints object.
Can be satisfied by any nonnegative size.
pub fn new(min: Size, max: Size) -> BoxConstraints
[src]
Create a new box constraints object.
Create constraints based on minimum and maximum size.
The given sizes are also rounded away from zero, so that the layout is aligned to integers.
pub fn tight(size: Size) -> BoxConstraints
[src]
Create a "tight" box constraints object.
A "tight" constraint can only be satisfied by a single size.
The given size is also rounded away from zero, so that the layout is aligned to integers.
pub fn loosen(&self) -> BoxConstraints
[src]
Create a "loose" version of the constraints.
Make a version with zero minimum size, but the same maximum size.
pub fn constrain(&self, size: impl Into<Size>) -> Size
[src]
Clamp a given size so that it fits within the constraints.
The given size is also rounded away from zero, so that the layout is aligned to integers.
pub fn max(&self) -> Size
[src]
Returns the max size of these constraints.
pub fn min(&self) -> Size
[src]
Returns the min size of these constraints.
pub fn is_width_bounded(&self) -> bool
[src]
Whether there is an upper bound on the width.
pub fn is_height_bounded(&self) -> bool
[src]
Whether there is an upper bound on the height.
pub fn debug_check(&self, name: &str)
[src]
Check to see if these constraints are legit.
Logs a warning if BoxConstraints are invalid.
pub fn shrink(&self, diff: impl Into<Size>) -> BoxConstraints
[src]
Shrink min and max constraints by size
The given size is also rounded away from zero, so that the layout is aligned to integers.
pub fn contains(&self, size: impl Into<Size>) -> bool
[src]
Test whether these constraints contain the given Size
.
pub fn constrain_aspect_ratio(&self, aspect_ratio: f64, width: f64) -> Size
[src]
Find the Size
within these BoxConstraint
s that minimises the difference between the
returned Size
's aspect ratio and aspect_ratio
, where aspect ratio is defined as
height / width
.
If multiple Size
s give the optimal aspect_ratio
, then the one with the width
nearest
the supplied width will be used. Specifically, if width == 0.0
then the smallest possible
Size
will be chosen, and likewise if width == f64::INFINITY
, then the largest Size
will be chosen.
Use this function when maintaining an aspect ratio is more important than minimizing the distance between input and output size width and height.
Trait Implementations
impl Clone for BoxConstraints
[src]
pub fn clone(&self) -> BoxConstraints
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for BoxConstraints
[src]
impl Debug for BoxConstraints
[src]
Auto Trait Implementations
impl RefUnwindSafe for BoxConstraints
[src]
impl Send for BoxConstraints
[src]
impl Sync for BoxConstraints
[src]
impl Unpin for BoxConstraints
[src]
impl UnwindSafe for BoxConstraints
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> RoundFrom<T> for T
pub fn round_from(x: T) -> T
impl<T, U> RoundInto<U> for T where
U: RoundFrom<T>,
U: RoundFrom<T>,
pub fn round_into(self) -> U
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,