[][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
  • Add views you want to arrange
  • Call arrange to finalize view placement
  • Align the returned ViewGroup to where you want it to be displayed
  • Call draw to display the views

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:

  • Horizontal orientation: vertical::Bottom
  • Vertical orientation: horizontal::Left

Structs

Horizontal

Horizontal layout direction

LinearLayout

LinearLayout

Vertical

Vertical layout direction

Traits

LayoutDirection

Helper trait that describes a layout direction.

SecondaryAlignment

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