About all my projects
Gnome::Gtk4::ListBox

Gnome::Gtk4::ListBox

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.

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-listbox

Creates a new Gnome::Gtk4::ListBox container.

method new-listbox ( --> Gnome::Gtk4::ListBox \)

Methods

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.

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::ListBox. 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 or undefined in case you also passed undefined as $model. 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!

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.

drag-unhighlight-row

If a row has previously been highlighted via .drag-highlight-row(), it will have the highlight removed.

method drag-unhighlight-row ( )

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.

get-adjustment

Gets the adjustment (if any) that the widget uses to for vertical scrolling.

method get-adjustment (--> N-Object )

Return value; the adjustment.

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.

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.

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.

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..

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.

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.

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 $child in.

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 ( )

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 ( )

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 ( )

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.

remove

Removes a child from $box.

method remove ( N-Object() $child )
  • $child; the child to remove.

remove-all

Removes all rows 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-row

Make $row the currently selected row.

method select-row ( N-Object() $row )
  • $row; The row to select.

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 $row, gpointer $user-data ).

  • $data; user data to pass to the function.

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.

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.

set-filter-func This function is not yet available

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 Gnome::Gtk4::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 ( &filter-func, gpointer $user-data, … )
  • &filter-func; callback that lets you filter which rows to show. Tthe function must be specified with following signature; :( N-Object $row, 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-header-func This function is not yet available

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 Gnome::Gtk4::ListBoxRow and either update the state of the widget as needed, or set a new one using .set-header() in class Gnome::Gtk4::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 Gnome::Gtk4::ListBoxRow) and when the row before changes (either by .changed() in class Gnome::Gtk4::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 ( &update-header, gpointer $user-data, … )
  • &update-header; callback that lets you add row headers. Tthe function must be specified with following signature; :( N-Object $row, N-Object $before, gpointer $user-data ).

  • $user-data; user data passed to $update-header.

  • destroy; destroy notifier for $user-data. Note that each argument must be specified as a type followed by its value!

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.

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.

set-show-separators

Sets whether the list box should show separators between rows.

method set-show-separators ( Bool() $show-separators )
  • $show-separators; True to show separators.

set-sort-func This function is not yet available

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 Gnome::Gtk4::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 ( &sort-func, gpointer $user-data, … )
  • &sort-func; the sort function. Tthe function must be specified with following signature; :( N-Object $row1, N-Object $row2, 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!

unselect-all

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

method unselect-all ( )

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.

Signals

activate-cursor-row

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::ListBox :$_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::ListBox 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

method handler (
   $object,
  gint $p0,
  gboolean $p1,
  gboolean $p2,
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::ListBox :$_widget,
  *C<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 a native Gnome::Gtk4::ListBox 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.

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,
  *C<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 a native Gnome::Gtk4::ListBox 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.

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,
  *C<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 a native Gnome::Gtk4::ListBox 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.

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,
  *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::ListBox 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-rows-changed

Emitted when the set of selected rows changes.

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::ListBox :$_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::ListBox 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-row

method handler (
  Int :$_handle_id,
  N-GObject :$_native-object,
  Gnome::Gtk4::ListBox :$_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::ListBox 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 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,
  *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::ListBox 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.