Class: Gtk::FlowBox

Inherits:
Widget
  • Object
show all
Defined in:
(unknown)

Overview

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 [methodGtk.FlowBox.insert], and a
GtkFlowBoxChild widget will automatically be inserted between the box
and the widget.

Also see [classGtk.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.

Instance Method Summary collapse

Methods inherited from Widget

#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #error_bell, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_size_request, #set_state_flags, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #template=, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=

Constructor Details

#initializeGtk::Widget

Creates a GtkFlowBox.

Instance Method Details

#accept_unpaired_release=(accept_unpaired_release) ⇒ Boolean

Parameters:

  • accept_unpaired_release (Boolean)

Returns:

  • (Boolean)

    accept-unpaired-release

  • (Boolean)

    accept-unpaired-release

#accept_unpaired_release?Boolean

Returns accept-unpaired-release.

Returns:

  • (Boolean)

    accept-unpaired-release

#activate_on_single_clickBoolean

Returns whether children activate on single clicks.

Returns:

  • (Boolean)

    true if children are activated on single click,
    false otherwise

#activate_on_single_click=(activate_on_single_click) ⇒ Boolean

Determines whether children can be activated with a single
click, or require a double-click.

Parameters:

  • activate_on_single_click (Boolean)

Returns:

  • (Boolean)

    activate-on-single-click

  • (Boolean)

    activate-on-single-click

#activate_on_single_click?Boolean

Determines whether children can be activated with a single
click, or require a double-click.

Returns:

  • (Boolean)

    activate-on-single-click

#append(child) ⇒ nil

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: [methodGtk.FlowBox.insert].

Parameters:

Returns:

  • (nil)

#bind_model(model, create_widget_func, user_data, user_data_free_func) ⇒ nil

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 nil, box is left empty.

It is undefined to add or remove widgets directly (for example, with
[methodGtk.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 (Gio::ListModel)

    the GListModel to be bound to box

  • create_widget_func (Gtk::FlowBoxCreateWidgetFunc)

    a function that creates widgets for items

  • user_data (GObject)

    user data passed to create_widget_func

  • user_data_free_func (GLib::DestroyNotify)

    function for freeing user_data

Returns:

  • (nil)

#column_spacingInteger

The amount of horizontal space between two children.

Returns:

  • (Integer)

    column-spacing

#column_spacing=(column_spacing) ⇒ Integer

The amount of horizontal space between two children.

Parameters:

  • column_spacing (Integer)

Returns:

  • (Integer)

    column-spacing

  • (Integer)

    column-spacing

#get_child_at_index(idx) ⇒ Gtk::FlowBoxChild

Gets the nth child in the box.

Parameters:

  • idx (Integer)

    the position of the child

Returns:

  • (Gtk::FlowBoxChild)

    the child widget, which will
    always be a GtkFlowBoxChild or nil in case no child widget
    with the given index exists.

#get_child_at_pos(x, y) ⇒ Gtk::FlowBoxChild

Gets the child in the (x, y) position.

Both x and y are assumed to be relative to the origin of box.

Parameters:

  • x (Integer)

    the x coordinate of the child

  • y (Integer)

    the y coordinate of the child

Returns:

  • (Gtk::FlowBoxChild)

    the child widget, which will
    always be a GtkFlowBoxChild or nil in case no child widget
    exists for the given x and y coordinates.

#hadjustment=(adjustment) ⇒ nil

Hooks up an adjustment to focus handling in box.

The adjustment is also used for autoscrolling during
rubberband selection. See [methodGtk.ScrolledWindow.get_hadjustment]
for a typical way of obtaining the adjustment, and
[methodGtk.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 (Gtk::Adjustment)

    an adjustment which should be adjusted
    when the focus is moved among the descendents of container

Returns:

  • (nil)

#homogeneousBoolean

Returns whether the box is homogeneous.

Returns:

  • (Boolean)

    true if the box is homogeneous.

#homogeneous=(homogeneous) ⇒ Boolean

Determines whether all children should be allocated the
same size.

Parameters:

  • homogeneous (Boolean)

Returns:

  • (Boolean)

    homogeneous

  • (Boolean)

    homogeneous

#homogeneous?Boolean

Determines whether all children should be allocated the
same size.

Returns:

  • (Boolean)

    homogeneous

#insert(widget, position) ⇒ nil

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 (Gtk::Widget)

    the GtkWidget to add

  • position (Integer)

    the position to insert child in

Returns:

  • (nil)

#invalidate_filternil

Updates the filtering for all children.

Call this function when the result of the filter
function on the box is changed due to 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.

Returns:

  • (nil)

#invalidate_sortnil

Updates the sorting for all children.

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

Returns:

  • (nil)

#max_children_per_lineInteger

The maximum amount of children to request space for consecutively
in the given orientation.

Returns:

  • (Integer)

    max-children-per-line

#max_children_per_line=(max_children_per_line) ⇒ Integer

The maximum amount of children to request space for consecutively
in the given orientation.

Parameters:

  • max_children_per_line (Integer)

Returns:

  • (Integer)

    max-children-per-line

  • (Integer)

    max-children-per-line

#min_children_per_lineInteger

The minimum number of children to allocate consecutively
in the given orientation.

Setting the minimum children per line ensures
that a reasonably small height will be requested
for the overall minimum width of the box.

Returns:

  • (Integer)

    min-children-per-line

#min_children_per_line=(min_children_per_line) ⇒ Integer

The minimum number of children to allocate consecutively
in the given orientation.

Setting the minimum children per line ensures
that a reasonably small height will be requested
for the overall minimum width of the box.

Parameters:

  • min_children_per_line (Integer)

Returns:

  • (Integer)

    min-children-per-line

  • (Integer)

    min-children-per-line

#prepend(child) ⇒ nil

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: [methodGtk.FlowBox.insert].

Parameters:

Returns:

  • (nil)

#remove(widget) ⇒ nil

Removes a child from box.

Parameters:

Returns:

  • (nil)

#remove_allnil

Removes all children from box.

This function does nothing if box is backed by a model.

Returns:

  • (nil)

#row_spacingInteger

The amount of vertical space between two children.

Returns:

  • (Integer)

    row-spacing

#row_spacing=(row_spacing) ⇒ Integer

The amount of vertical space between two children.

Parameters:

  • row_spacing (Integer)

Returns:

  • (Integer)

    row-spacing

  • (Integer)

    row-spacing

#select_allnil

Select all children of box, if the selection
mode allows it.

Returns:

  • (nil)

#select_child(child) ⇒ nil

Selects a single child of box, if the selection
mode allows it.

Parameters:

Returns:

  • (nil)

#selected_childrenGLib::List<Gtk::FlowBoxChild>

Creates a list of all selected children.

Returns:

  • (GLib::List<Gtk::FlowBoxChild>)

    A GList containing the GtkWidget for each selected child.
    Free with g_list_free() when done.

#selected_foreach(func, data) ⇒ nil

Calls a function for each selected child.

Note that the selection cannot be modified from within
this function.

Parameters:

  • func (Gtk::FlowBoxForeachFunc)

    the function to call for each selected child

  • data (GObject)

    user data to pass to the function

Returns:

  • (nil)

#selection_modeGtk::SelectionMode

The selection mode used by the flow box.

Returns:

#selection_mode=(selection_mode) ⇒ Gtk::SelectionMode

The selection mode used by the flow box.

Parameters:

Returns:

#set_filter_func(filter_func, user_data, destroy) ⇒ nil

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
[methodGtk.FlowBoxChild.changed]) or when
[methodGtk.FlowBox.invalidate_filter] is called.

Note that using a filter function is incompatible with using a model
(see [methodGtk.FlowBox.bind_model]).

Parameters:

  • filter_func (Gtk::FlowBoxFilterFunc)

    callback that
    lets you filter which children to show

  • user_data (GObject)

    user data passed to filter_func

  • destroy (GLib::DestroyNotify)

    destroy notifier for user_data

Returns:

  • (nil)

#set_sort_func(sort_func, user_data, destroy) ⇒ nil

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
[methodGtk.FlowBoxChild.changed]) and when
[methodGtk.FlowBox.invalidate_sort] is called.

Note that using a sort function is incompatible with using a model
(see [methodGtk.FlowBox.bind_model]).

Parameters:

  • sort_func (Gtk::FlowBoxSortFunc)

    the sort function

  • user_data (GObject)

    user data passed to sort_func

  • destroy (GLib::DestroyNotify)

    destroy notifier for user_data

Returns:

  • (nil)

#unselect_allnil

Unselect all children of box, if the selection
mode allows it.

Returns:

  • (nil)

#unselect_child(child) ⇒ nil

Unselects a single child of box, if the selection
mode allows it.

Parameters:

Returns:

  • (nil)

#vadjustment=(adjustment) ⇒ nil

Hooks up an adjustment to focus handling in box.

The adjustment is also used for autoscrolling during
rubberband selection. See [methodGtk.ScrolledWindow.get_vadjustment]
for a typical way of obtaining the adjustment, and
[methodGtk.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 (Gtk::Adjustment)

    an adjustment which should be adjusted
    when the focus is moved among the descendents of container

Returns:

  • (nil)