Incular logoIncular
API ReferenceLayout Values

Alignment

Normalized 2D alignment points with every constant and helper.

Alignment { x: f32, y: f32 } is a normalized point in [-1, 1]: (-1, -1) top-left, (0, 0) center, (1, 1) bottom-right. Default is center.

Constants

use incular::prelude::*;

fn main() {
    let points = [
        Alignment::TOP_LEFT,
        Alignment::TOP_CENTER,
        Alignment::TOP_RIGHT,
        Alignment::CENTER_LEFT,
        Alignment::CENTER,
        Alignment::CENTER_RIGHT,
        Alignment::BOTTOM_LEFT,
        Alignment::BOTTOM_CENTER,
        Alignment::BOTTOM_RIGHT,
        Alignment::new(0.5, -0.5),
    ];
    println!("points: {}", points.len());
}
Constantxy
TOP_LEFT-1-1
TOP_CENTER0-1
TOP_RIGHT1-1
CENTER_LEFT-10
CENTER00
CENTER_RIGHT10
BOTTOM_LEFT-11
BOTTOM_CENTER01
BOTTOM_RIGHT11
new(x, y)customcustom point in [-1, 1]

Three alignments running — 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()
                    .spacing(8.0)
                    .children(Vec::<Widget>::from([
                        Container::new()
                                .alignment(Alignment::TOP_LEFT)
                                .color(Color::WHITE)
                                .width(96.0)
                                .height(96.0)
                                .child(Text::new("TL")).into(),
                        Container::new()
                                .alignment(Alignment::CENTER)
                                .color(Color::WHITE)
                                .width(96.0)
                                .height(96.0)
                                .child(Text::new("C")).into(),
                        Container::new()
                                .alignment(Alignment::new(1.0, 1.0))
                                .color(Color::WHITE)
                                .width(96.0)
                                .height(96.0)
                                .child(Text::new("BR")).into(),
                    ]))
                    .build(),
            )
            .build()
            .into()
    })?;
    incular::run(app)?;
    Ok(())
}

Helpers

use incular::prelude::*;

fn main() {
    let a = Alignment::CENTER;
    let size = Size::new(100.0, 50.0);
    println!("along: {:?}", a.along_size(size));
    println!("within: {:?}", a.within(size, Size::new(20.0, 10.0)));
    println!("resolved: {:?}", a.resolve(TextDirection::Ltr));
}

Supports Add, Sub, Mul<f32>, Div<f32>, Neg, Lerp.

AlignmentDirectional { start: f32, y: f32 } is the direction-relative twin (TOP_START … BOTTOM_END constants) resolved with resolve(TextDirection) — use it when start/end must flip in RTL. See Directionality.

Used by: Container, Stack, Align, Image.

On this page