Gnome::Gtk4::ListBox
#------------------------------------------------------------------------------- #--[Class Description]---------------------------------------------------------- #-------------------------------------------------------------------------------
=begin rakudoc
Description
Gnome::Gtk4::ListBox is a vertical list.
A Gnome::Gtk4::ListBox only contains Gnome::Gtk4::ListBoxRow children. These rows can by dynamically sorted and filtered, and headers can be added dynamically depending on the row content. It also allows keyboard and mouse navigation and selection like a typical list.
Using Gnome::Gtk4::ListBox is often an alternative to Gnome::Gtk4::TreeView, especially when the list contents has a more complicated layout than what is allowed by a Gnome::Gtk4::CellRenderer, or when the contents is interactive (i.e. has a button in it).
Although a Gnome::Gtk4::ListBox must have only Gnome::Gtk4::ListBoxRow children, you can add any kind of widget to it via .prepend(), .append() and .insert() and a Gnome::Gtk4::ListBoxRow widget will automatically be inserted between the list and the widget.
GtkListBoxRows can be marked as activatable or selectable. If a row is activatable, row-activated will be emitted for it when the user tries to activate it. If it is selectable, the row will be marked as selected when the user tries to select it.
GtkListBox as GtkBuildable
The Gnome::Gtk4::ListBox implementation of the Gnome::Gtk4::R-Buildable interface supports setting a child as the placeholder by specifying โplaceholderโ as the โtypeโ attribute of a `<child>` element. See .set-placeholder() for info.
CSS nodes
Gnome::Gtk4::ListBox uses a single CSS node named list. It may carry the .separators style class, when the show-separators property is set. Each Gnome::Gtk4::ListBoxRow uses a single CSS node named row. The row nodes get the .activatable style class added when appropriate.
It may also carry the .boxed-list style class. In this case, the list will be automatically surrounded by a frame and have separators.
The main list node may also carry style classes to select the style of [list presentation](section-list-widget.html#list-styles): .rich-list, .navigation-sidebar or .data-table.
Accessibility
Gnome::Gtk4::ListBox uses the GTK_ACCESSIBLE_ROLE_LIST role and Gnome::Gtk4::ListBoxRow uses
the GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
Uml Diagram
=end rakudoc
#------------------------------------------------------------------------------- #--[Class Initialization]------------------------------------------------------- #-------------------------------------------------------------------------------
=begin rakudoc
Class initialization
new
:native-object
Create an object using a native object from an object of the same type found elsewhere. See also Gnome::N::TopLevelSupportClass.
multi method new ( N-Object() :$native-object! )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
new-listbox
Creates a new Gnome::Gtk4::ListBox container.
method new-listbox ( --> Gnome::Gtk4::ListBox )
=end rakudoc
#------------------------------------------------------------------------------- #--[Methods]-------------------------------------------------------------------- #-------------------------------------------------------------------------------
=begin rakudoc
Methods =end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
append
Append a widget to the list.
If a sort function is set, the widget will actually be inserted at the calculated position.
method append ( N-Object() $child )
$child; the Gnome::Gtk4::Widget to add.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
bind-model
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::ListBox. When using a model, filtering and sorting should be implemented by the model.
method bind-model ( N-List() $model, GtkListBoxCreateWidgetFunc &create-widget-func, gpointer $user-data, GDestroyNotify &user-data-free-func )
$model; the Gnome::Gio::R-ListModel to be bound to
$box.GtkListBoxCreateWidgetFunc &create-widget-func; a function that creates widgets for items or undefined in case you also passed undefined as
$model. The function must be specified with the following signature;:( gpointer $item, gpointer $user-data ).$user-data; user data passed to
$create-widget-func.GDestroyNotify &user-data-free-func; function for freeing
$user-data. The function must be specified with the following signature;:( gpointer $data ).
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
drag-highlight-row
Add a drag highlight to a row.
This is a helper function for implementing DnD onto a Gnome::Gtk4::ListBox.
The passed in $row will be highlighted by setting the
GTK_STATE_FLAG_DROP_ACTIVE state and any previously highlighted
row will be unhighlighted.
The row will also be unhighlighted when the widget gets a drag leave event.
method drag-highlight-row ( N-Object() $row )
$row; a Gnome::Gtk4::ListBoxRow.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
drag-unhighlight-row
If a row has previously been highlighted via .drag-highlight-row(),
it will have the highlight removed.
method drag-unhighlight-row ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-activate-on-single-click
Returns whether rows activate on single clicks.
method get-activate-on-single-click (--> Bool )
Return value; True if rows are activated on single click, False otherwise.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-adjustment
Gets the adjustment (if any) that the widget uses to for vertical scrolling.
method get-adjustment (--> N-Object )
Return value; the adjustment.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-row-at-index
Gets the n-th child in the list (not counting headers).
If $index- is negative or larger than the number of items in the
list, undefined is returned.
method get-row-at-index ( Int() $index --> N-Object )
$index; the index of the row.
Return value; the child Gnome::Gtk4::Widget.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-row-at-y
Gets the row at the $y position.
method get-row-at-y ( Int() $y --> N-Object )
$y; position.
Return value; the row.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-selected-row
Gets the selected row, or undefined if no rows are selected.
Note that the box may allow multiple selection, in which case you should use .selected-foreach() to find all selected rows.
method get-selected-row (--> N-Object )
Return value; the selected row.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-selected-rows
Creates a list of all selected children.
method get-selected-rows (--> 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..
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-selection-mode
Gets the selection mode of the listbox.
method get-selection-mode (--> GtkSelectionMode )
Return value; a enumeration GtkSelectionMode defined in Gnome::Gtk4::T-enums.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
get-show-separators
Returns whether the list box should show separators between rows.
method get-show-separators (--> Bool )
Return value; True if the list box shows separators.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
insert
Insert the $child into the $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 items in the $box, then the $child will be appended to the end.
method insert ( N-Object() $child, Int() $position )
$child; the Gnome::Gtk4::Widget to add.
$position; the position to insert
$childin.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
invalidate-filter
Update the filtering for all rows.
Call this when 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
string and the entry with the search string has changed.
method invalidate-filter ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
invalidate-headers
Update the separators for all rows.
Call this when result
of the header function on the $box is changed due
to an external factor.
method invalidate-headers ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
invalidate-sort
Update the sorting for all rows.
Call this when result
of the sort function on the $box is changed due
to an external factor.
method invalidate-sort ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
prepend
Prepend a widget to the list.
If a sort function is set, the widget will actually be inserted at the calculated position.
method prepend ( N-Object() $child )
$child; the Gnome::Gtk4::Widget to add.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
remove
Removes a child from $box.
method remove ( N-Object() $child )
$child; the child to remove.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
remove-all
Removes all rows from $box.
This function does nothing if $box is backed by a model.
method remove-all ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
select-all
Select all children of $box, if the selection mode allows it.
method select-all ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
select-row
Make $row the currently selected row.
method select-row ( N-Object() $row )
$row; The row to select.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
selected-foreach
Calls a function for each selected child.
Note that the selection cannot be modified from within this function.
method selected-foreach ( GtkListBoxForeachFunc &func, gpointer $data )
GtkListBoxForeachFunc &func; the function to call for each selected child. The function must be specified with the following signature;
:( N-Object $box, N-Object $row, gpointer $user-data ).$data; user data to pass to the function.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-activate-on-single-click
If $single is True, rows will be activated when you click on them,
otherwise you need to double-click.
method set-activate-on-single-click ( Bool() $single )
$single; a boolean.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-adjustment
Sets the adjustment (if any) that the widget uses to for vertical scrolling.
For instance, this is used to get the page size for PageUp/Down key handling.
In the normal case when the $box is packed inside
a Gnome::Gtk4::ScrolledWindow the adjustment from that will
be picked up automatically, so there is no need
to manually do that.
method set-adjustment ( N-Object() $adjustment )
$adjustment; the adjustment.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-filter-func
By setting a filter function on the $box one can decide dynamically which
of the rows to show.
For instance, to implement a search function on a list that filters the original list to only show the matching rows.
The $filter-func will be called for each row after the call, and
it will continue to be called each time a row changes (via
.changed() in class ListBoxRow) 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 ( GtkListBoxFilterFunc &filter-func, gpointer $user-data, GDestroyNotify &destroy )
GtkListBoxFilterFunc &filter-func; callback that lets you filter which rows to show. The function must be specified with the following signature;
:( N-Object $row, gpointer $user-data ).$user-data; user data passed to
$filter-func.GDestroyNotify &destroy; destroy notifier for
$user-data. The function must be specified with the following signature;:( gpointer $data ).
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-header-func
Sets a header function.
By setting a header function on the $box one can dynamically add headers
in front of rows, depending on the contents of the row and its position
in the list.
For instance, one could use it to add headers in front of the first item of a new kind, in a list sorted by the kind.
The $update-header can look at the current header widget using
.get-header() in class ListBoxRow and either update the state of the widget
as needed, or set a new one using .set-header() in class ListBoxRow. If no
header is needed, set the header to undefined.
Note that you may get many calls $update-header to this for a particular
row when e.g. changing things that donโt affect the header. In this case
it is important for performance to not blindly replace an existing header
with an identical one.
The $update-header function will be called for each row after the call,
and it will continue to be called each time a row changes (via
.changed() in class ListBoxRow) and when the row before changes (either
by .changed() in class ListBoxRow on the previous row, or when the previous
row becomes a different row). It is also called for all rows when
.invalidate-headers() is called.
method set-header-func ( GtkListBoxUpdateHeaderFunc &update-header, gpointer $user-data, GDestroyNotify &destroy )
GtkListBoxUpdateHeaderFunc &update-header; callback that lets you add row headers. The function must be specified with the following signature;
:( N-Object $row, N-Object $before, gpointer $user-data ).$user-data; user data passed to
$update-header.GDestroyNotify &destroy; destroy notifier for
$user-data. The function must be specified with the following signature;:( gpointer $data ).
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-placeholder
Sets the placeholder widget that is shown in the list when it doesn't display any visible children.
method set-placeholder ( N-Object() $placeholder )
$placeholder; a Gnome::Gtk4::Widget.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-selection-mode
Sets how selection works in the listbox.
method set-selection-mode ( GtkSelectionMode $mode )
$mode; The
enumeration GtkSelectionMode defined in Gnome::Gtk4::T-enums.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-show-separators
Sets whether the list box should show separators between rows.
method set-show-separators ( Bool() $show-separators )
$show-separators;
Trueto show separators.
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
set-sort-func
Sets a sort function.
By setting a sort function on the $box one can dynamically reorder
the rows of the list, based on the contents of the rows.
The $sort-func will be called for each row after the call, and will
continue to be called each time a row changes (via
.changed() in class ListBoxRow) 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 ( GtkListBoxSortFunc &sort-func, gpointer $user-data, GDestroyNotify &destroy )
GtkListBoxSortFunc &sort-func; the sort function. The function must be specified with the following signature;
:( N-Object $row1, N-Object $row2, gpointer $user-data ).$user-data; user data passed to
$sort-func.GDestroyNotify &destroy; destroy notifier for
$user-data. The function must be specified with the following signature;:( gpointer $data ).
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
unselect-all
Unselect all children of $box, if the selection mode allows it.
method unselect-all ( )
=end rakudoc
#------------------------------------------------------------------------------- =begin rakudoc
unselect-row
Unselects a single row of $box, if the selection mode allows it.
method unselect-row ( N-Object() $row )
$row; the row to unselect.
=end rakudoc
#------------------------------------------------------------------------------- #--[Signal Documentation]------------------------------------------------------- #-------------------------------------------------------------------------------
=begin rakudoc
Signals
activate-cursor-row
method handler (
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
move-cursor
method handler (
$object,
gint $p0,
gboolean $p1,
gboolean $p2,
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$object; .
$p0; .
$p1; .
$p2; .
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
row-activated
Emitted when a row has been activated by the user.
method handler (
N-Object $row,
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$row; the activated row.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
row-selected
Emitted when a new row is selected, or (with a undefined $row)
when the selection is cleared.
When the $box is using GTK_SELECTION_MULTIPLE, this signal will not
give you the full picture of selection changes, and you should use
the selected-rows-changed signal instead.
method handler (
N-Object $row,
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$row; the selected row.
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
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 binding for this signal is <kbd>Ctrl</kbd>-<kbd>a</kbd>.
method handler (
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
selected-rows-changed
Emitted when the set of selected rows changes.
method handler (
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
toggle-cursor-row
method handler (
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class 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 binding for this signal is <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>a</kbd>.
method handler (
Int :$_handle_id,
N-GObject :$_native-object,
Gnome::Gtk4::ListBox :$_widget,
*%user-options
)
$_handle_id; The registered event handler id.
$_native-object; The native object provided by the Raku object which registered this event. This is a native Gnome::Gtk4::ListBox object.
%user-options; A list of named arguments provided by .register-signal() in class Object.
=end rakudoc