module Gtk::SelectionModel

Overview

Gtk::SelectionModel is an interface that add support for selection to list models.

This support is then used by widgets using list models to add the ability to select and unselect various items.

GTK provides default implementations of the most common selection modes such as Gtk::SingleSelection, so you will only need to implement this interface if you want detailed control about how selections should be handled.

A Gtk::SelectionModel supports a single boolean per item indicating if an item is selected or not. This can be queried via Gtk::SelectionModel#is_selected?. When the selected state of one or more items changes, the model will emit the [signal@Gtk.SelectionModel::selection-changed] signal by calling the Gtk::SelectionModel#selection_changed function. The positions given in that signal may have their selection state changed, though that is not a requirement. If new items added to the model via the [signal@Gio.ListModel::items-changed] signal are selected or not is up to the implementation.

Note that items added via [signal@Gio.ListModel::items-changed] may already be selected and no [signal@Gtk.SelectionModel::selection-changed] will be emitted for them. So to track which items are selected, it is necessary to listen to both signals.

Additionally, the interface can expose functionality to select and unselect items. If these functions are implemented, GTK's list widgets will allow users to select and unselect items. However, Gtk::SelectionModels are free to only implement them partially or not at all. In that case the widgets will not support the unimplemented operations.

When selecting or unselecting is supported by a model, the return values of the selection functions do not indicate if selection or unselection happened. They are only meant to indicate complete failure, like when this mode of selecting is not supported by the model.

Selections may happen asynchronously, so the only reliable way to find out when an item was selected is to listen to the signals that indicate selection.

Direct including types

Defined in:

lib/gi-crystal/src/auto/gtk-4.0/selection_model.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.cast(obj : GObject::Object) : self #

Cast a GObject::Object to self, throws a TypeCastError if the cast can't be made.


[View source]

Class Method Detail

def self.cast?(obj : GObject::Object) : self | Nil #

[View source]
def self.g_type : UInt64 #

[View source]

Instance Method Detail

def is_selected(position : UInt32) : Bool #

[View source]
def select_all : Bool #

[View source]
def select_item(position : UInt32, unselect_rest : Bool) : Bool #

[View source]
def select_range(position : UInt32, n_items : UInt32, unselect_rest : Bool) : Bool #

[View source]
def selection : Gtk::Bitset #

[View source]
def selection_changed(position : UInt32, n_items : UInt32) : Nil #

[View source]
def selection_changed_signal #

[View source]
def selection_in_range(position : UInt32, n_items : UInt32) : Gtk::Bitset #

[View source]
def set_selection(selected : Gtk::Bitset, mask : Gtk::Bitset) : Bool #

[View source]
abstract def to_unsafe #

[View source]
def unselect_all : Bool #

[View source]
def unselect_item(position : UInt32) : Bool #

[View source]
def unselect_range(position : UInt32, n_items : UInt32) : Bool #

[View source]