SubView

Trait SubView 

Source
pub trait SubView {
    // Required methods
    fn size_that_fits(&self, proposal: ProposalSize) -> Size;
    fn stretch_axis(&self) -> StretchAxis;
    fn priority(&self) -> i32;
}
Expand description

A proxy for querying child view sizes during layout.

This trait allows layout containers to negotiate with children by asking “if I propose this size, how big would you be?” multiple times with different proposals.

§Pure Functions

All methods are pure (take &self) with no side effects. Caching of measurement results is handled by the native backend, not in Rust.

Required Methods§

Source

fn size_that_fits(&self, proposal: ProposalSize) -> Size

Query the child’s size for a given proposal.

This method may be called multiple times with different proposals to probe the child’s flexibility:

  • ProposalSize::new(None, None) - ideal/intrinsic size
  • ProposalSize::new(Some(0.0), None) - minimum width
  • ProposalSize::new(Some(f32::INFINITY), None) - maximum width
  • ProposalSize::new(Some(200.0), None) - constrained width
Source

fn stretch_axis(&self) -> StretchAxis

Which axis (or axes) this view stretches to fill available space.

  • StretchAxis::None: Content-sized, uses intrinsic size
  • StretchAxis::Horizontal: Expands width only (e.g., TextField, Slider)
  • StretchAxis::Vertical: Expands height only
  • StretchAxis::Both: Greedy, fills all space (e.g., Spacer, Color)

Layout containers use this to distribute remaining space appropriately:

  • VStack checks stretches_vertical() for height distribution
  • HStack checks stretches_horizontal() for width distribution
Source

fn priority(&self) -> i32

Layout priority for space distribution.

Higher priority views are measured first and get space preference.

Implementors§