Class: Gtk::ListBox

Inherits:
Widget
  • Object
show all
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

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_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=, #children, #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, #error_bell, #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, #request_mode, #root, #root=, #scale_factor, #scale_factor=, #sensitive, #sensitive=, #sensitive?, #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, #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

#initializeGtk::Widget

Creates a new GtkListBox container.

Instance Method Details

#accept_unpaired_release=(accept_unpaired_release) ⇒ Boolean

Whether to accept unpaired release events.

Parameters:

  • accept_unpaired_release (Boolean)

Returns:

  • (Boolean)

    accept-unpaired-release

  • (Boolean)

    accept-unpaired-release

#accept_unpaired_release?Boolean

Whether to accept unpaired release events.

Returns:

  • (Boolean)

    accept-unpaired-release

#activate_on_single_clickBoolean

Returns whether rows activate on single clicks.

Returns:

  • (Boolean)

    true if rows are activated on single click, false otherwise

#activate_on_single_click=(activate_on_single_click) ⇒ Boolean

Determines whether children can be activated with a single click, or require a double-click.

Parameters:

  • activate_on_single_click (Boolean)

Returns:

  • (Boolean)

    activate-on-single-click

  • (Boolean)

    activate-on-single-click

#activate_on_single_click?Boolean

Determines whether children can be activated with a single click, or require a double-click.

Returns:

  • (Boolean)

    activate-on-single-click

#adjustmentGtk::Adjustment

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

Returns:

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

Parameters:

Returns:

  • (nil)

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

Parameters:

Returns:

  • (nil)

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

Parameters:

  • model (Gio::ListModel)

    the GListModel to be bound to box

  • create_widget_func (Gtk::ListBoxCreateWidgetFunc)

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

  • user_data (GObject)

    user data passed to create_widget_func

  • user_data_free_func (GLib::DestroyNotify)

    function for freeing user_data

Returns:

  • (nil)

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

Parameters:

Returns:

  • (nil)

#drag_unhighlight_rownil

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

Returns:

  • (nil)

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

Parameters:

  • index_ (Integer)

    the index of the row

Returns:

#get_row_at_y(y) ⇒ Gtk::ListBoxRow

Gets the row at the y position.

Parameters:

  • y (Integer)

    position

Returns:

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

Parameters:

  • child (Gtk::Widget)

    the GtkWidget to add

  • position (Integer)

    the position to insert child in

Returns:

  • (nil)

#invalidate_filternil

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.

Returns:

  • (nil)

#invalidate_headersnil

Update the separators for all rows.

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

Returns:

  • (nil)

#invalidate_sortnil

Update the sorting for all rows.

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

Returns:

  • (nil)

#placeholder=(placeholder) ⇒ nil

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

Parameters:

Returns:

  • (nil)

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

Parameters:

Returns:

  • (nil)

#remove(child) ⇒ nil

Removes a child from box.

Parameters:

Returns:

  • (nil)

#remove_allnil

Removes all rows from box.

This function does nothing if box is backed by a model.

Returns:

  • (nil)

#select_allnil

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

Returns:

  • (nil)

#select_row(row) ⇒ nil

Make row the currently selected row.

Parameters:

Returns:

  • (nil)

#selected_foreach(func, data) ⇒ nil

Calls a function for each selected child.

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

Parameters:

  • func (Gtk::ListBoxForeachFunc)

    the function to call for each selected child

  • data (GObject)

    user data to pass to the function

Returns:

  • (nil)

#selected_rowGtk::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.

Returns:

#selected_rowsGLib::List<Gtk::ListBoxRow>

Creates a list of all selected children.

Returns:

  • (GLib::List<Gtk::ListBoxRow>)

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

#selection_modeGtk::SelectionMode

The selection mode used by the list box.

Returns:

#selection_mode=(selection_mode) ⇒ Gtk::SelectionMode

The selection mode used by the list box.

Parameters:

Returns:

#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]).

Parameters:

  • filter_func (Gtk::ListBoxFilterFunc)

    callback that lets you filter which rows to show

  • user_data (GObject)

    user data passed to filter_func

  • destroy (GLib::DestroyNotify)

    destroy notifier for user_data

Returns:

  • (nil)

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

Parameters:

  • update_header (Gtk::ListBoxUpdateHeaderFunc)

    callback that lets you add row headers

  • user_data (GObject)

    user data passed to update_header

  • destroy (GLib::DestroyNotify)

    destroy notifier for user_data

Returns:

  • (nil)

#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]).

Parameters:

  • sort_func (Gtk::ListBoxSortFunc)

    the sort function

  • user_data (GObject)

    user data passed to sort_func

  • destroy (GLib::DestroyNotify)

    destroy notifier for user_data

Returns:

  • (nil)

#show_separatorsBoolean

Returns whether the list box should show separators between rows.

Returns:

  • (Boolean)

    true if the list box shows separators

#show_separators=(show_separators) ⇒ Boolean

Whether to show separators between rows.

Parameters:

  • show_separators (Boolean)

Returns:

  • (Boolean)

    show-separators

  • (Boolean)

    show-separators

#show_separators?Boolean

Whether to show separators between rows.

Returns:

  • (Boolean)

    show-separators

#unselect_allnil

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

Returns:

  • (nil)

#unselect_row(row) ⇒ nil

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

Parameters:

Returns:

  • (nil)