Incular logoIncular
API ReferenceLayout Widgets

Container

Every field, method, and composition rule for the Container widget.

Container (incular::prelude, from incular-widgets) combines sizing, margin, padding, background, border, radius, alignment, transform, and clipping in one descriptor. It lowers to primitives in a fixed order: inner Align → Padding → decoration → ConstrainedBox → outer margin Padding → Transform → clip.

Fields

Prop

Type

Construction

Copy, paste, and run — a first Container application:

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(Text::new("Hello, Container!"))
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Container::builder() takes every field; the fluent Container::new() style (Container::new().padding(..).child(..)) and the shortcuts Container::with_child(..) / Container::empty() build the same struct.

Methods

child(child: impl Into<Widget>)

Set or replace the child — any widget converts via Into<Widget>.

alignment(alignment: Alignment)

Positions the child when the Container is larger than it. No visible effect when shrink-wrapped. All constants: TOP_LEFT, TOP_CENTER, TOP_RIGHT, CENTER_LEFT, CENTER, CENTER_RIGHT, BOTTOM_LEFT, BOTTOM_CENTER, BOTTOM_RIGHT, or Alignment::new(x, y).

padding(padding: EdgeInsets)

Insets between border/background edge and child. See EdgeInsets for all constructors (all, symmetric, only, ZERO).

margin(margin: EdgeInsets)

Space outside the background/border. Siblings with margin never overlap backgrounds.

color(color: Color) and background(brush: impl Into<Brush>)

Solid fill vs any Brush (gradients). Last writer wins — prefer color for solids, background for gradients.

border(border: impl Into<Border>) and decoration(decoration: BoxDecoration)

radius(radius: impl Into<CornerRadii>)

width(f32) and height(f32)

constraints(constraints: Constraints)

See Constraints.

transform(transform: AffineTransform)

Affine after layout; size unchanged, only painting/hit-test/semantics observe.

clip_behavior(clip: Clip)

None (overflow paints) / HardEdge (default, fast) / AntiAlias / AntiAliasWithSaveLayer (smooth + isolated, costly).

Complete example

A card exercising margin, padding, alignment, color, border, radius, clip, and width:

use incular::prelude::*;
use incular::config::Clip;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new(|_cx| {
        Container::builder()
            .margin(EdgeInsets::symmetric(16.0, 8.0))
            .padding(EdgeInsets::all(16.0))
            .alignment(Alignment::CENTER_LEFT)
            .color(Color::WHITE)
            .border(Border::new(1.0, Color::BLACK))
            .radius(12.0)
            .clip_behavior(Clip::AntiAlias)
            .width(320.0)
            .child(
                Column::builder()
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        Text::new("Title").into(),
                        Text::new("Body text").into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Decoration showcase

Gradients, full decoration, extra constraints, and transforms:

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let app = Application::new(|_cx| {
        Container::new()
            .background(Brush::LinearGradient(LinearGradient {
                start: Offset::new(0.0, 0.0),
                end: Offset::new(200.0, 0.0),
                stops: GradientStops::new(vec![
                    GradientStop {
                        offset: 0.0,
                        color: Color::WHITE,
                    },
                    GradientStop {
                        offset: 1.0,
                        color: Color::BLACK,
                    },
                ]),
            }))
            .decoration(BoxDecoration::new().color(Color::WHITE))
            .constraints(Constraints::new(0.0, 300.0, 0.0, 200.0))
            .transform(AffineTransform::rotation(0.1))
            .height(160.0)
            .padding(EdgeInsets::only(8.0, 4.0, 8.0, 4.0))
            .child(Text::new("Decorated"))
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Related: Row, EdgeInsets, Alignment.

On this page