Skip to main content

Constraints

Struct Constraints 

Source
pub struct Constraints {
    pub min_width: u16,
    pub min_height: u16,
    /* private fields */
}
Expand description

Constraints are used to ensure that a widget doesn’t size it self outside of a set of given bounds. A constraint can be tight, meaning then minimum and maximum width / height are the same.

Fields§

§min_width: u16

Minimum width.

§min_height: u16

Minimum height.

Implementations§

Source§

impl Constraints

Source

pub const MAX: Self

Source

pub const ZERO: Self

Source

pub fn max_height(&self) -> u16

Source

pub fn max_width(&self) -> u16

Source

pub fn sub_max_width(&mut self, width: u16)

Subtract width from the max width, as long as the width isn’t unbounded.

Source

pub fn sub_max_height(&mut self, height: u16)

Subtract height from the max height, as long as the height isn’t unbounded.

Source

pub fn new( max_width: impl Into<Option<u16>>, max_height: impl Into<Option<u16>>, ) -> Self

Create a set of constraints with a given max width / height. If None is passed for either max_width and / or max_height then this is qualified as “unbounded” constraints.

The min_width and min_height are zero by default.

If the min_width and the max_width are the same the constraints are considered “tight”.

Source

pub fn unbounded() -> Self

Create unbounded constraints.

Source

pub fn unbound_height(&mut self)

Create unbounded height

Source

pub fn unbound_width(&mut self)

Create unbounded width

Source

pub fn is_unbounded(&self) -> bool

Returns true if the width and height is unbounded.

Source

pub fn is_width_unbounded(&self) -> bool

Returns true if the width is unbounded.

Source

pub fn is_height_unbounded(&self) -> bool

Returns true if the height is unbounded.

Source

pub fn is_width_tight(&self) -> bool

Returns true if the min_width and max_width are the same.

Source

pub fn is_height_tight(&self) -> bool

Returns true if the min_height and max_height are the same.

Source

pub fn make_width_tight(&mut self, width: u16)

Make the width constraint tight.

let mut constraints = Constraints::new(10, 10);
constraints.make_width_tight(constraints.max_width());
Source

pub fn make_height_tight(&mut self, height: u16)

Make the height constraint tight.

let mut constraints = Constraints::new(10, 10);
constraints.make_height_tight(constraints.max_height());
Source

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

Source

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

Source

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

Source

pub fn set_max_width(&mut self, width: u16)

This function does not verify anything, but simply sets the max width. There is no check to see if the max width is smaller than the min width here.

Source

pub fn set_max_height(&mut self, height: u16)

This function does not verify anything, but simply sets the max height. There is no check to see if the max height is smaller than the min height here.

Source

pub fn div_assign_max_width(self, count: u16, overflow: u16) -> Self

Source

pub fn div_assign_max_height(self, count: u16, overflow: u16) -> Self

Source

pub fn has_zero_dimension(&self) -> bool

If either the max width or max height are zero then nothing can be laid out within the given constraint.

Source

pub fn max_size(&self) -> Size

Get a size from the max width / height

Trait Implementations§

Source§

impl Clone for Constraints

Source§

fn clone(&self) -> Constraints

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Constraints

Source§

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

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

impl Default for Constraints

Source§

fn default() -> Self

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

impl From<Region> for Constraints

Source§

fn from(value: Region) -> Self

Converts to this type from the input type.
Source§

impl From<Size> for Constraints

Source§

fn from(value: Size) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Constraints

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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

impl Copy for Constraints

Source§

impl Eq for Constraints

Source§

impl StructuralPartialEq for Constraints

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<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> 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> 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 = Infallible

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

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

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.