Skip to main content

LayoutResponse

Struct LayoutResponse 

Source
pub struct LayoutResponse {
    pub size: Size,
    pub flex: f32,
    pub min: Size,
    pub shrink: f32,
}
Expand description

A widget’s reply to a parent’s layout query.

Carries four quantities that together describe how the widget participates in a stack’s space distribution along the layout’s main axis:

  • size — the widget’s wanted/ideal size; the floor for growth.
  • flex — positive-slack grow weight. 0.0 = rigid (no claim on surplus); > 0.0 = wants a share of surplus proportional to its weight.
  • min — the hard floor for compression. A parent must never shrink the widget below this. Defaults to size (i.e. “I do not shrink”).
  • shrink — negative-slack shrink weight. 0.0 = will not compress (the widget overflows before it shrinks); > 0.0 = absorbs a share of an over-constraint deficit proportional to its weight, down to min.

flex and shrink are independent — as in CSS flexbox (flex-grow vs flex-shrink), a widget may grow but not shrink, or shrink but not grow. Most widgets just return a Size; the From<Size> impl wraps it as fully rigid (flex = 0, shrink = 0, min = size). Grow-bearing widgets (Spacer, Expand) use LayoutResponse::flexible; shrink-bearing ones (Shrinkable, single-line TextWidget) use LayoutResponse::shrinkable.

Fields§

§size: Size§flex: f32§min: Size§shrink: f32

Implementations§

Source§

impl LayoutResponse

Source

pub const ZERO: Self

Source

pub fn rigid(size: Size) -> Self

A fully rigid response: wanted size, no growth, no compression (min == size).

Source

pub fn flexible(size: Size, flex: f32) -> Self

A grow-bearing response: wanted size with grow weight flex. Does not shrink (min == size).

Source

pub fn shrinkable(size: Size, min: Size, shrink: f32) -> Self

A shrink-bearing response: wanted size, compressible down to min with shrink weight shrink. Does not grow (flex == 0). min is clamped componentwise to be no larger than size.

Source

pub fn with_flex(self, flex: f32) -> Self

Builder: set the grow weight on an existing response.

Source

pub fn with_shrink(self, shrink: f32) -> Self

Builder: set the shrink weight on an existing response.

Source

pub fn with_min(self, min: Size) -> Self

Builder: set the compression floor (clamped componentwise ≤ size).

Trait Implementations§

Source§

impl Clone for LayoutResponse

Source§

fn clone(&self) -> LayoutResponse

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for LayoutResponse

Source§

impl Debug for LayoutResponse

Source§

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

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

impl From<Size> for LayoutResponse

Source§

fn from(size: Size) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for LayoutResponse

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LayoutResponse

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

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.