Class WrapLayout

All Implemented Interfaces:
Orientable, Proxy

@Generated("org.javagi.JavaGI") public class WrapLayout extends LayoutManager implements Orientable

A box-like layout that can wrap into multiple lines.

wrap-box

AdwWrapLayout is similar to BoxLayout, but can wrap lines when the widgets cannot fit otherwise. Unlike FlowBox, the children aren't arranged into a grid and behave more like words in a wrapping label.

Like GtkBoxLayout, AdwWrapLayout is orientable and has spacing:

  • WrapLayout:child-spacing between children in the same line;
  • WrapLayout:line-spacing between lines.

::: note Unlike GtkBoxLayout, AdwWrapLayout cannot follow the CSS border-spacing property.

Use the WrapLayout:natural-line-length property to determine the layout's natural size, e.g. when using it in a Popover.

Normally, a horizontal AdwWrapLayout wraps left to right and top to bottom for left-to-right languages. Both of these directions can be reversed, using the WrapLayout:pack-direction and WrapLayout:wrap-reverse properties. Additionally, the alignment of each line can be controlled with the WrapLayout:align property.

Lines can be justified using the WrapLayout:justify property, filling the entire line by either increasing child size or spacing depending on the value. Set WrapLayout:justify-last-line to justify the last line as well.

By default, AdwWrapLayout wraps as soon as the previous line cannot fit any more children without shrinking them past their natural size. Set WrapLayout:wrap-policy to Adw.WrapPolicy.minimum to only wrap once all the children in the previous line have been shrunk to their minimum size.

To make each line take the same amount of space, set WrapLayout:line-homogeneous to TRUE.

Spacing and natural line length can scale with the text scale factor, use the WrapLayout:child-spacing-unit, WrapLayout:line-spacing-unit and/or WrapLayout:natural-line-length-unit properties to enable that behavior.

See WrapBox.

Since:
1.7
  • Constructor Details

    • WrapLayout

      public WrapLayout(MemorySegment address)
      Create a WrapLayout instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • WrapLayout

      public WrapLayout()
      Create a new WrapLayout.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the WrapLayout class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected WrapLayout asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class LayoutManager
      Returns:
      the instance as if it were its parent type
    • getAlign

      public float getAlign()
      Gets the alignment of the children within each line.
      Returns:
      the child alignment
      Since:
      1.7
    • getChildSpacing

      public int getChildSpacing()
      Gets spacing between widgets on the same line.
      Returns:
      spacing between widgets on the same line
      Since:
      1.7
    • getChildSpacingUnit

      public LengthUnit getChildSpacingUnit()
      Gets the length unit for child spacing.
      Returns:
      the length unit
      Since:
      1.7
    • getJustify

      public JustifyMode getJustify()
      Gets whether and how each complete line is stretched to fill the entire widget.
      Returns:
      the justify mode
      Since:
      1.7
    • getJustifyLastLine

      public boolean getJustifyLastLine()
      Gets whether the last line should be stretched to fill the entire widget.
      Returns:
      whether the last line is justified
      Since:
      1.7
    • getLineHomogeneous

      public boolean getLineHomogeneous()
      Gets whether all lines should take the same amount of space.
      Returns:
      whether lines should be homogeneous
      Since:
      1.7
    • getLineSpacing

      public int getLineSpacing()
      Gets the spacing between lines.
      Returns:
      the line spacing
      Since:
      1.7
    • getLineSpacingUnit

      public LengthUnit getLineSpacingUnit()
      Gets the length unit for line spacing.
      Returns:
      the length unit
      Since:
      1.7
    • getNaturalLineLength

      public int getNaturalLineLength()
      Gets the natural size for each line.
      Returns:
      the natural length
      Since:
      1.7
    • getNaturalLineLengthUnit

      public LengthUnit getNaturalLineLengthUnit()
      Gets the length unit for line spacing.
      Returns:
      the length unit
      Since:
      1.7
    • getPackDirection

      public PackDirection getPackDirection()
      Gets the direction children are packed in each line.
      Returns:
      the line direction
      Since:
      1.7
    • getWrapPolicy

      public WrapPolicy getWrapPolicy()
      Gets the policy for line wrapping.
      Returns:
      the wrap policy
      Since:
      1.7
    • getWrapReverse

      public boolean getWrapReverse()
      Gets whether wrap direction is reversed.
      Returns:
      whether wrap direction is reversed
      Since:
      1.7
    • setAlign

      public void setAlign(float align)

      Sets the alignment of the children within each line.

      0 means the children are placed at the start of the line, 1 means they are placed at the end of the line. 0.5 means they are placed in the middle of the line.

      Alignment is only used when WrapLayout:justify is set to Adw.JustifyMode.none, or on the last line when the WrapLayout:justify-last-line is FALSE.

      Parameters:
      align - the child alignment
      Since:
      1.7
    • setChildSpacing

      public void setChildSpacing(int childSpacing)

      Sets the spacing between widgets on the same line.

      See WrapLayout:child-spacing-unit.

      Parameters:
      childSpacing - the child spacing
      Since:
      1.7
    • setChildSpacingUnit

      public void setChildSpacingUnit(LengthUnit unit)

      Sets the length unit for child spacing.

      Allows the spacing to vary depending on the text scale factor.

      See WrapLayout:child-spacing.

      Parameters:
      unit - the length unit
      Since:
      1.7
    • setJustify

      public void setJustify(JustifyMode justify)

      Sets whether and how each complete line should be stretched to fill the entire widget.

      If set to Adw.JustifyMode.fill, each widget in the line will be stretched, keeping consistent spacing, so that the line fills the entire widget.

      If set to Adw.JustifyMode.spread, the spacing between widgets will be increased, keeping widget sizes intact. The first and last widget will be aligned with the beginning and end of the line. If the line only contains a single widget, it will be stretched regardless.

      If set to Adw.JustifyMode.none, the line will not be stretched and the children will be placed together within the line, according to WrapLayout:align.

      By default this doesn't affect the last line, as it will be incomplete. Use WrapLayout:justify-last-line to justify it as well.

      Parameters:
      justify - the justify mode
      Since:
      1.7
    • setJustifyLastLine

      public void setJustifyLastLine(boolean justifyLastLine)

      Sets whether the last line should be stretched to fill the entire widget.

      See WrapLayout:justify.

      Parameters:
      justifyLastLine - whether to justify the last line
      Since:
      1.7
    • setLineHomogeneous

      public void setLineHomogeneous(boolean homogeneous)
      Sets whether all lines should take the same amount of space.
      Parameters:
      homogeneous - whether lines should be homogeneous
      Since:
      1.7
    • setLineSpacing

      public void setLineSpacing(int lineSpacing)

      Sets the spacing between lines.

      See WrapLayout:line-spacing-unit.

      Parameters:
      lineSpacing - the line spacing
      Since:
      1.7
    • setLineSpacingUnit

      public void setLineSpacingUnit(LengthUnit unit)

      Sets the length unit for line spacing.

      Allows the spacing to vary depending on the text scale factor.

      See WrapLayout:line-spacing.

      Parameters:
      unit - the length unit
      Since:
      1.7
    • setNaturalLineLength

      public void setNaturalLineLength(int naturalLineLength)

      Sets the natural size for each line.

      It should be used to limit the line lengths, for example when used in popovers.

      See WrapLayout:natural-line-length-unit.

      Parameters:
      naturalLineLength - the natural length
      Since:
      1.7
    • setNaturalLineLengthUnit

      public void setNaturalLineLengthUnit(LengthUnit unit)

      Sets the length unit for natural line length.

      Allows the length to vary depending on the text scale factor.

      See WrapLayout:natural-line-length.

      Parameters:
      unit - the length unit
      Since:
      1.7
    • setPackDirection

      public void setPackDirection(PackDirection packDirection)
      Sets the direction children are packed in each line.
      Parameters:
      packDirection - the new line direction
      Since:
      1.7
    • setWrapPolicy

      public void setWrapPolicy(WrapPolicy wrapPolicy)

      Sets the policy for line wrapping.

      If set to Adw.WrapPolicy.natural, the box will wrap to the next line as soon as the previous line cannot fit any more children without shrinking them past their natural size.

      If set to Adw.WrapPolicy.minimum, the box will try to fit as many children into each line as possible, shrinking them down to their minimum size before wrapping to the next line.

      Parameters:
      wrapPolicy - the new wrap policy
      Since:
      1.7
    • setWrapReverse

      public void setWrapReverse(boolean wrapReverse)

      Sets whether wrap direction should be reversed.

      By default, lines wrap downwards in a horizontal box, and towards the end in a vertical box. If set to TRUE, they wrap upwards or towards the start respectively.

      Parameters:
      wrapReverse - whether to reverse wrap direction
      Since:
      1.7
    • builder

      public static WrapLayout.Builder<? extends WrapLayout.Builder> builder()
      A WrapLayout.Builder object constructs a WrapLayout with the specified properties. Use the various set...() methods to set properties, and finish construction with WrapLayout.Builder.build().
      Returns:
      the builder object