Skip to main content

Constraints

Struct Constraints 

Source
pub struct Constraints {
    pub width: WidthSpec,
    pub height: HeightSpec,
}
Expand description

Size constraints for layout computation.

Holds a WidthSpec and a HeightSpec for the two axes. Use the builder methods on Constraints to set individual bounds in a fluent style; the builders pick the appropriate variant for you.

§Example

use slt::Constraints;

let c = Constraints::default().min_w(10).max_w(40);

Fields§

§width: WidthSpec

Width specification.

§height: HeightSpec

Height specification.

Implementations§

Source§

impl Constraints

Source

pub const fn min_w(self, min_width: u32) -> Self

Set the minimum width constraint.

If the current variant is WidthSpec::MinMax, updates only the min side. Otherwise replaces the variant with MinMax { min: min_width, max: u32::MAX }.

Source

pub const fn max_w(self, max_width: u32) -> Self

Set the maximum width constraint.

If the current variant is WidthSpec::MinMax, updates only the max side. Otherwise replaces the variant with MinMax { min: 0, max: max_width }.

Source

pub const fn min_h(self, min_height: u32) -> Self

Set the minimum height constraint.

If the current variant is HeightSpec::MinMax, updates only the min side. Otherwise replaces the variant with MinMax { min: min_height, max: u32::MAX }.

Source

pub const fn max_h(self, max_height: u32) -> Self

Set the maximum height constraint.

If the current variant is HeightSpec::MinMax, updates only the max side. Otherwise replaces the variant with MinMax { min: 0, max: max_height }.

Source

pub const fn w_minmax(self, min: u32, max: u32) -> Self

Set min and max width together.

Equivalent to chaining min_w(min) and max_w(max) but in a single call, replacing the variant with WidthSpec::MinMax.

Source

pub const fn h_minmax(self, min: u32, max: u32) -> Self

Set min and max height together.

Source

pub const fn w(self, width: u32) -> Self

Set a fixed width (replaces any existing width spec).

Source

pub const fn h(self, height: u32) -> Self

Set a fixed height (replaces any existing height spec).

Source

pub const fn w_pct(self, pct: u8) -> Self

Set width as a percentage (0..=100) of the parent container.

Source

pub const fn h_pct(self, pct: u8) -> Self

Set height as a percentage (0..=100) of the parent container.

Source

pub const fn w_ratio(self, num: u16, den: u16) -> Self

Set width as an exact integer fraction of the parent (numerator, denominator).

w_ratio(1, 3) produces area / 3 — floor division. For area = 80, num = 1, den = 326.

Source

pub const fn h_ratio(self, num: u16, den: u16) -> Self

Set height as an exact integer fraction of the parent (numerator, denominator).

h_ratio(1, 3) produces area / 3 — floor division.

Source

pub const fn min_width(&self) -> Option<u32>

Minimum width derived from the current WidthSpec.

Returns Some(n) for WidthSpec::Fixed (both min and max are n) and for WidthSpec::MinMax when the min side is non-zero. Returns None for WidthSpec::Auto, WidthSpec::Pct, WidthSpec::Ratio, and for MinMax { min: 0, .. } (sentinel for “no minimum”).

Source

pub const fn max_width(&self) -> Option<u32>

Maximum width derived from the current WidthSpec.

Returns Some(n) for WidthSpec::Fixed and for WidthSpec::MinMax when the max side is not the sentinel u32::MAX. Returns None otherwise.

Source

pub const fn min_height(&self) -> Option<u32>

Minimum height derived from the current HeightSpec.

Mirror of min_width for the cross axis.

Source

pub const fn max_height(&self) -> Option<u32>

Maximum height derived from the current HeightSpec.

Mirror of max_width for the cross axis.

Source

pub const fn width_pct(&self) -> Option<u8>

Width percentage if the variant is WidthSpec::Pct.

Source

pub const fn height_pct(&self) -> Option<u8>

Height percentage if the variant is HeightSpec::Pct.

Source

pub fn set_min_width(&mut self, value: Option<u32>)

Set the minimum width as Option<u32>.

Promotes the variant to WidthSpec::MinMax preserving any existing max side. Passing None clears the minimum (sets it to 0); if the resulting MinMax has no effective bounds (min == 0 and max == u32::MAX) the variant collapses back to WidthSpec::Auto.

Prefer Constraints::min_w when you own the value; this setter is for in-place mutation through &mut Constraints.

Source

pub fn set_max_width(&mut self, value: Option<u32>)

Set the maximum width as Option<u32>.

Source

pub fn set_min_height(&mut self, value: Option<u32>)

Set the minimum height as Option<u32>.

Source

pub fn set_max_height(&mut self, value: Option<u32>)

Set the maximum height as Option<u32>.

Source

pub fn set_width_pct(&mut self, value: Option<u8>)

Set the width percentage as Option<u8>.

Source

pub fn set_height_pct(&mut self, value: Option<u8>)

Set the height percentage as Option<u8>.

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() -> Constraints

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

impl<'de> Deserialize<'de> for Constraints

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Hash for Constraints

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

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,