Incular logoIncular
API ReferenceLayout Widgets

Expanded

Tight proportional flex child filling its share of free space.

Expanded { flex: u32, child: Widget } occupies a proportional share of the flex main axis with a tight fit. flex defaults to 1; 0 coerces to 1.

Props

Prop

Type

Construction

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                Row::builder()
                    .children(Vec::<Widget>::from([
                        Expanded::new(Text::new("Double")).flex(2).into(),
                        Expanded::flex_factor(
                            1,
                            Text::new("Single"),
                        ).into(),
                    ]))
                    .spacing(8.0)
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Methods

pub fn new(child: impl Into<Widget>) -> Self
pub fn flex_factor(flex: u32, child: impl Into<Widget>) -> Self
pub fn flex(mut self, flex: u32) -> Self // max(1)

Example: weighted split

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new(|_cx| {
        Container::builder()
            .padding(EdgeInsets::all(24.0))
            .alignment(Alignment::CENTER)
            .child(
                Column::builder()
                    .main_axis_size(MainAxisSize::Min)
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        Row::new(Vec::<Widget>::from([
                            Expanded::new(Text::new("Left")).flex(2).into(),
                            Expanded::new(Text::new("Right")).into(),
                        ])).into(),
                        Text::new("Footer").into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

For a configurable loose/tight fit use Flexible; for empty space use Spacer.

Related: Flex, FlexFit.

On this page