Class FlowBox

All Implemented Interfaces:
PointerInterface

public class FlowBox extends Widget
A `GtkFlowBox` puts child widgets in reflowing grid.

For instance, with the horizontal orientation, the widgets will be
arranged from left to right, starting a new row under the previous
row when necessary. Reducing the width in this case will require more
rows, so a larger height will be requested.

Likewise, with the vertical orientation, the widgets will be arranged
from top to bottom, starting a new column to the right when necessary.
Reducing the height will require more columns, so a larger width will
be requested.

The size request of a `GtkFlowBox` alone may not be what you expect;
if you need to be able to shrink it along both axes and dynamically
reflow its children, you may have to wrap it in a `GtkScrolledWindow`
to enable that.

The children of a `GtkFlowBox` can be dynamically sorted and filtered.

Although a `GtkFlowBox` must have only `GtkFlowBoxChild` children, you
can add any kind of widget to it via [method@Gtk.FlowBox.insert], and a
`GtkFlowBoxChild` widget will automatically be inserted between the box
and the widget.

Also see [class@Gtk.ListBox].

# CSS nodes

```
flowbox
├── flowboxchild
│ ╰── <child>
├── flowboxchild
│ ╰── <child>

╰── [rubberband]
```

`GtkFlowBox` uses a single CSS node with name flowbox. `GtkFlowBoxChild`
uses a single CSS node with name flowboxchild. For rubberband selection,
a subnode with name rubberband is used.

# Accessibility

`GtkFlowBox` uses the %GTK_ACCESSIBLE_ROLE_GRID role, and `GtkFlowBoxChild`
uses the %GTK_ACCESSIBLE_ROLE_GRID_CELL role.

https://docs.gtk.org/gtk4/class.FlowBox.html

  • Field Details

  • Constructor Details

    • FlowBox

      public FlowBox(PointerContainer pointer)
    • FlowBox

      public FlowBox()
      Creates a `GtkFlowBox`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • append

      public void append(@Nonnull Widget child)
      Adds @child to the end of @self.

      If a sort function is set, the widget will
      actually be inserted at the calculated position.

      See also: [method@Gtk.FlowBox.insert].
      Parameters:
      child - the `GtkWidget` to add
    • bindModel

      public void bindModel(@Nullable ListModel model, FlowBox.OnFlowBoxCreateWidgetFunc create_widget_func, @Nullable Pointer user_data, FlowBox.OnDestroyNotify user_data_free_func)
      Binds @model to @box.

      If @box was already bound to a model, that previous binding is
      destroyed.

      The contents of @box are cleared and then filled with widgets that
      represent items from @model. @box is updated whenever @model changes.
      If @model is %NULL, @box is left empty.

      It is undefined to add or remove widgets directly (for example, with
      [method@Gtk.FlowBox.insert]) while @box is bound to a model.

      Note that using a model is incompatible with the filtering and sorting
      functionality in `GtkFlowBox`. When using a model, filtering and sorting
      should be implemented by the model.
      Parameters:
      model - the `GListModel` to be bound to @box
      create_widget_func - a function that creates widgets for items
      user_data - user data passed to @create_widget_func
      user_data_free_func - function for freeing @user_data
    • getActivateOnSingleClick

      public boolean getActivateOnSingleClick()
      Returns whether children activate on single clicks.
      Returns:
      %TRUE if children are activated on single click, %FALSE otherwise
    • getChildAtIndex

      public FlowBoxChild getChildAtIndex(int idx)
      Gets the nth child in the @box.
      Parameters:
      idx - the position of the child
      Returns:
      the child widget, which will always be a `GtkFlowBoxChild` or %NULL in case no child widget with the given index exists.
    • getChildAtPos

      public FlowBoxChild getChildAtPos(int x, int y)
      Gets the child in the (@x, @y) position.

      Both @x and @y are assumed to be relative to the origin of @box.
      Parameters:
      x - the x coordinate of the child
      y - the y coordinate of the child
      Returns:
      the child widget, which will always be a `GtkFlowBoxChild` or %NULL in case no child widget exists for the given x and y coordinates.
    • getColumnSpacing

      public int getColumnSpacing()
      Gets the horizontal spacing.
      Returns:
      the horizontal spacing
    • getHomogeneous

      public boolean getHomogeneous()
      Returns whether the box is homogeneous.
      Returns:
      %TRUE if the box is homogeneous.
    • getMaxChildrenPerLine

      public int getMaxChildrenPerLine()
      Gets the maximum number of children per line.
      Returns:
      the maximum number of children per line
    • getMinChildrenPerLine

      public int getMinChildrenPerLine()
      Gets the minimum number of children per line.
      Returns:
      the minimum number of children per line
    • getRowSpacing

      public int getRowSpacing()
      Gets the vertical spacing.
      Returns:
      the vertical spacing
    • getSelectedChildren

      public List getSelectedChildren()
      Creates a list of all selected children.
      Returns:
      A `GList` containing the `GtkWidget` for each selected child. Free with g_list_free() when done.
    • getSelectionMode

      public int getSelectionMode()
      Gets the selection mode of @box.
      Returns:
      the `GtkSelectionMode`
    • insert

      public void insert(@Nonnull Widget widget, int position)
      Inserts the @widget into @box at @position.

      If a sort function is set, the widget will actually be inserted
      at the calculated position.

      If @position is -1, or larger than the total number of children
      in the @box, then the @widget will be appended to the end.
      Parameters:
      widget - the `GtkWidget` to add
      position - the position to insert @child in
    • invalidateFilter

      public void invalidateFilter()
      Updates the filtering for all children.

      Call this function when the result of the filter
      function on the @box is changed due ot an external
      factor. For instance, this would be used if the
      filter function just looked for a specific search
      term, and the entry with the string has changed.
    • invalidateSort

      public void invalidateSort()
      Updates the sorting for all children.

      Call this when the result of the sort function on
      @box is changed due to an external factor.
    • prepend

      public void prepend(@Nonnull Widget child)
      Adds @child to the start of @self.

      If a sort function is set, the widget will
      actually be inserted at the calculated position.

      See also: [method@Gtk.FlowBox.insert].
      Parameters:
      child - the `GtkWidget` to add
    • remove

      public void remove(@Nonnull Widget widget)
      Removes a child from @box.
      Parameters:
      widget - the child widget to remove
    • selectAll

      public void selectAll()
      Select all children of @box, if the selection
      mode allows it.
    • selectChild

      public void selectChild(@Nonnull FlowBoxChild child)
      Selects a single child of @box, if the selection
      mode allows it.
      Parameters:
      child - a child of @box
    • selectedForeach

      public void selectedForeach(FlowBox.OnFlowBoxForeachFunc func, @Nullable Pointer data)
      Calls a function for each selected child.

      Note that the selection cannot be modified from within
      this function.
      Parameters:
      func - the function to call for each selected child
      data - user data to pass to the function
    • setActivateOnSingleClick

      public void setActivateOnSingleClick(boolean single)
      If @single is %TRUE, children will be activated when you click
      on them, otherwise you need to double-click.
      Parameters:
      single - %TRUE to emit child-activated on a single click
    • setColumnSpacing

      public void setColumnSpacing(int spacing)
      Sets the horizontal space to add between children.
      Parameters:
      spacing - the spacing to use
    • setFilterFunc

      public void setFilterFunc(FlowBox.OnFlowBoxFilterFunc filter_func, @Nullable Pointer user_data, FlowBox.OnDestroyNotify destroy)
      By setting a filter function on the @box one can decide dynamically
      which of the children to show.

      For instance, to implement a search function that only shows the
      children matching the search terms.

      The @filter_func will be called for each child after the call, and
      it will continue to be called each time a child changes (via
      [method@Gtk.FlowBoxChild.changed]) or when
      [method@Gtk.FlowBox.invalidate_filter] is called.

      Note that using a filter function is incompatible with using a model
      (see [method@Gtk.FlowBox.bind_model]).
      Parameters:
      filter_func - callback that lets you filter which children to show
      user_data - user data passed to @filter_func
      destroy - destroy notifier for @user_data
    • setHadjustment

      public void setHadjustment(@Nonnull Adjustment adjustment)
      Hooks up an adjustment to focus handling in @box.

      The adjustment is also used for autoscrolling during
      rubberband selection. See [method@Gtk.ScrolledWindow.get_hadjustment]
      for a typical way of obtaining the adjustment, and
      [method@Gtk.FlowBox.set_vadjustment] for setting the vertical
      adjustment.

      The adjustments have to be in pixel units and in the same
      coordinate system as the allocation for immediate children
      of the box.
      Parameters:
      adjustment - an adjustment which should be adjusted when the focus is moved among the descendents of @container
    • setHomogeneous

      public void setHomogeneous(boolean homogeneous)
      Sets whether or not all children of @box are given
      equal space in the box.
      Parameters:
      homogeneous - %TRUE to create equal allotments, %FALSE for variable allotments
    • setMaxChildrenPerLine

      public void setMaxChildrenPerLine(int n_children)
      Sets the maximum number of children to request and
      allocate space for in @box’s orientation.

      Setting the maximum number of children per line
      limits the overall natural size request to be no more
      than @n_children children long in the given orientation.
      Parameters:
      n_children - the maximum number of children per line
    • setMinChildrenPerLine

      public void setMinChildrenPerLine(int n_children)
      Sets the minimum number of children to line up
      in @box’s orientation before flowing.
      Parameters:
      n_children - the minimum number of children per line
    • setRowSpacing

      public void setRowSpacing(int spacing)
      Sets the vertical space to add between children.
      Parameters:
      spacing - the spacing to use
    • setSelectionMode

      public void setSelectionMode(int mode)
      Sets how selection works in @box.
      Parameters:
      mode - the new selection mode
    • setSortFunc

      public void setSortFunc(FlowBox.OnFlowBoxSortFunc sort_func, @Nullable Pointer user_data, FlowBox.OnDestroyNotify destroy)
      By setting a sort function on the @box, one can dynamically
      reorder the children of the box, based on the contents of
      the children.

      The @sort_func will be called for each child after the call,
      and will continue to be called each time a child changes (via
      [method@Gtk.FlowBoxChild.changed]) and when
      [method@Gtk.FlowBox.invalidate_sort] is called.

      Note that using a sort function is incompatible with using a model
      (see [method@Gtk.FlowBox.bind_model]).
      Parameters:
      sort_func - the sort function
      user_data - user data passed to @sort_func
      destroy - destroy notifier for @user_data
    • setVadjustment

      public void setVadjustment(@Nonnull Adjustment adjustment)
      Hooks up an adjustment to focus handling in @box.

      The adjustment is also used for autoscrolling during
      rubberband selection. See [method@Gtk.ScrolledWindow.get_vadjustment]
      for a typical way of obtaining the adjustment, and
      [method@Gtk.FlowBox.set_hadjustment] for setting the horizontal
      adjustment.

      The adjustments have to be in pixel units and in the same
      coordinate system as the allocation for immediate children
      of the box.
      Parameters:
      adjustment - an adjustment which should be adjusted when the focus is moved among the descendents of @container
    • unselectAll

      public void unselectAll()
      Unselect all children of @box, if the selection
      mode allows it.
    • unselectChild

      public void unselectChild(@Nonnull FlowBoxChild child)
      Unselects a single child of @box, if the selection
      mode allows it.
      Parameters:
      child - a child of @box
    • onActivateCursorChild

      public SignalHandler onActivateCursorChild(FlowBox.OnActivateCursorChild signal)
      Connect to signal "activate-cursor-child".
      See FlowBox.OnActivateCursorChild.onActivateCursorChild() for signal description.
      Field SIGNAL_ON_ACTIVATE_CURSOR_CHILD contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onChildActivated

      public SignalHandler onChildActivated(FlowBox.OnChildActivated signal)
      Connect to signal "child-activated".
      See FlowBox.OnChildActivated.onChildActivated(ch.bailu.gtk.gtk.FlowBoxChild) for signal description.
      Field SIGNAL_ON_CHILD_ACTIVATED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onMoveCursor

      public SignalHandler onMoveCursor(FlowBox.OnMoveCursor signal)
      Connect to signal "move-cursor".
      See FlowBox.OnMoveCursor.onMoveCursor(int, int, boolean, boolean) for signal description.
      Field SIGNAL_ON_MOVE_CURSOR contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onSelectAll

      public SignalHandler onSelectAll(FlowBox.OnSelectAll signal)
      Connect to signal "select-all".
      See FlowBox.OnSelectAll.onSelectAll() for signal description.
      Field SIGNAL_ON_SELECT_ALL contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onSelectedChildrenChanged

      public SignalHandler onSelectedChildrenChanged(FlowBox.OnSelectedChildrenChanged signal)
      Connect to signal "selected-children-changed".
      See FlowBox.OnSelectedChildrenChanged.onSelectedChildrenChanged() for signal description.
      Field SIGNAL_ON_SELECTED_CHILDREN_CHANGED contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onToggleCursorChild

      public SignalHandler onToggleCursorChild(FlowBox.OnToggleCursorChild signal)
      Connect to signal "toggle-cursor-child".
      See FlowBox.OnToggleCursorChild.onToggleCursorChild() for signal description.
      Field SIGNAL_ON_TOGGLE_CURSOR_CHILD contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • onUnselectAll

      public SignalHandler onUnselectAll(FlowBox.OnUnselectAll signal)
      Connect to signal "unselect-all".
      See FlowBox.OnUnselectAll.onUnselectAll() for signal description.
      Field SIGNAL_ON_UNSELECT_ALL contains original signal name and can be used as resource reference.
      Parameters:
      signal - callback function (lambda).
      Returns:
      SignalHandler. Can be used to disconnect signal and to release callback function.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class Widget
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class Widget
      Returns:
      Buildable
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class Widget
      Returns:
      ConstraintTarget
    • asOrientable

      public Orientable asOrientable()
      Implements interface Orientable. Call this to get access to interface functions.
      Returns:
      Orientable
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()