pub struct FlexMeasurePolicy {
pub axis: Axis,
pub main_axis_arrangement: LinearArrangement,
pub cross_axis_alignment: CrossAxisAlignment,
}Expand description
Unified Flex layout policy that powers both Row and Column.
This policy implements Jetpack Compose’s flex layout semantics:
- Measures children with proper loose constraints (min = 0 on both axes)
- Supports weighted distribution of remaining space
- Handles bounded/unbounded main axis correctly
- Implements correct intrinsics for both axes
§Overflow Behavior
Like Jetpack Compose, this policy allows children to overflow their container bounds:
- Children can be positioned outside the parent’s measured size
- Overflowing content is rendered (unless clipped by a modifier)
- When content overflows, distribution arrangements switch to
Startto avoid negative spacing SpacedBykeeps its fixed inter-child spacing even when content overflows
Example: A Row with 300px of content in a 200px container will:
- Measure children at their natural sizes
- Detect overflow (300px > 200px)
- Switch to Start arrangement (pack children at the start)
- Position last children beyond the 200px boundary
To prevent overflow:
- Use weights for flexible sizing:
.weight(1.0, true) - Use
fillMaxWidth()/fillMaxHeight()modifiers - Design UI to fit within available space
- Add a clip modifier to hide overflowing content
§Weighted Children
When the main axis is bounded and children have weights:
- Fixed children (no weight) are measured first
- Remaining space is distributed proportionally to weights
- Each weighted child gets:
remaining * (weight / total_weight) - If
fill=true, child gets tight constraints; iffill=false, loose constraints
When the main axis is unbounded, weights are ignored (all children wrap content).
Fields§
§axis: AxisMain axis direction (Horizontal for Row, Vertical for Column)
main_axis_arrangement: LinearArrangementArrangement along the main axis
cross_axis_alignment: CrossAxisAlignmentAlignment along the cross axis (used as default for children without explicit alignment)
Implementations§
Source§impl FlexMeasurePolicy
impl FlexMeasurePolicy
pub fn new( axis: Axis, main_axis_arrangement: LinearArrangement, cross_axis_alignment: CrossAxisAlignment, ) -> Self
Sourcepub fn row(
horizontal_arrangement: LinearArrangement,
vertical_alignment: VerticalAlignment,
) -> Self
pub fn row( horizontal_arrangement: LinearArrangement, vertical_alignment: VerticalAlignment, ) -> Self
Creates a FlexMeasurePolicy for Row (horizontal main axis).
Sourcepub fn column(
vertical_arrangement: LinearArrangement,
horizontal_alignment: HorizontalAlignment,
) -> Self
pub fn column( vertical_arrangement: LinearArrangement, horizontal_alignment: HorizontalAlignment, ) -> Self
Creates a FlexMeasurePolicy for Column (vertical main axis).
Trait Implementations§
Source§impl Clone for FlexMeasurePolicy
impl Clone for FlexMeasurePolicy
Source§fn clone(&self) -> FlexMeasurePolicy
fn clone(&self) -> FlexMeasurePolicy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for FlexMeasurePolicy
impl Debug for FlexMeasurePolicy
Source§impl MeasurePolicy for FlexMeasurePolicy
impl MeasurePolicy for FlexMeasurePolicy
Source§fn measure(
&self,
measurables: &[Box<dyn Measurable>],
constraints: Constraints,
) -> MeasureResult
fn measure( &self, measurables: &[Box<dyn Measurable>], constraints: Constraints, ) -> MeasureResult
Runs the measurement pass with the provided children and constraints.
Source§fn measure_into(
&self,
measurables: &[Box<dyn Measurable>],
constraints: Constraints,
placements: &mut Vec<Placement>,
) -> Size
fn measure_into( &self, measurables: &[Box<dyn Measurable>], constraints: Constraints, placements: &mut Vec<Placement>, ) -> Size
Runs measurement into caller-owned placement storage. Read more
Source§fn min_intrinsic_width(
&self,
measurables: &[Box<dyn Measurable>],
height: f32,
) -> f32
fn min_intrinsic_width( &self, measurables: &[Box<dyn Measurable>], height: f32, ) -> f32
Computes the minimum intrinsic width of this policy.
Source§fn max_intrinsic_width(
&self,
measurables: &[Box<dyn Measurable>],
height: f32,
) -> f32
fn max_intrinsic_width( &self, measurables: &[Box<dyn Measurable>], height: f32, ) -> f32
Computes the maximum intrinsic width of this policy.
Source§fn min_intrinsic_height(
&self,
measurables: &[Box<dyn Measurable>],
width: f32,
) -> f32
fn min_intrinsic_height( &self, measurables: &[Box<dyn Measurable>], width: f32, ) -> f32
Computes the minimum intrinsic height of this policy.
Source§fn max_intrinsic_height(
&self,
measurables: &[Box<dyn Measurable>],
width: f32,
) -> f32
fn max_intrinsic_height( &self, measurables: &[Box<dyn Measurable>], width: f32, ) -> f32
Computes the maximum intrinsic height of this policy.
Source§impl PartialEq for FlexMeasurePolicy
impl PartialEq for FlexMeasurePolicy
Source§fn eq(&self, other: &FlexMeasurePolicy) -> bool
fn eq(&self, other: &FlexMeasurePolicy) -> bool
Tests for
self and other values to be equal, and is used by ==.impl StructuralPartialEq for FlexMeasurePolicy
Auto Trait Implementations§
impl Freeze for FlexMeasurePolicy
impl RefUnwindSafe for FlexMeasurePolicy
impl Send for FlexMeasurePolicy
impl Sync for FlexMeasurePolicy
impl Unpin for FlexMeasurePolicy
impl UnsafeUnpin for FlexMeasurePolicy
impl UnwindSafe for FlexMeasurePolicy
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
Mutably borrows from an owned value. Read more