Skip to main content

BoxConstraints

Struct BoxConstraints 

Source
pub struct BoxConstraints { /* private fields */ }
Expand description

Constraints for layout.

The layout strategy for Masonry 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.

Implementations§

Source§

impl BoxConstraints

Source

pub const UNBOUNDED: Self

An unbounded box constraints object.

Can be satisfied by any nonnegative size.

Source

pub fn new(min: Size, max: Size) -> Self

Create a new box constraints object.

Create constraints based on minimum and maximum size.

Source

pub fn tight(size: Size) -> Self

Create a “tight” box constraints object.

A “tight” constraint can only be satisfied by a single size.

Source

pub fn loosen(&self) -> Self

Create a “loose” version of the constraints.

Make a version with zero minimum size, but the same maximum size.

Source

pub fn constrain(&self, size: impl Into<Size>) -> Size

Clamp a given size so that it fits within the constraints.

Source

pub fn max(&self) -> Size

Returns the max size of these constraints.

Source

pub fn min(&self) -> Size

Returns the min size of these constraints.

Source

pub fn is_width_bounded(&self) -> bool

Whether there is an upper bound on the width.

Source

pub fn is_height_bounded(&self) -> bool

Whether there is an upper bound on the height.

Source

pub fn bounded_or(&self, size: Size) -> Size

Return the max in each axis if bounded, else the value given in size.

Source

pub fn debug_check(&self, name: &str)

Check to see if these constraints are legit.

In Debug mode, logs a warning if BoxConstraints are invalid.

Source

pub fn shrink(&self, diff: impl Into<Size>) -> Self

Shrink min and max constraints by size

Source

pub fn contains(&self, size: impl Into<Size>) -> bool

Test whether these constraints contain the given Size.

Source

pub fn constrain_aspect_ratio(&self, aspect_ratio: f64, width: f64) -> Size

Find the Size within these BoxConstraints that minimises the difference between the returned Size’s aspect ratio and aspect_ratio, where aspect ratio is defined as height / width.

If multiple Sizes 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.

§Panics

Panics if aspect_ratio or width are NaN, infinite or negative.

Trait Implementations§

Source§

impl Clone for BoxConstraints

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for BoxConstraints

Source§

impl Debug for BoxConstraints

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for BoxConstraints

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for BoxConstraints

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AnyDebug for T
where T: Any + Debug,

Source§

fn type_name(&self) -> &'static str

Available on crate feature type_name only.
Returns the type_name of this value’s concrete type. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneAny for T
where T: Any + Clone,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more