Incular logoIncular
API ReferenceLayout Widgets

Spacer

Empty proportional gap on the flex axis.

Spacer { flex: u32 } renders empty flexible space, lowering to an expanded shrink box. Default flex = 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([
                        Text::new("Left").into(),
                        Spacer::new().flex(1).into(),
                        Text::new("Right").into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Methods

pub const fn new() -> Self
pub const fn flex_factor(flex: u32) -> Self
pub const fn flex(mut self, flex: u32) -> Self

Example

Spacer::flex_factor(2) and Spacer::new().flex(2) are equivalent; the runnable program above pushes neighbors apart with a flex-1 gap.

Related: Expanded, Row.

On this page