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 builder-pattern struct instance to construct ListBox
objects.
This method returns an instance of ListBoxBuilder
which can be used to create ListBox
objects.
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
If a row has previously been highlighted via drag_highlight_row()
,
it will have the highlight removed.
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
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.
Select all children of self
, if the selection mode allows it.
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
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
pub fn set_header_func<P: Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>(
&self,
update_header: P
)
pub fn set_header_func<P: Fn(&ListBoxRow, Option<&ListBoxRow>) + 'static>(
&self,
update_header: P
)
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 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.
Whether to accept unpaired release events.
Whether to accept unpaired release events.
pub fn connect_move_cursor<F: Fn(&Self, MovementStep, i32, bool, bool) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_row_activated<F: Fn(&Self, &ListBoxRow) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_row_activated<F: Fn(&Self, &ListBoxRow) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_row_selected<F: Fn(&Self, Option<&ListBoxRow>) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_row_selected<F: Fn(&Self, Option<&ListBoxRow>) + 'static>(
&self,
f: F
) -> SignalHandlerId
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>
.
pub fn connect_accept_unpaired_release_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
pub fn connect_activate_on_single_click_notify<F: Fn(&Self) + 'static>(
&self,
f: F
) -> SignalHandlerId
Trait Implementations
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
Returns the type identifier of Self
.
Auto Trait Implementations
impl RefUnwindSafe for ListBox
impl UnwindSafe for ListBox
Blanket Implementations
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
Returns true
if the object is an instance of (can be cast to) T
.
pub fn set_property<'a, N, V>(
&self,
property_name: N,
value: V
) -> Result<(), BoolError> where
N: Into<&'a str>,
V: ToValue,
pub fn set_property_from_value<'a, N>(
&self,
property_name: N,
value: &Value
) -> Result<(), BoolError> where
N: Into<&'a str>,
pub fn set_properties_from_value(
&self,
property_values: &[(&str, Value)]
) -> Result<(), BoolError>
pub fn has_property<'a, N>(&self, property_name: N, type_: Option<Type>) -> bool where
N: Into<&'a str>,
pub fn find_property<'a, N>(&self, property_name: N) -> Option<ParamSpec> where
N: Into<&'a str>,
Safety Read more
Safety Read more
Safety Read more
Safety Read more
pub fn connect<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value> + Send + Sync,
Same as connect
but takes a SignalId
instead of a signal name.
pub fn connect_local<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: 'static + Fn(&[Value]) -> Option<Value>,
Same as connect_local
but takes a SignalId
instead of a signal name.
pub unsafe fn connect_unsafe<'a, N, F>(
&self,
signal_name: N,
after: bool,
callback: F
) -> Result<SignalHandlerId, BoolError> where
N: Into<&'a str>,
F: Fn(&[Value]) -> Option<Value>,
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.
pub fn connect_notify<F>(&self, name: Option<&str>, f: F) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec) + Send + Sync,
pub fn connect_notify_local<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: 'static + Fn(&T, &ParamSpec),
pub unsafe fn connect_notify_unsafe<F>(
&self,
name: Option<&str>,
f: F
) -> SignalHandlerId where
F: Fn(&T, &ParamSpec),
pub fn bind_property<'a, O, N, M>(
&'a self,
source_property: N,
target: &'a O,
target_property: M
) -> BindingBuilder<'a> where
O: ObjectType,
N: Into<&'a str>,
M: Into<&'a str>,
Returns a SendValue
clone of self
.