Gnome::Gtk4::FlowBox
Description
A Gnome::Gtk4::FlowBox 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 Gnome::Gtk4::FlowBox 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 Gnome::Gtk4::ScrolledWindow to enable that.
The children of a Gnome::Gtk4::FlowBox can be dynamically sorted and filtered.
Although a Gnome::Gtk4::FlowBox must have only Gnome::Gtk4::FlowBoxChild children, you can add any kind of widget to it via .insert()
, and a Gnome::Gtk4::FlowBoxChild widget will automatically be inserted between the box and the widget.
Also see Gnome::Gtk4::ListBox.
CSS nodes
Gnome::Gtk4::FlowBox uses a single CSS node with name flowbox. Gnome::Gtk4::FlowBoxChild uses a single CSS node with name flowboxchild. For rubberband selection, a subnode with name rubberband is used.
Accessibility
Gnome::Gtk4::FlowBox uses the GTK_ACCESSIBLE_ROLE_GRID
role, and Gnome::Gtk4::FlowBoxChild uses the GTK_ACCESSIBLE_ROLE_GRID_CELL
role.
Class initialization
new
:native-object
Create an object using a native object from elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object :$native-object! )
new-flowbox
Creates a Gnome::Gtk4::FlowBox.
method new-flowbox ( --> Gnome::Gtk4::FlowBox \)
Methods
append
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: .insert()
.
method append ( N-Object() $child )
$child; the Gnome::Gtk4::Widget to add.
bind-model This function is not yet available
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 undefined, $box
is left empty.
It is undefined to add or remove widgets directly (for example, with .insert()
) while $box
is bound to a model.
Note that using a model is incompatible with the filtering and sorting functionality in Gnome::Gtk4::FlowBox. When using a model, filtering and sorting should be implemented by the model.
method bind-model ( N-List() $model, &create-widget-func, gpointer $user-data, … )
$model; the Gnome::Gio::R-ListModel to be bound to
$box
.&create-widget-func; a function that creates widgets for items. Tthe function must be specified with following signature;
:( gpointer $item, gpointer $user-data --
N-Object )>.$user-data; user data passed to
$create-widget-func
.user-data-free-func; function for freeing
$user-data
. Note that each argument must be specified as a type followed by its value!
get-activate-on-single-click
Returns whether children activate on single clicks.
method get-activate-on-single-click (--> Bool )
Return value; True
if children are activated on single click, False
otherwise.
get-child-at-index
Gets the nth child in the $box
.
method get-child-at-index ( Int() $idx --> N-Object )
$idx; the position of the child.
Return value; the child widget, which will always be a Gnome::Gtk4::FlowBoxChild or undefined in case no child widget with the given index exists..
get-child-at-pos
Gets the child in the ( $x
, $y
) position.
Both $x
and $y
are assumed to be relative to the origin of $box
.
method get-child-at-pos ( Int() $x, Int() $y --> N-Object )
$x; the x coordinate of the child.
$y; the y coordinate of the child.
Return value; the child widget, which will always be a Gnome::Gtk4::FlowBoxChild or undefined in case no child widget exists for the given x and y coordinates..
get-column-spacing
Gets the horizontal spacing.
method get-column-spacing (--> UInt )
Return value; the horizontal spacing.
get-homogeneous
Returns whether the box is homogeneous.
method get-homogeneous (--> Bool )
Return value; True
if the box is homogeneous..
get-max-children-per-line
Gets the maximum number of children per line.
method get-max-children-per-line (--> UInt )
Return value; the maximum number of children per line.
get-min-children-per-line
Gets the minimum number of children per line.
method get-min-children-per-line (--> UInt )
Return value; the minimum number of children per line.
get-row-spacing
Gets the vertical spacing.
method get-row-spacing (--> UInt )
Return value; the vertical spacing.
get-selected-children
Creates a list of all selected children.
method get-selected-children (--> N-List )
Return value; A Gnome::Glib::N-List containing the Gnome::Gtk4::Widget for each selected child. Free with g_list_free() when done..
get-selection-mode
Gets the selection mode of $box
.
method get-selection-mode (--> GtkSelectionMode )
Return value; the enumeration GtkSelectionMode defined in Gnome::Gtk4::T-enums
.
insert
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.
method insert ( N-Object() $widget, Int() $position )
$widget; the Gnome::Gtk4::Widget to add.
$position; the position to insert
$child
in.
invalidate-filter
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.
method invalidate-filter ( )
invalidate-sort
Updates the sorting for all children.
Call this when the result of the sort function on $box
is changed due to an external factor.
method invalidate-sort ( )
prepend
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: .insert()
.
method prepend ( N-Object() $child )
$child; the Gnome::Gtk4::Widget to add.
remove
Removes a child from $box
.
method remove ( N-Object() $widget )
$widget; the child widget to remove.
remove-all
Removes all children from $box
.
This function does nothing if $box
is backed by a model.
method remove-all ( )
select-all
Select all children of $box
, if the selection mode allows it.
method select-all ( )
select-child
Selects a single child of $box
, if the selection mode allows it.
method select-child ( N-Object() $child )
$child; a child of
$box
.
selected-foreach
Calls a function for each selected child.
Note that the selection cannot be modified from within this function.
method selected-foreach ( &func, gpointer $data )
&func; the function to call for each selected child. Tthe function must be specified with following signature;
:( N-Object $box, N-Object $child, gpointer $user-data )
.$data; user data to pass to the function.
set-activate-on-single-click
If $single
is True
, children will be activated when you click on them, otherwise you need to double-click.
method set-activate-on-single-click ( Bool() $single )
$single;
True
to emit child-activated on a single click.
set-column-spacing
Sets the horizontal space to add between children.
method set-column-spacing ( UInt() $spacing )
$spacing; the spacing to use.
set-filter-func This function is not yet available
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 .changed() in class Gnome::Gtk4::FlowBoxChild
) or when .invalidate-filter()
is called.
Note that using a filter function is incompatible with using a model (see .bind-model()
).
method set-filter-func ( &filter-func, gpointer $user-data, … )
&filter-func; callback that lets you filter which children to show. Tthe function must be specified with following signature;
:( N-Object $child, gpointer $user-data --
gboolean )>.$user-data; user data passed to
$filter-func
.destroy; destroy notifier for
$user-data
. Note that each argument must be specified as a type followed by its value!
set-hadjustment
Hooks up an adjustment to focus handling in $box
.
The adjustment is also used for autoscrolling during rubberband selection. See .get-hadjustment() in class Gnome::Gtk4::ScrolledWindow
for a typical way of obtaining the adjustment, and .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.
method set-hadjustment ( N-Object() $adjustment )
$adjustment; an adjustment which should be adjusted when the focus is moved among the descendents of
$container
.
set-homogeneous
Sets whether or not all children of $box
are given equal space in the box.
method set-homogeneous ( Bool() $homogeneous )
$homogeneous;
True
to create equal allotments,False
for variable allotments.
set-max-children-per-line
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.
method set-max-children-per-line ( UInt() $n-children )
$n-children; the maximum number of children per line.
set-min-children-per-line
Sets the minimum number of children to line up in $box
’s orientation before flowing.
method set-min-children-per-line ( UInt() $n-children )
$n-children; the minimum number of children per line.
set-row-spacing
Sets the vertical space to add between children.
method set-row-spacing ( UInt() $spacing )
$spacing; the spacing to use.
set-selection-mode
Sets how selection works in $box
.
method set-selection-mode ( GtkSelectionMode $mode )
$mode; the new selection mode.
set-sort-func This function is not yet available
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 .changed() in class Gnome::Gtk4::FlowBoxChild
) and when .invalidate-sort()
is called.
Note that using a sort function is incompatible with using a model (see .bind-model()
).
method set-sort-func ( &sort-func, gpointer $user-data, … )
&sort-func; the sort function. Tthe function must be specified with following signature;
:( N-Object $child1, N-Object $child2, gpointer $user-data --
gint )>.$user-data; user data passed to
$sort-func
.destroy; destroy notifier for
$user-data
. Note that each argument must be specified as a type followed by its value!
set-vadjustment
Hooks up an adjustment to focus handling in $box
.
The adjustment is also used for autoscrolling during rubberband selection. See .get-vadjustment() in class Gnome::Gtk4::ScrolledWindow
for a typical way of obtaining the adjustment, and .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.
method set-vadjustment ( N-Object() $adjustment )
$adjustment; an adjustment which should be adjusted when the focus is moved among the descendents of
$container
.
unselect-all
Unselect all children of $box
, if the selection mode allows it.
method unselect-all ( )
unselect-child
Unselects a single child of $box
, if the selection mode allows it.
method unselect-child ( N-Object() $child )
$child; a child of
$box
.
Signals
activate-cursor-child
Emitted when the user activates the $box
.
This is a [keybinding signal](class.SignalAction.html).
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
child-activated
Emitted when a child has been activated by the user.
method handler ( N-Object $child, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options )
$child; the child that is activated.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
move-cursor
Emitted when the user initiates a cursor movement.
This is a [keybinding signal](class.SignalAction.html). Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.
The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifier does not. There are too many key combinations to list them all here.
<kbd>←</kbd>, <kbd>→</kbd>, <kbd>↑</kbd>, <kbd>↓</kbd> move by individual children
<kbd>Home</kbd>, <kbd>End</kbd> move to the ends of the box
<kbd>PgUp</kbd>, <kbd>PgDn</kbd> move vertically by pages
method handler ( $step, gint $count, gboolean $extend, gboolean $modify, Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options --> gboolean )
$step; the granularity of the move, as a
enumeration GtkMovementStep defined in Gnome::Gtk4::T-enums
.$count; the number of
$step
units to move.$extend; whether to extend the selection.
$modify; whether to modify the selection.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
Return value; True
to stop other handlers from being invoked for the event. False
to propagate the event further.
select-all
Emitted to select all children of the box, if the selection mode permits it.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal is <kbd>Ctrl</kbd>-<kbd>a</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
selected-children-changed
Emitted when the set of selected children changes.
Use .selected-foreach()
or .get-selected-children()
to obtain the selected children.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
toggle-cursor-child
Emitted to toggle the selection of the child that has the focus.
This is a [keybinding signal](class.SignalAction.html).
The default binding for this signal is <kbd>Ctrl</kbd>-<kbd>Space</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.
unselect-all
Emitted to unselect all children of the box, if the selection mode permits it.
This is a [keybinding signal](class.SignalAction.html).
The default bindings for this signal is <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>a</kbd>.
method handler ( Int :$_handle_id, N-GObject :$_native-object, Gnome::Gtk4::FlowBox :$_widget, *C<user>-options )
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This a native Gnome::Gtk4::FlowBox object.
$_widget; The object which registered the signal. User code may have left the object going out of scope.
user
-options; A list of named arguments provided at the.register-signal()
method from Gnome::GObject::Object.