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: WidthSpecWidth specification.
height: HeightSpecHeight specification.
Implementations§
Source§impl Constraints
impl Constraints
Sourcepub const fn min_w(self, min_width: u32) -> Self
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 }.
Sourcepub const fn max_w(self, max_width: u32) -> Self
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 }.
Sourcepub const fn min_h(self, min_height: u32) -> Self
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 }.
Sourcepub const fn max_h(self, max_height: u32) -> Self
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 }.
Sourcepub const fn w_minmax(self, min: u32, max: u32) -> Self
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.
Sourcepub const fn h(self, height: u32) -> Self
pub const fn h(self, height: u32) -> Self
Set a fixed height (replaces any existing height spec).
Sourcepub const fn w_pct(self, pct: u8) -> Self
pub const fn w_pct(self, pct: u8) -> Self
Set width as a percentage (0..=100) of the parent container.
Sourcepub const fn h_pct(self, pct: u8) -> Self
pub const fn h_pct(self, pct: u8) -> Self
Set height as a percentage (0..=100) of the parent container.
Sourcepub const fn w_ratio(self, num: u16, den: u16) -> Self
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 = 3 → 26.
Sourcepub const fn h_ratio(self, num: u16, den: u16) -> Self
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.
Sourcepub const fn min_width(&self) -> Option<u32>
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”).
Sourcepub const fn max_width(&self) -> Option<u32>
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.
Sourcepub const fn min_height(&self) -> Option<u32>
pub const fn min_height(&self) -> Option<u32>
Minimum height derived from the current HeightSpec.
Mirror of min_width for the cross axis.
Sourcepub const fn max_height(&self) -> Option<u32>
pub const fn max_height(&self) -> Option<u32>
Maximum height derived from the current HeightSpec.
Mirror of max_width for the cross axis.
Sourcepub const fn width_pct(&self) -> Option<u8>
pub const fn width_pct(&self) -> Option<u8>
Width percentage if the variant is WidthSpec::Pct.
Sourcepub const fn height_pct(&self) -> Option<u8>
pub const fn height_pct(&self) -> Option<u8>
Height percentage if the variant is HeightSpec::Pct.
Sourcepub fn set_min_width(&mut self, value: Option<u32>)
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.
Sourcepub fn set_max_width(&mut self, value: Option<u32>)
pub fn set_max_width(&mut self, value: Option<u32>)
Set the maximum width as Option<u32>.
Sourcepub fn set_min_height(&mut self, value: Option<u32>)
pub fn set_min_height(&mut self, value: Option<u32>)
Set the minimum height as Option<u32>.
Sourcepub fn set_max_height(&mut self, value: Option<u32>)
pub fn set_max_height(&mut self, value: Option<u32>)
Set the maximum height as Option<u32>.
Sourcepub fn set_width_pct(&mut self, value: Option<u8>)
pub fn set_width_pct(&mut self, value: Option<u8>)
Set the width percentage as Option<u8>.
Sourcepub fn set_height_pct(&mut self, value: Option<u8>)
pub fn set_height_pct(&mut self, value: Option<u8>)
Set the height percentage as Option<u8>.
Trait Implementations§
Source§impl Clone for Constraints
impl Clone for Constraints
Source§fn clone(&self) -> Constraints
fn clone(&self) -> Constraints
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more