pub struct SizeConstraints {
pub min: Size,
pub preferred: Size,
pub max: Option<Size>,
}Expand description
Size constraints returned by measure operations.
Captures the full sizing semantics for a widget:
- min: Minimum usable size (content clips below this)
- preferred: Ideal size for content display
- max: Maximum useful size (no benefit beyond this)
§Invariants
The following must hold:
min.width <= preferred.width <= max.map_or(u16::MAX, |m| m.width)min.height <= preferred.height <= max.map_or(u16::MAX, |m| m.height)
§Example
use ftui_core::geometry::Size;
use ftui_widgets::SizeConstraints;
// A 10x3 text block with some flexibility
let constraints = SizeConstraints {
min: Size::new(5, 1), // Can shrink to 5 chars, 1 line
preferred: Size::new(10, 3), // Ideal display
max: Some(Size::new(20, 5)), // No benefit beyond this
};
// Clamp an allocation to these constraints
let allocated = Size::new(8, 2);
let clamped = constraints.clamp(allocated);
assert_eq!(clamped, Size::new(8, 2)); // Within range, unchangedFields§
§min: SizeMinimum size below which the widget is unusable or clips content.
preferred: SizePreferred size that best displays content.
max: Option<Size>Maximum useful size. None means unbounded (widget can use all available space).
Implementations§
Source§impl SizeConstraints
impl SizeConstraints
Sourcepub const ZERO: Self
pub const ZERO: Self
Zero constraints (no minimum, no preferred, unbounded maximum).
This is the default for widgets that fill available space.
Sourcepub const fn exact(size: Size) -> Self
pub const fn exact(size: Size) -> Self
Create constraints with exact sizing (min = preferred = max).
Use this for widgets with a fixed, known size.
Sourcepub const fn at_least(min: Size, preferred: Size) -> Self
pub const fn at_least(min: Size, preferred: Size) -> Self
Create constraints with a minimum and preferred size, unbounded maximum.
Sourcepub fn clamp(&self, size: Size) -> Size
pub fn clamp(&self, size: Size) -> Size
Clamp a given size to these constraints.
The result will be:
- At least
min.widthxmin.height - At most
max.widthxmax.height(if max is set)
§Example
use ftui_core::geometry::Size;
use ftui_widgets::SizeConstraints;
let c = SizeConstraints {
min: Size::new(5, 2),
preferred: Size::new(10, 5),
max: Some(Size::new(20, 10)),
};
// Below minimum
assert_eq!(c.clamp(Size::new(3, 1)), Size::new(5, 2));
// Within range
assert_eq!(c.clamp(Size::new(15, 7)), Size::new(15, 7));
// Above maximum
assert_eq!(c.clamp(Size::new(30, 20)), Size::new(20, 10));Sourcepub fn is_satisfied_by(&self, size: Size) -> bool
pub fn is_satisfied_by(&self, size: Size) -> bool
Check if these constraints are satisfied by the given size.
Returns true if size is within the min/max bounds.
Sourcepub fn intersect(&self, other: &SizeConstraints) -> SizeConstraints
pub fn intersect(&self, other: &SizeConstraints) -> SizeConstraints
Combine two constraints by taking the maximum minimums and minimum maximums.
Useful when a widget has multiple children and needs to satisfy all constraints.
Trait Implementations§
Source§impl Clone for SizeConstraints
impl Clone for SizeConstraints
Source§fn clone(&self) -> SizeConstraints
fn clone(&self) -> SizeConstraints
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SizeConstraints
impl Debug for SizeConstraints
Source§impl Default for SizeConstraints
impl Default for SizeConstraints
Source§impl Hash for SizeConstraints
impl Hash for SizeConstraints
Source§impl PartialEq for SizeConstraints
impl PartialEq for SizeConstraints
impl Copy for SizeConstraints
impl Eq for SizeConstraints
impl StructuralPartialEq for SizeConstraints
Auto Trait Implementations§
impl Freeze for SizeConstraints
impl RefUnwindSafe for SizeConstraints
impl Send for SizeConstraints
impl Sync for SizeConstraints
impl Unpin for SizeConstraints
impl UnsafeUnpin for SizeConstraints
impl UnwindSafe for SizeConstraints
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.