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 tosize(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 tomin.
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: f32Implementations§
Source§impl LayoutResponse
impl LayoutResponse
pub const ZERO: Self
Sourcepub fn rigid(size: Size) -> Self
pub fn rigid(size: Size) -> Self
A fully rigid response: wanted size, no growth, no compression
(min == size).
Sourcepub fn flexible(size: Size, flex: f32) -> Self
pub fn flexible(size: Size, flex: f32) -> Self
A grow-bearing response: wanted size with grow weight flex. Does
not shrink (min == size).
Sourcepub fn shrinkable(size: Size, min: Size, shrink: f32) -> Self
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.
Sourcepub fn with_flex(self, flex: f32) -> Self
pub fn with_flex(self, flex: f32) -> Self
Builder: set the grow weight on an existing response.
Sourcepub fn with_shrink(self, shrink: f32) -> Self
pub fn with_shrink(self, shrink: f32) -> Self
Builder: set the shrink weight on an existing response.
Trait Implementations§
Source§impl Clone for LayoutResponse
impl Clone for LayoutResponse
Source§fn clone(&self) -> LayoutResponse
fn clone(&self) -> LayoutResponse
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more