[][src]Crate embedded_layout

Enable simple layout operations in embedded-graphics

This crate extends embedded-graphics objects that implement the Transform trait to be aligned to other objects that have Dimensions.

Examples

The examples are based on the embedded-graphics simulator. The simulator is built on top of SDL2. If you don't have that installed, set the EG_SIMULATOR_DUMP="screenshot.png" environment variable so that running the examples produce a screenshot image instead of a window.

Draw some text to the center of the display


use embedded_graphics::{
    fonts::{Font6x8, Text},
    pixelcolor::BinaryColor,
    prelude::*,
    style::TextStyleBuilder,
};
use embedded_layout::prelude::*;

// Create a Rectangle from the display's dimensions
let display_area = display.display_area();

let text_style = TextStyleBuilder::new(Font6x8)
    .text_color(BinaryColor::On)
    .build();

Text::new("Hello, World!", Point::zero())
    .into_styled(text_style)
    // align text to the display
    .align_to(&display_area, horizontal::Center, vertical::Center)
    .draw(&mut display)
    .unwrap();

Use LinearLayout to arrange multiple objects


use embedded_graphics::{
    fonts::{Font6x8, Text},
    pixelcolor::BinaryColor,
    prelude::*,
    style::TextStyleBuilder,
};
use embedded_layout::layout::linear::LinearLayout;
use embedded_layout::prelude::*;

let display_area = display.display_area();

let text_style = TextStyleBuilder::new(Font6x8)
    .text_color(BinaryColor::On)
    .build();

LinearLayout::vertical()
    .with_alignment(horizontal::Center)
    .add_view(Text::new("Vertical", Point::zero()).into_styled(text_style))
    .add_view(Text::new("Linear", Point::zero()).into_styled(text_style))
    .add_view(Text::new("Layout", Point::zero()).into_styled(text_style))
    .arrange()
    .align_to(&display_area, horizontal::Center, vertical::Center)
    .draw(&mut display)
    .unwrap();

Modules

layout

Layout module

prelude

The essentials

Traits

View

A view is the base unit for most of the embedded-layout operations.