Class Flex


  • public class Flex
    extends Container
    Lays out child elements in a flexible manner by arranging them along a main axis and a cross axis.

    The flex layout manager allows you to create flexible and responsive layouts for containers. It arranges child elements individually along the main axis, following the specified direction and justify. Additionally, you can control the alignment of the items along the cross axis. Child elements are positioned based on the order they are added to the layout.

    Example of a flex layout with a row horizontal direction, centered along the main axis, and stretched to fill the available height along the cross axis:

     Flex flex = new Flex(Direction.ROW, Justify.CENTER, Align.STRETCH);
     
    See Also:
    Flex(Direction, Justify, Align)
    • Constructor Detail

      • Flex

        public Flex​(Flex.Direction direction,
                    Flex.Justify justify,
                    Flex.Align alignment)
        Creates a flex container specifying its layout parameters.
        Parameters:
        direction - the main axis direction for the layout (e.g., Direction.ROW or Flex.Direction.COLUMN).
        justify - the alignment of items along the main axis (e.g., Justify.START, Justify.CENTER or Justify.END).
        alignment - the alignment of items along the cross axis (e.g., Align.STRETCH (default), Align.CENTER, Align.END).
    • Method Detail

      • computeContentOptimalSize

        protected void computeContentOptimalSize​(Size size)
        Description copied from class: Widget
        Computes the optimal size of the widget.

        This method does not consider the border, margin, padding and dimension specified in the style.

        The given size is the available size for this widget in its parent. A width or a height equal to Widget#NO_CONSTRAINT means that there is no constraint on this dimension.

        The given size is modified to set the optimal size.

        Specified by:
        computeContentOptimalSize in class Widget
        Parameters:
        size - the size available for the content.
      • layOutChildren

        protected void layOutChildren​(int contentWidth,
                                      int contentHeight)
        Description copied from class: Container
        Lays out the children of this container.

        The given size is the size of this container minus the border, margin and padding specified in the style.

        When this method returns the children of this container have been lay out using Container.layOutChild(Widget, int, int, int, int).

        Specified by:
        layOutChildren in class Container
        Parameters:
        contentWidth - the width available for the content.
        contentHeight - the height available for the content.
      • setDirection

        public void setDirection​(Flex.Direction direction)
        Sets the direction of the flex.
        Parameters:
        direction - the direction to set.
      • setJustify

        public void setJustify​(Flex.Justify justify)
        Sets the justify of the flex.
        Parameters:
        justify - the justify to set.
      • setAlign

        public void setAlign​(Flex.Align align)
        Sets the align of the flex.
        Parameters:
        align - the align to set.
      • isRow

        public boolean isRow()
        Checks if the main axis is horizontal (ROW or ROW_REVERSE).
        Returns:
        true if the main axis is horizontal, false otherwise.
      • isReverse

        public boolean isReverse()
        Checks if the direction is reversed (ROW_REVERSE or COLUMN_REVERSE).
        Returns:
        true if the direction is reversed, false otherwise.
      • isStretch

        public boolean isStretch()
        Checks if the current align is STRETCH.
        Returns:
        true if align is STRETCH, false otherwise.
      • addChild

        public void addChild​(Widget child)
        Description copied from class: Container
        Adds the specified widget to the end of the list of children of this container.

        The container needs to be laid out again.

        Should be called in the display thread to avoid concurrency issues.

        Overrides:
        addChild in class Container
        Parameters:
        child - the widget to add.
        See Also:
        Widget.requestLayOut(), Widget.isAttached()
      • removeChild

        public void removeChild​(Widget childToRemove)
        Description copied from class: Container
        Removes the specified widget from the list of children of this container.

        The container needs to be laid out again.

        If the widget is not in the list of children of the container, nothing is done.

        Should be called in the display thread to avoid concurrency issues.

        Overrides:
        removeChild in class Container
        Parameters:
        childToRemove - the widget to remove.
        See Also:
        Widget.requestLayOut()
      • removeAllChildren

        public void removeAllChildren()
        Description copied from class: Container
        Removes all the children of this container.

        The container needs to be laid out again.

        Should be called in the display thread to avoid concurrency issues.

        Overrides:
        removeAllChildren in class Container
        See Also:
        Widget.requestLayOut()