Class Flex<W extends Flex<W>>

Direct Known Subclasses:
Column, Row

public abstract class Flex<W extends Flex<W>> extends Container<W>
Simplified flexbox shared by Column and Row: children flow along the main axis with an optional gap; Expanded children split the leftover main-axis space by flex weight; alignment controls the distribution of leftovers (Flex.MainAlignment) and cross-axis placement (Flex.CrossAlignment, including STRETCH).
  • Method Details

    • gap

      public W gap(float newGap)
      Space between children, in logical points. Not applied before the first or after the last. Negative values clamp to 0. UI thread only.
      Parameters:
      newGap - the gutter between neighbours
      Returns:
      this container
      Throws:
      IllegalArgumentException - when NaN or infinite
    • gapSilently

      protected final void gapSilently(float newGap)
      Sets the gap without requesting a layout pass: the measure-path form, for a container that derives its gap from resolved size tokens inside its own onMeasure. Safe there and only there: the caller is already inside the pass that will consume the new value, so requesting another one is at best wasteful and at worst non-terminating. Everything else uses gap(float), and this refuses and clamps what that does.
      Parameters:
      newGap - the gutter between neighbours
      Throws:
      IllegalArgumentException - when NaN or infinite
    • mainAlignment

      public W mainAlignment(Flex.MainAlignment alignment)
      How leftover space along the layout axis is distributed.
    • crossAlignment

      public W crossAlignment(Flex.CrossAlignment alignment)
      How children are placed across the layout axis; BASELINE is the one for a row that mixes size steps and carries text.
    • onMeasure

      protected Size onMeasure(Constraints constraints)
      Description copied from class: Widget
      Reports the size this widget wants within constraints. Called once per layout pass, and the result is cached against the constraints and the resolved axes (size step, layout direction, locale), so it must be a pure function of them and of this widget's own state.

      Resolve the ControlSize and the LayoutDirection once each here and thread them down; never read either in a constructor. The locale needs no threading: it is in scope, and I18n.locale() answers it wherever text is resolved.

      Specified by:
      onMeasure in class Widget<W extends Flex<W>>
    • onLayout

      protected void onLayout()
      Description copied from class: Widget
      Containers position children here (measure + Widget.layoutBox(float, float, float, float) per child).
      Overrides:
      onLayout in class Widget<W extends Flex<W>>