MCPcopy Index your code
hub / github.com/bugadani/embedded-layout

github.com/bugadani/embedded-layout @v0.4.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.4.2 ↗ · + Follow
169 symbols 438 edges 24 files 19 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

embedded-layout

embedded-layout extends [embedded-graphics] with basic layout functions.

embedded-layout consists of three main parts: - alignments that can be used to position two objects relative to one another * horizontal * NoAlignment, Left, Right, Center * LeftToRight, RightToLeft * vertical * NoAlignment, Top, Bottom, Center * TopToBottom, BottomToTop - layouts that can be used to arrange multiple views * LinearLayout - view groups which are collections of view objects * Chain to create ad-hoc collections (can hold views of different types) * Views to create view groups from arrays and slices (can only hold views of a single type) * derive(ViewGroup) to turn any plain old Rust struct into a view group

Example

The examples are based on the embedded-graphics simulator. The simulator is built on top of SDL2. See the simulator README for more information.

embedded-layout example

use embedded_graphics_simulator::{
    BinaryColorTheme, OutputSettingsBuilder, SimulatorDisplay, Window,
};

use embedded_graphics::{
    mono_font::{ascii::FONT_6X9, MonoTextStyle},
    pixelcolor::BinaryColor,
    prelude::*,
    primitives::{Circle, PrimitiveStyle, Triangle},
    text::Text,
};
use embedded_layout::{layout::linear::LinearLayout, prelude::*};

fn main() -> Result<(), core::convert::Infallible> {
    let mut display: SimulatorDisplay<BinaryColor> = SimulatorDisplay::new(Size::new(128, 64));

    let output_settings = OutputSettingsBuilder::new()
        .theme(BinaryColorTheme::OledBlue)
        .build();

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

    // Style objects
    let text_style = MonoTextStyle::new(&FONT_6X9, BinaryColor::On);

    let thin_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 1);
    let thick_stroke = PrimitiveStyle::with_stroke(BinaryColor::On, 3);
    let fill_on = PrimitiveStyle::with_fill(BinaryColor::On);
    let fill_off = PrimitiveStyle::with_fill(BinaryColor::Off);

    // Primitives to be displayed
    let triangle = Triangle::new(Point::new(0, 0), Point::new(12, 0), Point::new(6, 12))
        .into_styled(thin_stroke);

    let circle = Circle::new(Point::zero(), 11).into_styled(thick_stroke);
    let circle2 = Circle::new(Point::zero(), 15).into_styled(fill_on);
    let triangle2 =
        Triangle::new(Point::new(0, 0), Point::new(10, 0), Point::new(5, 8)).into_styled(fill_off);
    let text = Text::new("embedded-layout", Point::zero(), text_style);

    // The layout
    LinearLayout::vertical(
        Chain::new(text)
            .append(LinearLayout::horizontal(Chain::new(triangle).append(circle)).arrange())
            .append(
                Chain::new(triangle2.align_to(&circle2, horizontal::Center, vertical::Top))
                    .append(circle2),
            ),
    )
    .with_alignment(horizontal::Center)
    .arrange()
    .align_to(&display_area, horizontal::Center, vertical::Center)
    .draw(&mut display)
    .unwrap();

    Window::new("Layout example", &output_settings).show_static(&display);
    Ok(())
}

Development setup

Minimum supported Rust version

The minimum supported Rust version for embedded-layout is 1.61.0 or greater.

Installation

For setup in general, follow the installation instructions for [embedded-graphics].

To install SDL2 on Windows, see https://github.com/Rust-SDL2/rust-sdl2#windows-msvc

Extension points exported contracts — how you extend this code

View (Interface)
A `View` is the base unit for most of the `embedded-layout` operations. `View`s must have a size and a position. See t [7 …
src/lib.rs
SecondaryAlignment (Interface)
Secondary alignment is used to align views perpendicular to the placement axis. For example, use [`horizontal::Right`] [10 …
src/layout/linear/secondary_alignment.rs
Alignment (Interface)
Base trait for alignment operations An [`Alignment`] object modifies either the horizontal, or the vertical position of [12 …
src/align/mod.rs
ViewGroup (Interface)
A set of operations required to implement [`View`] containers. [5 implementers]
src/view_group/mod.rs
ChainElement (Interface)
A generic chain element [2 implementers]
src/object_chain.rs
RectExt (Interface)
The trait that describes the extension methods. [1 implementers]
src/utils/rect_helper.rs
ElementSpacing (Interface)
`ElementSpacing` base trait [3 implementers]
src/layout/linear/spacing.rs
HorizontalAlignment (Interface)
Implement this trait for horizontal alignment operations This trait does not provide any functionality other than that [6 …
src/align/mod.rs

Core symbols most depended-on inside this repo

append
called by 39
src/object_chain.rs
align_to
called by 38
src/align/mod.rs
arrange
called by 25
src/layout/linear/mod.rs
size
called by 15
src/lib.rs
translate
called by 10
src/view_group/mod.rs
with_alignment
called by 9
src/layout/linear/mod.rs
draw
called by 9
src/layout/linear/mod.rs
draw
called by 9
examples/custom_view.rs

Shape

Method 74
Function 54
Class 28
Interface 12
Enum 1

Languages

Rust100%

Modules by API surface

src/layout/linear/mod.rs32 symbols
src/align/horizontal/mod.rs18 symbols
src/align/vertical/mod.rs17 symbols
src/view_group/views.rs14 symbols
src/object_chain.rs13 symbols
src/view_group/mod.rs11 symbols
src/layout/linear/orientation.rs10 symbols
src/view_group/object_chain.rs8 symbols
src/lib.rs7 symbols
src/align/mod.rs7 symbols
examples/custom_view.rs7 symbols
src/layout/linear/spacing.rs5 symbols

For agents

$ claude mcp add embedded-layout \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact