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

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

pub const UNBOUNDED: BoxConstraints = BoxConstraints{ min: Size::ZERO, max: Size::new(f64::INFINITY, f64::INFINITY),}

An unbounded box constraints object.

Can be satisfied by any nonnegative size.

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

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

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

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

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

Returns the max size of these constraints.

pub fn min(&self) -> Size

Returns the min size of these constraints.

pub fn is_width_bounded(&self) -> bool

Whether there is an upper bound on the width.

pub fn is_height_bounded(&self) -> bool

Whether there is an upper bound on the height.

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

Check to see if these constraints are legit.

Logs a warning if BoxConstraints are invalid.

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

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

Test whether these constraints contain the given Size.

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.

pub fn unbound_max(&self, axis: Axis) -> BoxConstraints

Sets the max on a given axis to infinity.

pub fn unbound_max_width(&self) -> BoxConstraints

Sets max width to infinity.

pub fn unbound_max_height(&self) -> BoxConstraints

Sets max height to infinity.

pub fn shrink_max_to(&self, axis: Axis, dim: f64) -> BoxConstraints

Shrinks the max dimension on the given axis. Does NOT shrink beyond min.

pub fn shrink_max_width_to(&self, dim: f64) -> BoxConstraints

Shrinks the max width to dim. Does NOT shrink beyond min width.

pub fn shrink_max_height_to(&self, dim: f64) -> BoxConstraints

Shrinks the max height to dim. Does NOT shrink beyond min height.

Trait Implementations§

§

impl Clone for BoxConstraints

§

fn clone(&self) -> BoxConstraints

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for BoxConstraints

§

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

Formats the value using the given formatter. Read more
§

impl PartialEq<BoxConstraints> for BoxConstraints

§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Copy for BoxConstraints

§

impl StructuralPartialEq for BoxConstraints

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AnyEq for Twhere T: Any + PartialEq<T>,

§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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 Twhere U: From<T>,

const: unstable · 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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