Skip to main content

BoxConstraints

Struct BoxConstraints 

Source
pub struct BoxConstraints {
    pub min_width: f64,
    pub max_width: f64,
    pub min_height: f64,
    pub max_height: f64,
}
Expand description

Immutable layout constraints for RenderBox layout.

A Size respects a BoxConstraints if, and only if, all of the following relations hold:

Fields§

§min_width: f64

The minimum width that satisfies the constraints.

§max_width: f64

The maximum width that satisfies the constraints.

Might be f64::INFINITY.

§min_height: f64

The minimum height that satisfies the constraints.

§max_height: f64

The maximum height that satisfies the constraints.

Might be f64::INFINITY.

Implementations§

Source§

impl BoxConstraints

Source

pub const fn new() -> BoxConstraints

Creates box constraints with the given constraints.

Source

pub const fn min_width(self, value: f64) -> BoxConstraints

Sets min_width.

Source

pub const fn max_width(self, value: f64) -> BoxConstraints

Sets max_width.

Source

pub const fn min_height(self, value: f64) -> BoxConstraints

Sets min_height.

Source

pub const fn max_height(self, value: f64) -> BoxConstraints

Sets max_height.

Source

pub fn tight(size: Size) -> BoxConstraints

Creates box constraints that is respected only by the given size.

Source

pub const fn tight_for( width: Option<f64>, height: Option<f64>, ) -> BoxConstraints

Creates box constraints that require the given width or height.

Source

pub const fn tight_for_finite(width: f64, height: f64) -> BoxConstraints

Creates box constraints that require the given width or height, except if they are infinite.

Source

pub fn loose(size: Size) -> BoxConstraints

Creates box constraints that forbid sizes larger than the given size.

Source

pub const fn expand(width: Option<f64>, height: Option<f64>) -> BoxConstraints

Creates box constraints that expand to fill another box constraints.

Source

pub const fn from_view_constraints( constraints: ViewConstraints, ) -> BoxConstraints

Creates box constraints that match the given view constraints.

Source

pub const fn copy_with(self) -> BoxConstraints

Creates a copy of this box constraints. Chain field replacements.

Source

pub fn deflate(self, edges: EdgeInsetsGeometry) -> BoxConstraints

Returns new box constraints that are smaller by the given edge dimensions.

Source

pub fn loosen(self) -> BoxConstraints

Returns new box constraints that remove the minimum width and height requirements.

Source

pub fn enforce(self, constraints: BoxConstraints) -> BoxConstraints

Returns new box constraints that respect the given constraints while being as close as possible to the original constraints.

Source

pub fn tighten(self, width: Option<f64>, height: Option<f64>) -> BoxConstraints

Returns new box constraints with a tight width and/or height as close to the given width and height as possible while still respecting the original box constraints.

Source

pub const fn flipped(self) -> BoxConstraints

A box constraints with the width and height constraints flipped.

Source

pub const fn width_constraints(self) -> BoxConstraints

Returns box constraints with the same width constraints but with unconstrained height.

Source

pub const fn height_constraints(self) -> BoxConstraints

Returns box constraints with the same height constraints but with unconstrained width.

Source

pub fn constrain_width(self, width: f64) -> f64

Returns the width that both satisfies the constraints and is as close as possible to the given width.

Source

pub fn constrain_height(self, height: f64) -> f64

Returns the height that both satisfies the constraints and is as close as possible to the given height.

Source

pub fn constrain(self, size: Size) -> Size

Returns the size that both satisfies the constraints and is as close as possible to the given size.

Source

pub fn constrain_dimensions(self, width: f64, height: f64) -> Size

Returns the size that both satisfies the constraints and is as close as possible to the given width and height.

Source

pub fn constrain_size_and_attempt_to_preserve_aspect_ratio( self, size: Size, ) -> Size

Returns a size that attempts to meet the following conditions, in order:

  • The size must satisfy these constraints.
  • The aspect ratio of the returned size matches the aspect ratio of the given size.
  • The returned size is as big as possible while still being equal to or smaller than the given size.
Source

pub fn biggest(self) -> Size

The biggest size that satisfies the constraints.

Source

pub fn smallest(self) -> Size

The smallest size that satisfies the constraints.

Source

pub fn has_tight_width(self) -> bool

Whether there is exactly one width value that satisfies the constraints.

Source

pub fn has_tight_height(self) -> bool

Whether there is exactly one height value that satisfies the constraints.

Source

pub fn has_bounded_width(self) -> bool

Whether there is an upper bound on the maximum width.

Source

pub fn has_bounded_height(self) -> bool

Whether there is an upper bound on the maximum height.

Source

pub fn has_infinite_width(self) -> bool

Whether the width constraint is infinite.

Source

pub fn has_infinite_height(self) -> bool

Whether the height constraint is infinite.

Source

pub fn is_satisfied_by(self, size: Size) -> bool

Whether the given size satisfies the constraints.

Source

pub fn truncating_div(self, factor: f64) -> BoxConstraints

Scales each constraint parameter by the inverse of the given factor, rounded toward zero (Dart ~/).

Source

pub fn lerp( a: Option<BoxConstraints>, b: Option<BoxConstraints>, t: f64, ) -> Option<BoxConstraints>

Linearly interpolate between two box constraints.

If either is none, this function interpolates from a BoxConstraints object whose fields are all set to 0.0.

Source

pub fn normalize(self) -> BoxConstraints

Returns a box constraints that is_normalized.

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 Constraints for BoxConstraints

Source§

fn is_tight(&self) -> bool

Whether there is exactly one size possible given these constraints.
Source§

fn is_normalized(&self) -> bool

Whether the constraint is expressed in a consistent manner.
Source§

fn debug_assert_is_valid(&self, is_applied_constraint: bool) -> bool

Asserts that the constraints are valid. 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 Default for BoxConstraints

Source§

fn default() -> BoxConstraints

Returns the “default value” for a type. Read more
Source§

impl Display for BoxConstraints

Source§

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

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

impl Div<f64> for BoxConstraints

Source§

type Output = BoxConstraints

The resulting type after applying the / operator.
Source§

fn div(self, factor: f64) -> BoxConstraints

Performs the / operation. Read more
Source§

impl Eq for BoxConstraints

Source§

impl Hash for BoxConstraints

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Mul<f64> for BoxConstraints

Source§

type Output = BoxConstraints

The resulting type after applying the * operator.
Source§

fn mul(self, factor: f64) -> BoxConstraints

Performs the * operation. Read more
Source§

impl PartialEq for BoxConstraints

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Rem<f64> for BoxConstraints

Source§

type Output = BoxConstraints

The resulting type after applying the % operator.
Source§

fn rem(self, value: f64) -> BoxConstraints

Performs the % operation. Read more

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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,