Struct gtk4::ListBox[][src]

pub struct ListBox(_);
Expand description

ListBox is a vertical list.

A ListBox only contains 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 ListBox is often an alternative to TreeView, especially when the list contents has a more complicated layout than what is allowed by a CellRenderer, or when the contents is interactive (i.e. has a button in it).

Although a ListBox must have only ListBoxRow children, you can add any kind of widget to it via prepend(), append() and insert() and a 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, signal::ListBox::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 ListBox implementation of the 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

⚠️ The following code is in plain ⚠️

list[.separators][.rich-list][.navigation-sidebar]
╰── row[.activatable]

ListBox uses a single CSS node named list. It may carry the .separators style class, when the property::ListBox::show-separators property is set. Each ListBoxRow uses a single CSS node named row. The row nodes get the .activatable style class added when appropriate.

The main list node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.

Accessibility

ListBox uses the AccessibleRole::List role and ListBoxRow uses the AccessibleRole::ListItem role.

Implements

WidgetExt, glib::ObjectExt, AccessibleExt, BuildableExt, ConstraintTargetExt, WidgetExtManual, AccessibleExtManual

Implementations

Creates a new ListBox container.

Returns

a new ListBox

Creates a new builder-pattern struct instance to construct ListBox objects.

This method returns an instance of ListBoxBuilder which can be used to create ListBox objects.

Append a widget to the list.

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

child

the Widget to add

Binds model to self.

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

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

It is undefined to add or remove widgets directly (for example, with insert()) while self is bound to a model.

Note that using a model is incompatible with the filtering and sorting functionality in ListBox. When using a model, filtering and sorting should be implemented by the model.

model

the GListModel to be bound to self

create_widget_func

a function that creates widgets for items or None in case you also passed None as model

Add a drag highlight to a row.

This is a helper function for implementing DnD onto a ListBox. The passed in row will be highlighted by setting the StateFlags::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.

row

a ListBoxRow

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

Returns whether rows activate on single clicks.

Returns

true if rows are activated on single click, false otherwise

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

Returns

the adjustment

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, None is returned.

index_

the index of the row

Returns

the child Widget

Gets the row at the y position.

y

position

Returns

the row

Gets the selected row, or None 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.

Returns

the selected row

Creates a list of all selected children.

Returns

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

Gets the selection mode of the listbox.

Returns

a SelectionMode

Returns whether the list box should show separators between rows.

Returns

true if the list box shows separators

Insert the child into the self 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 self, then the child will be appended to the end.

child

the Widget to add

position

the position to insert child in

Update the filtering for all rows.

Call this when result of the filter function on the self 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.

Update the separators for all rows.

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

Update the sorting for all rows.

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

Prepend a widget to the list.

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

child

the Widget to add

Removes a child from self.

child

the child to remove

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

Make row the currently selected row.

row

The row to select

Calls a function for each selected child.

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

func

the function to call for each selected child

If single is true, rows will be activated when you click on them, otherwise you need to double-click.

single

a boolean

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 self is packed inside a ScrolledWindow the adjustment from that will be picked up automatically, so there is no need to manually do that.

adjustment

the adjustment

By setting a filter function on the self 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 ListBoxRowExt::changed()) or when invalidate_filter() is called.

Note that using a filter function is incompatible with using a model (see bind_model()).

filter_func

callback that lets you filter which rows to show

Sets a header function.

By setting a header function on the self 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 ListBoxRowExt::header() and either update the state of the widget as needed, or set a new one using ListBoxRowExt::set_header(). If no header is needed, set the header to None.

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 ListBoxRowExt::changed()) and when the row before changes (either by ListBoxRowExt::changed() 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.

update_header

callback that lets you add row headers

Sets the placeholder widget that is shown in the list when it doesn’t display any visible children.

placeholder

a Widget

Sets how selection works in the listbox.

mode

The SelectionMode

Sets whether the list box should show separators between rows.

show_separators

true to show separators

Sets a sort function.

By setting a sort function on the self 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 ListBoxRowExt::changed()) and when invalidate_sort() is called.

Note that using a sort function is incompatible with using a model (see bind_model()).

sort_func

the sort function

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

Unselects a single row of self, if the selection mode allows it.

row

the row to unselected

Whether to accept unpaired release events.

Whether to accept unpaired release events.

Emitted when a row has been activated by the user.

row

the activated row

Emitted when a new row is selected, or (with a None row) when the selection is cleared.

When the box_ is using SelectionMode::Multiple, this signal will not give you the full picture of selection changes, and you should use the signal::ListBox::selected-rows-changed signal instead.

row

the selected row

Emitted to select all children of the box, if the selection mode permits it.

This is a keybinding signal.

The default binding for this signal is <kbd>Ctrl</kbd>-<kbd>a</kbd>.

Emitted when the set of selected rows changes.

Emitted to unselect all children of the box, if the selection mode permits it.

This is a keybinding signal.

The default binding for this signal is <kbd>Ctrl</kbd>-<kbd>Shift</kbd>-<kbd>a</kbd>.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns the type identifier of Self.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Upcasts an object to a superclass or interface T. Read more

Upcasts an object to a reference of its superclass or interface T. Read more

Tries to downcast to a subclass or interface implementor T. Read more

Tries to downcast to a reference of its subclass or interface implementor T. Read more

Tries to cast to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Tries to cast to reference to an object of type T. This handles upcasting, downcasting and casting between interface and interface implementors. All checks are performed at runtime, while downcast and upcast will do many checks at compile-time already. Read more

Casts to T unconditionally. Read more

Casts to &T unconditionally. Read more

Performs the conversion.

Performs the conversion.

Returns true if the object is an instance of (can be cast to) T.

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Safety Read more

Same as connect but takes a SignalId instead of a signal name.

Same as connect_local but takes a SignalId instead of a signal name.

Same as connect_unsafe but takes a SignalId instead of a signal name.

Emit signal by signal id.

Same as emit but takes Value for the arguments.

Emit signal by its name.

Same as emit_by_name but takes Value for the arguments.

Emit signal with details by signal id.

Same as emit_with_details but takes Value for the arguments.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Returns a SendValue clone of self.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.