Incular logoIncular
API ReferenceLayout Widgets

Flexible

Flex child with configurable tight or loose fit.

Flexible { flex: u32, fit: FlexFit, child: Widget } allocates a proportional share like Expanded but lets you choose the fit. Defaults: flex = 1 (coerced max(1)), fit = Loose.

Props

Prop

Type

Construction

Loose versus tight shares — copy, paste, and run:

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([
                        Flexible::new(Text::new("Loose")).flex(1).into(),
                        Flexible::flex_factor(
                            2,
                            Text::new("Wide"),
                        ).into(),
                        Flexible::new(Text::new("Tight")).tight().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
pub fn fit(mut self, fit: FlexFit) -> Self
pub fn tight(mut self) -> Self // fit = Tight

Loose keeps the child's natural size within its share; Tight forces it to fill the share. Note the FlexFit enum itself defaults to Tight, while this widget defaults to Loose.

Related: Expanded, Spacer.

On this page