[][src]Module embedded_layout::layout::linear

Linear layout

A linear layout is a list of Views that are placed one after the other along the horizontal or vertical axis.

The main flow when working with a LinearLayout is the following:

  • Create the layout: you need to choose which orientation you want your views arranged in
  • Optionally, set secondary alignment
  • Optionally, set element spacing
  • Add views you want to arrange
  • Call LinearLayout::arrange to finalize view placement
  • Align the returned ViewGroup to where you want it to be displayed
  • Call draw to display the views

Note: LinearLayout is implemented using object chaining so it's exact type depends on it's contents.

Orientation

When constructing a LinearLayout object, you need to choose an orientation along which the views will be arranged. This can either be horizontal or vertical.

Examples:

Create a LinearLayout with two pieces of text, where one is below the other:

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

let _ = LinearLayout::vertical()
    .add_view(Text::new("Hello,", Point::zero()).into_styled(text_style))
    .add_view(Text::new("World!", Point::zero()).into_styled(text_style))
    .arrange();

Secondary alignment

Secondary alignment means the alignment on the "other" axis:

  • horizontal alignment in vertical linear layouts
  • vertical alignment in horizontal linear layouts

By default, the secondary alignments are the following:

Except for using the cascading (XtoY) secondary alignments, the LinearLayout will take up as much space along the secondary alignment as the biggest element, i.e. vertical layouts will be as wide as the widest view inside them.

Element spacing

It's possible to modify how views are placed relative to one another.

Re-exports

pub use spacing::ElementSpacing;
pub use spacing::FixedMargin;

Modules

spacing

Element spacing

Structs

Horizontal

Horizontal layout direction

LinearLayout

LinearLayout

Vertical

Vertical layout direction

Traits

Orientation

Helper trait that describes a linear layout orientation.

SecondaryAlignment

Secondary alignment is used to align views perpendicular to the placement axis.