public class Flex extends Container
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);
Flex(Direction, Justify, Align)
Modifier and Type | Class and Description |
---|---|
static class |
Flex.Align
Enum representing the possible values for aligning the row's start position on the cross axis.
|
static class |
Flex.Direction
Enum representing the possible directions for computing a flex layout.
|
static class |
Flex.Justify
Enum representing the possible values for justifying the widget's start position on the cross axis.
|
NO_CONSTRAINT
Constructor and Description |
---|
Flex(Flex.Direction direction,
Flex.Justify justify,
Flex.Align alignment)
Creates a flex container specifying its layout parameters.
|
Modifier and Type | Method and Description |
---|---|
void |
addChild(Widget child)
Adds the specified widget to the end of the list of children of this container.
|
protected void |
computeContentOptimalSize(Size size)
Computes the optimal size of the widget.
|
boolean |
isReverse()
Checks if the direction is reversed (ROW_REVERSE or COLUMN_REVERSE).
|
boolean |
isRow()
Checks if the main axis is horizontal (ROW or ROW_REVERSE).
|
boolean |
isStretch()
Checks if the current align is STRETCH.
|
protected void |
layOutChildren(int contentWidth,
int contentHeight)
Lays out the children of this container.
|
void |
removeAllChildren()
Removes all the children of this container.
|
void |
removeChild(Widget childToRemove)
Removes the specified widget from the list of children of this container.
|
void |
setAlign(Flex.Align align)
Sets the align of the flex.
|
void |
setDirection(Flex.Direction direction)
Sets the direction of the flex.
|
void |
setJustify(Flex.Justify justify)
Sets the justify of the flex.
|
changeChildIndex, computeChildOptimalSize, getChild, getChildIndex, getChildren, getChildrenCount, getContentBounds, getContentHeight, getContentWidth, getContentX, getContentY, getWidgetAt, insertChild, layOutAlignedChild, layOutChild, renderChild, renderContent, replaceChild, setHiddenChild, setHiddenChildren, setShownChild, setShownChildren, updateStyle
addClassSelector, contains, containsWidget, getAbsoluteX, getAbsoluteY, getDesktop, getHeight, getParent, getStyle, getWidth, getX, getY, handleEvent, hasClassSelector, isAttached, isEnabled, isInState, isShown, isTransparent, onAttached, onDetached, onHidden, onLaidOut, onShown, removeAllClassSelectors, removeClassSelector, render, requestLayOut, requestRender, requestRender, setClassSelectors, setEnabled, setPosition, setStyle
public Flex(Flex.Direction direction, Flex.Justify justify, Flex.Align alignment)
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).public void addChild(Widget child)
Container
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
addChild
in class Container
child
- the widget to add.Widget.requestLayOut()
,
Widget.isAttached()
protected void computeContentOptimalSize(Size size)
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.
computeContentOptimalSize
in class Widget
size
- the size available for the content.public boolean isReverse()
true
if the direction is reversed, false
otherwise.public boolean isRow()
true
if the main axis is horizontal, false
otherwise.public boolean isStretch()
true
if align is STRETCH, false
otherwise.protected void layOutChildren(int contentWidth, int contentHeight)
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)
.
layOutChildren
in class Container
contentWidth
- the width available for the content.contentHeight
- the height available for the content.public void removeAllChildren()
Container
The container needs to be laid out again.
Should be called in the display thread to avoid concurrency issues.
removeAllChildren
in class Container
Widget.requestLayOut()
public void removeChild(Widget childToRemove)
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.
removeChild
in class Container
childToRemove
- the widget to remove.Widget.requestLayOut()
public void setAlign(Flex.Align align)
align
- the align to set.public void setDirection(Flex.Direction direction)
direction
- the direction to set.public void setJustify(Flex.Justify justify)
justify
- the justify to set.