Class: Gtk::ListBox
- Defined in:
- (unknown)
Overview
GtkListBox is a vertical list.
A GtkListBox only contains GtkListBoxRow 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 GtkListBox is often an alternative to GtkTreeView, especially
when the list contents has a more complicated layout than what is allowed
by a GtkCellRenderer, or when the contents is interactive (i.e. has a
button in it).
Although a GtkListBox must have only GtkListBoxRow children, you can
add any kind of widget to it via [methodGtk.ListBox.prepend],
[methodGtk.ListBox.append] and [methodGtk.ListBox.insert] and a
GtkListBoxRow widget will automatically be inserted between the list
and the widget.
GtkListBoxRows can be marked as activatable or selectable. If a row is
activatable, [signalGtk.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 GtkListBox implementation of the GtkBuildable interface supports
setting a child as the placeholder by specifying “placeholder” as the “type”
attribute of a <child> element. See [methodGtk.ListBox.set_placeholder]
for info.
CSS nodes
list[.separators][.rich-list][.navigation-sidebar][.boxed-list]
╰── row[.activatable]
GtkListBox uses a single CSS node named list. It may carry the .separators
style class, when the [propertyGtk.ListBox:show-separators] property is set.
Each GtkListBoxRow 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: .rich-list, .navigation-sidebar or .data-table.
Accessibility
GtkListBox uses the %GTK_ACCESSIBLE_ROLE_LIST role and GtkListBoxRow uses
the %GTK_ACCESSIBLE_ROLE_LIST_ITEM role.
Instance Method Summary collapse
-
#accept_unpaired_release=(accept_unpaired_release) ⇒ Boolean
Whether to accept unpaired release events.
-
#accept_unpaired_release? ⇒ Boolean
Whether to accept unpaired release events.
-
#activate_on_single_click ⇒ Boolean
Returns whether rows activate on single clicks.
-
#activate_on_single_click=(activate_on_single_click) ⇒ Boolean
Determines whether children can be activated with a single click, or require a double-click.
-
#activate_on_single_click? ⇒ Boolean
Determines whether children can be activated with a single click, or require a double-click.
-
#adjustment ⇒ Gtk::Adjustment
Gets the adjustment (if any) that the widget uses to for vertical scrolling.
-
#adjustment=(adjustment) ⇒ nil
Sets the adjustment (if any) that the widget uses to for vertical scrolling.
-
#append(child) ⇒ nil
Append a widget to the list.
-
#bind_model(model, create_widget_func, user_data, user_data_free_func) ⇒ nil
Binds model to box.
-
#drag_highlight_row(row) ⇒ nil
Add a drag highlight to a row.
-
#drag_unhighlight_row ⇒ nil
If a row has previously been highlighted via gtk_list_box_drag_highlight_row(), it will have the highlight removed.
-
#get_row_at_index(index_) ⇒ Gtk::ListBoxRow
Gets the n-th child in the list (not counting headers).
-
#get_row_at_y(y) ⇒ Gtk::ListBoxRow
Gets the row at the y position.
-
#initialize ⇒ Gtk::Widget
constructor
Creates a new
GtkListBoxcontainer. -
#insert(child, position) ⇒ nil
Insert the child into the box at position.
-
#invalidate_filter ⇒ nil
Update the filtering for all rows.
-
#invalidate_headers ⇒ nil
Update the separators for all rows.
-
#invalidate_sort ⇒ nil
Update the sorting for all rows.
-
#placeholder=(placeholder) ⇒ nil
Sets the placeholder widget that is shown in the list when it doesn't display any visible children.
-
#prepend(child) ⇒ nil
Prepend a widget to the list.
-
#remove(child) ⇒ nil
Removes a child from box.
-
#remove_all ⇒ nil
Removes all rows from box.
-
#select_all ⇒ nil
Select all children of box, if the selection mode allows it.
-
#select_row(row) ⇒ nil
Make row the currently selected row.
-
#selected_foreach(func, data) ⇒ nil
Calls a function for each selected child.
-
#selected_row ⇒ Gtk::ListBoxRow
Gets the selected row, or nil if no rows are selected.
-
#selected_rows ⇒ GLib::List<Gtk::ListBoxRow>
Creates a list of all selected children.
-
#selection_mode ⇒ Gtk::SelectionMode
The selection mode used by the list box.
-
#selection_mode=(selection_mode) ⇒ Gtk::SelectionMode
The selection mode used by the list box.
-
#set_filter_func(filter_func, user_data, destroy) ⇒ nil
By setting a filter function on the box one can decide dynamically which of the rows to show.
-
#set_header_func(update_header, user_data, destroy) ⇒ nil
Sets a header function.
-
#set_sort_func(sort_func, user_data, destroy) ⇒ nil
Sets a sort function.
-
#show_separators ⇒ Boolean
Returns whether the list box should show separators between rows.
-
#show_separators=(show_separators) ⇒ Boolean
Whether to show separators between rows.
-
#show_separators? ⇒ Boolean
Whether to show separators between rows.
-
#unselect_all ⇒ nil
Unselect all children of box, if the selection mode allows it.
-
#unselect_row(row) ⇒ nil
Unselects a single row of box, if the selection mode allows it.
Methods inherited from Widget
#accessible_role, #accessible_role=, #action_set_enabled, #activate, #activate_action, #activate_action_variant, #activate_default, #activate_signal, #activate_signal=, #activate_signal_from_name=, #add_binding, #add_binding_action, #add_binding_signal, #add_controller, #add_css_class, #add_events, #add_events_raw, #add_mnemonic_label, #add_shortcut, #add_tick_callback, #allocate, #allocated_baseline, #allocated_height, #allocated_width, #baseline, #bind_template_callback_full, #bind_template_child, #bind_template_child_full, #can_focus, #can_focus=, #can_focus?, #can_target, #can_target=, #can_target?, #child_focus, #child_visible, #child_visible=, #clipboard, #compute_bounds, #compute_expand, #compute_point, #compute_transform, #contains, #create_pango_context, #create_pango_layout, #css_classes, #css_classes=, #css_name, #css_name=, #cursor, #cursor=, #cursor_from_name=, default_direction, default_direction=, #direction, #direction=, #display, #dispose_template, #drag_check_threshold, #drag_dest_set, #drag_dest_set_raw, #drag_source_set, #drag_source_set_raw, #error_bell, #events, #events_raw, #first_child, #focus_child, #focus_child=, #focus_on_click, #focus_on_click=, #focus_on_click?, #focusable, #focusable=, #focusable?, #font_map, #font_map=, #font_options, #font_options=, #frame_clock, #get_allocation, #get_ancestor, #get_color, #get_preferred_size, #get_size, #get_size_request, #get_template_child, #grab_focus, #halign, #halign=, #has_css_class, #has_default, #has_default=, #has_default?, #has_focus, #has_focus=, #has_focus?, #has_tooltip, #has_tooltip=, #has_tooltip?, #has_visible_focus, have_template?, #height, #height_request, #height_request=, #hexpand, #hexpand=, #hexpand?, #hexpand_set, #hexpand_set=, #hexpand_set?, #hide, #in_destruction, #init_template, #insert_action_group, #insert_action_group_raw, #insert_after, #insert_before, #install_action, #install_property_action, #is_ancestor, #is_drawable, #is_focus, #is_sensitive, #is_visible, #keynav_failed, #last_child, #layout_manager, #layout_manager=, #layout_manager_type, #layout_manager_type=, #list_mnemonic_labels, #map, #mapped, #margin_bottom, #margin_bottom=, #margin_end, #margin_end=, #margin_start, #margin_start=, #margin_top, #margin_top=, #measure, #mnemonic_activate, #name, #name=, #native, #next_sibling, #observe_children, #observe_controllers, #opacity, #opacity=, #overflow, #overflow=, #pango_context, #parent, #parent=, #pick, #prev_sibling, #primary_clipboard, #query_action, #queue_allocate, #queue_draw, #queue_resize, #realize, #realized, #receives_default, #receives_default=, #receives_default?, #remove_controller, #remove_css_class, #remove_mnemonic_label, #remove_tick_callback, #render_icon_pixbuf, #render_icon_pixbuf_raw, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #set_allocation, set_connect_func, set_connect_func_raw, #set_events, #set_events_raw, #set_size_request, #set_size_request_raw, #set_state_flags, #set_template, #set_template_raw, #settings, #should_layout, #show, #size_allocate, #snapshot_child, #state_flags, #style_context, #style_context_raw, #style_get_property, #style_get_property_raw, #template=, template_children, #template_from_resource=, #template_scope=, #tooltip_markup, #tooltip_markup=, #tooltip_text, #tooltip_text=, #translate_coordinates, #translate_coordinates_raw, #trigger_tooltip_query, #unmap, #unparent, #unrealize, #unset_state_flags, #valign, #valign=, #vexpand, #vexpand=, #vexpand?, #vexpand_set, #vexpand_set=, #vexpand_set?, #visible, #visible=, #visible?, #width, #width_request, #width_request=
Constructor Details
#initialize ⇒ Gtk::Widget
Creates a new GtkListBox container.
Instance Method Details
#accept_unpaired_release=(accept_unpaired_release) ⇒ Boolean
Whether to accept unpaired release events.
#accept_unpaired_release? ⇒ Boolean
Whether to accept unpaired release events.
#activate_on_single_click ⇒ Boolean
Returns whether rows activate on single clicks.
#activate_on_single_click=(activate_on_single_click) ⇒ Boolean
Determines whether children can be activated with a single click, or require a double-click.
#activate_on_single_click? ⇒ Boolean
Determines whether children can be activated with a single click, or require a double-click.
#adjustment ⇒ Gtk::Adjustment
Gets the adjustment (if any) that the widget uses to for vertical scrolling.
#adjustment=(adjustment) ⇒ nil
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 GtkScrolledWindow the adjustment from that will
be picked up automatically, so there is no need
to manually do that.
#append(child) ⇒ nil
Append a widget to the list.
If a sort function is set, the widget will actually be inserted at the calculated position.
#bind_model(model, create_widget_func, user_data, user_data_free_func) ⇒ nil
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 nil, box is left empty.
It is undefined to add or remove widgets directly (for example, with [methodGtk.ListBox.insert]) while box is bound to a model.
Note that using a model is incompatible with the filtering and sorting
functionality in GtkListBox. When using a model, filtering and sorting
should be implemented by the model.
#drag_highlight_row(row) ⇒ nil
Add a drag highlight to a row.
This is a helper function for implementing DnD onto a GtkListBox.
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.
#drag_unhighlight_row ⇒ nil
If a row has previously been highlighted via gtk_list_box_drag_highlight_row(), it will have the highlight removed.
#get_row_at_index(index_) ⇒ Gtk::ListBoxRow
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, nil is returned.
#get_row_at_y(y) ⇒ Gtk::ListBoxRow
Gets the row at the y position.
#insert(child, position) ⇒ nil
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.
#invalidate_filter ⇒ nil
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.
#invalidate_headers ⇒ nil
Update the separators for all rows.
Call this when result of the header function on the box is changed due to an external factor.
#invalidate_sort ⇒ nil
Update the sorting for all rows.
Call this when result of the sort function on the box is changed due to an external factor.
#placeholder=(placeholder) ⇒ nil
Sets the placeholder widget that is shown in the list when it doesn't display any visible children.
#prepend(child) ⇒ nil
Prepend a widget to the list.
If a sort function is set, the widget will actually be inserted at the calculated position.
#remove(child) ⇒ nil
Removes a child from box.
#remove_all ⇒ nil
Removes all rows from box.
This function does nothing if box is backed by a model.
#select_all ⇒ nil
Select all children of box, if the selection mode allows it.
#select_row(row) ⇒ nil
Make row the currently selected row.
#selected_foreach(func, data) ⇒ nil
Calls a function for each selected child.
Note that the selection cannot be modified from within this function.
#selected_row ⇒ Gtk::ListBoxRow
Gets the selected row, or nil if no rows are selected.
Note that the box may allow multiple selection, in which case you should use [methodGtk.ListBox.selected_foreach] to find all selected rows.
#selected_rows ⇒ GLib::List<Gtk::ListBoxRow>
Creates a list of all selected children.
#selection_mode ⇒ Gtk::SelectionMode
The selection mode used by the list box.
#selection_mode=(selection_mode) ⇒ Gtk::SelectionMode
The selection mode used by the list box.
#set_filter_func(filter_func, user_data, destroy) ⇒ nil
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 [methodGtk.ListBoxRow.changed]) or when [methodGtk.ListBox.invalidate_filter] is called.
Note that using a filter function is incompatible with using a model (see [methodGtk.ListBox.bind_model]).
#set_header_func(update_header, user_data, destroy) ⇒ nil
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 [methodGtk.ListBoxRow.get_header] and either update the state of the widget as needed, or set a new one using [methodGtk.ListBoxRow.set_header]. If no header is needed, set the header to nil.
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 [methodGtk.ListBoxRow.changed]) and when the row before changes (either by [methodGtk.ListBoxRow.changed] on the previous row, or when the previous row becomes a different row). It is also called for all rows when [methodGtk.ListBox.invalidate_headers] is called.
#set_sort_func(sort_func, user_data, destroy) ⇒ nil
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 [methodGtk.ListBoxRow.changed]) and when [methodGtk.ListBox.invalidate_sort] is called.
Note that using a sort function is incompatible with using a model (see [methodGtk.ListBox.bind_model]).
#show_separators ⇒ Boolean
Returns whether the list box should show separators between rows.
#show_separators=(show_separators) ⇒ Boolean
Whether to show separators between rows.
#show_separators? ⇒ Boolean
Whether to show separators between rows.
#unselect_all ⇒ nil
Unselect all children of box, if the selection mode allows it.
#unselect_row(row) ⇒ nil
Unselects a single row of box, if the selection mode allows it.