Class Flex
- java.lang.Object
-
- ej.mwt.Widget
-
- ej.mwt.Container
-
- ej.widget.container.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)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFlex.AlignEnum representing the possible values for aligning the row's start position on the cross axis.static classFlex.DirectionEnum representing the possible directions for computing a flex layout.static classFlex.JustifyEnum representing the possible values for justifying the widget's start position on the cross axis.-
Nested classes/interfaces inherited from class ej.mwt.Widget
Widget.WidgetListener
-
-
Field Summary
-
Fields inherited from class ej.mwt.Widget
DEBUG_WIDGET_ENABLED_CONSTANT, DEBUG_WIDGET_MONITOR_CONSTANT, NO_CONSTRAINT
-
-
Constructor Summary
Constructors Constructor Description Flex(Flex.Direction direction, Flex.Justify justify, Flex.Align alignment)Creates a flex container specifying its layout parameters.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddChild(Widget child)Adds the specified widget to the end of the list of children of this container.protected voidcomputeContentOptimalSize(Size size)Computes the optimal size of the widget.booleanisReverse()Checks if the direction is reversed (ROW_REVERSE or COLUMN_REVERSE).booleanisRow()Checks if the main axis is horizontal (ROW or ROW_REVERSE).booleanisStretch()Checks if the current align is STRETCH.protected voidlayOutChildren(int contentWidth, int contentHeight)Lays out the children of this container.voidremoveAllChildren()Removes all the children of this container.voidremoveChild(Widget childToRemove)Removes the specified widget from the list of children of this container.voidsetAlign(Flex.Align align)Sets the align of the flex.voidsetDirection(Flex.Direction direction)Sets the direction of the flex.voidsetJustify(Flex.Justify justify)Sets the justify of the flex.-
Methods inherited from class ej.mwt.Container
changeChildIndex, computeChildOptimalSize, getChild, getChildIndex, getChildren, getChildrenCount, getContentBounds, getContentHeight, getContentWidth, getContentX, getContentY, getWidgetAt, insertChild, layOutAlignedChild, layOutChild, renderChild, renderContent, replaceChild, setHiddenChild, setHiddenChildren, setShownChild, setShownChildren, updateStyle
-
Methods inherited from class ej.mwt.Widget
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, setX, setY
-
-
-
-
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:WidgetComputes 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_CONSTRAINTmeans that there is no constraint on this dimension.The given size is modified to set the optimal size.
- Specified by:
computeContentOptimalSizein classWidget- Parameters:
size- the size available for the content.
-
layOutChildren
protected void layOutChildren(int contentWidth, int contentHeight)Description copied from class:ContainerLays 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:
layOutChildrenin classContainer- 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:
trueif the main axis is horizontal,falseotherwise.
-
isReverse
public boolean isReverse()
Checks if the direction is reversed (ROW_REVERSE or COLUMN_REVERSE).- Returns:
trueif the direction is reversed,falseotherwise.
-
isStretch
public boolean isStretch()
Checks if the current align is STRETCH.- Returns:
trueif align is STRETCH,falseotherwise.
-
addChild
public void addChild(Widget child)
Description copied from class:ContainerAdds 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:
addChildin classContainer- Parameters:
child- the widget to add.- See Also:
Widget.requestLayOut(),Widget.isAttached()
-
removeChild
public void removeChild(Widget childToRemove)
Description copied from class:ContainerRemoves 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:
removeChildin classContainer- Parameters:
childToRemove- the widget to remove.- See Also:
Widget.requestLayOut()
-
removeAllChildren
public void removeAllChildren()
Description copied from class:ContainerRemoves 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:
removeAllChildrenin classContainer- See Also:
Widget.requestLayOut()
-
-