Incular logoIncular
API ReferenceLayout Values

EdgeInsets

Every constructor, accessor, and arithmetic operator for box insets.

EdgeInsets holds four physical edges { left, top, right, bottom }, all public f32, kept as supplied — layout sanitizes non-finite and negative values. Default is zero.

Constructors

use incular::prelude::*;

fn main() {
    println!("zero: {:?}", EdgeInsets::ZERO);
    println!("all: {:?}", EdgeInsets::all(8.0));
    println!("symmetric: {:?}", EdgeInsets::symmetric(12.0, 6.0));
    println!("only: {:?}", EdgeInsets::only(8.0, 4.0, 8.0, 4.0));
    println!("ltrb: {:?}", EdgeInsets::from_ltrb(8.0, 4.0, 8.0, 4.0));
}
ConstructorResult
ZERO / zero()All edges 0.0
all(v)All edges v
symmetric(h, v)Left/right h, top/bottom v
horizontal_insets(h)Left/right h, vertical 0.0
vertical_insets(v)Top/bottom v, horizontal 0.0
from_xy(h, v)Same as symmetric
only(l, t, r, b)Each edge explicitly
from_ltrb(l, t, r, b)Same as only

All three styles running side by side — copy, paste, and run:

use incular::prelude::*;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let outer = EdgeInsets::all(8.0);
    let inner = EdgeInsets::symmetric(12.0, 6.0);
    let total = outer + inner;
    let app = Application::new(move |_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([
                        Container::new()
                                .padding(EdgeInsets::all(8.0))
                                .color(Color::WHITE)
                                .child(Text::new("all(8)")).into(),
                        Container::new()
                                .padding(inner)
                                .color(Color::WHITE)
                                .child(Text::new("symmetric")).into(),
                        Container::new()
                                .padding(total)
                                .color(Color::WHITE)
                                .child(Text::new("added")).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Accessors and validation

use incular::prelude::*;

fn main() {
    let insets = EdgeInsets::all(8.0);
    println!("h: {} v: {}", insets.horizontal(), insets.vertical());
    println!("zero: {}", insets.is_zero());
    println!("normalized: {:?}", insets.normalized());
    println!("grown: {:?}", insets.outset(4.0));
}

Arithmetic

Add, AddAssign, Sub, SubAssign, Mul<f32>, Div<f32>, Neg, and Lerp (component-wise).

EdgeInsetsDirectional { start, top, end, bottom } is the logical-pixel twin (zero / all / only / symmetric constructors, resolve(direction)), for direction-aware padding. See Directionality.

use incular::prelude::*;

fn main() {
    let outer = EdgeInsets::all(8.0);
    let inner = EdgeInsets::symmetric(12.0, 6.0);
    let total = outer + inner;
    let doubled = inner * 2.0;
    println!("total: {:?}", total);
    println!("doubled: {:?}", doubled);
}

Used by: Container, Padding, TransientPlacement.

On this page