Class WrapBox

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Orientable, Proxy

@Generated("org.javagi.JavaGI") public class WrapBox extends Widget implements Accessible, Buildable, ConstraintTarget, Orientable

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

wrap-box

AdwWrapBox is similar to Box, 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 GtkBox, AdwWrapBox is orientable and has spacing:

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

::: note Unlike GtkBox, AdwWrapBox cannot follow the CSS border-spacing property.

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

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

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

By default, AdwWrapBox wraps as soon as the previous line cannot fit any more children without shrinking them past their natural size. Set WrapBox: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 WrapBox:line-homogeneous to TRUE.

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

See WrapLayout.

CSS nodes

AdwWrapBox uses a single CSS node with name wrap-box.

Accessibility

AdwWrapBox uses the Gtk.AccessibleRole.group role.

Since:
1.7
  • Constructor Details

    • WrapBox

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

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

    • getType

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

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

      protected WrapBox 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 Widget
      Returns:
      the instance as if it were its parent type
    • append

      public void append(Widget child)
      Adds child as the last child to self.
      Parameters:
      child - the widget to append
      Since:
      1.7
    • 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.

      See WrapBox:line-spacing-unit.

      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
    • insertChildAfter

      public void insertChildAfter(Widget child, @Nullable Widget sibling)

      Inserts child in the position after sibling in the list of this WrapBox children.

      If sibling is NULL, inserts child at the first position.

      Parameters:
      child - the widget to insert
      sibling - the sibling after which to insert child
      Since:
      1.7
    • prepend

      public void prepend(Widget child)
      Adds child as the first child to self.
      Parameters:
      child - the widget to prepend
      Since:
      1.7
    • remove

      public void remove(Widget child)

      Removes a child widget from self.

      The child must have been added before with append(Widget), prepend(Widget), or insertChildAfter(Widget, Widget).

      Parameters:
      child - the child to remove
      Since:
      1.7
    • removeAll

      public void removeAll()
      Removes all children from self.
      Since:
      1.8
    • reorderChildAfter

      public void reorderChildAfter(Widget child, @Nullable Widget sibling)

      Moves child to the position after sibling in the list of this WrapBox children.

      If sibling is NULL, moves child to the first position.

      Parameters:
      child - the widget to move, must be a child of this WrapBox
      sibling - the sibling to move child after
      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 WrapBox:justify is set to Adw.JustifyMode.none, or on the last line when the WrapBox: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 WrapBox: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 WrapBox:child-spacing.

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

      public void setJustify(JustifyMode justify)

      Determines 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 WrapBox:align.

      By default this doesn't affect the last line, as it will be incomplete. Use WrapBox: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 WrapBox: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.
      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 WrapBox: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 WrapBox: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 WrapBox: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 WrapBox.Builder<? extends WrapBox.Builder> builder()
      A WrapBox.Builder object constructs a WrapBox with the specified properties. Use the various set...() methods to set properties, and finish construction with WrapBox.Builder.build().
      Returns:
      the builder object