Trait gtk4::prelude::SelectionModelExt
source · pub trait SelectionModelExt: 'static {
// Required methods
fn selection(&self) -> Bitset;
fn selection_in_range(&self, position: u32, n_items: u32) -> Bitset;
fn is_selected(&self, position: u32) -> bool;
fn select_all(&self) -> bool;
fn select_item(&self, position: u32, unselect_rest: bool) -> bool;
fn select_range(
&self,
position: u32,
n_items: u32,
unselect_rest: bool
) -> bool;
fn selection_changed(&self, position: u32, n_items: u32);
fn set_selection(&self, selected: &Bitset, mask: &Bitset) -> bool;
fn unselect_all(&self) -> bool;
fn unselect_item(&self, position: u32) -> bool;
fn unselect_range(&self, position: u32, n_items: u32) -> bool;
fn connect_selection_changed<F: Fn(&Self, u32, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId;
}
Expand description
Trait containing all SelectionModel
methods.
Implementors
MultiSelection
, NoSelection
, SelectionModel
, SingleSelection
Required Methods§
sourcefn selection(&self) -> Bitset
fn selection(&self) -> Bitset
Gets the set containing all currently selected items in the model.
This function may be slow, so if you are only interested in single item,
consider using is_selected()
or if you are only
interested in a few, consider selection_in_range()
.
Returns
a Bitset
containing all the values currently
selected in @self. If no items are selected, the bitset is empty.
The bitset must not be modified.
sourcefn selection_in_range(&self, position: u32, n_items: u32) -> Bitset
fn selection_in_range(&self, position: u32, n_items: u32) -> Bitset
Gets the set of selected items in a range.
This function is an optimization for
selection()
when you are only
interested in part of the model’s selected state. A common use
case is in response to the signal::SelectionModel::selection-changed
signal.
position
start of the queired range
n_items
number of items in the queried range
Returns
A Bitset
that matches the selection state
for the given range with all other values being undefined.
The bitset must not be modified.
sourcefn is_selected(&self, position: u32) -> bool
fn is_selected(&self, position: u32) -> bool
sourcefn select_all(&self) -> bool
fn select_all(&self) -> bool
sourcefn select_item(&self, position: u32, unselect_rest: bool) -> bool
fn select_item(&self, position: u32, unselect_rest: bool) -> bool
Requests to select an item in the model.
position
the position of the item to select
unselect_rest
whether previously selected items should be unselected
Returns
true
if this action was supported and no fallback should be
tried. This does not mean the item was selected.
sourcefn select_range(&self, position: u32, n_items: u32, unselect_rest: bool) -> bool
fn select_range(&self, position: u32, n_items: u32, unselect_rest: bool) -> bool
Requests to select a range of items in the model.
position
the first item to select
n_items
the number of items to select
unselect_rest
whether previously selected items should be unselected
Returns
true
if this action was supported and no fallback should be
tried. This does not mean the range was selected.
sourcefn selection_changed(&self, position: u32, n_items: u32)
fn selection_changed(&self, position: u32, n_items: u32)
Helper function for implementations of SelectionModel
.
Call this when a the selection changes to emit the
signal::SelectionModel::selection-changed
signal.
position
the first changed item
n_items
the number of changed items
sourcefn set_selection(&self, selected: &Bitset, mask: &Bitset) -> bool
fn set_selection(&self, selected: &Bitset, mask: &Bitset) -> bool
Make selection changes.
This is the most advanced selection updating method that allows the most fine-grained control over selection changes. If you can, you should try the simpler versions, as implementations are more likely to implement support for those.
Requests that the selection state of all positions set in @mask be updated to the respective value in the @selected bitmask.
In pseudocode, it would look something like this:
⚠️ The following code is in c ⚠️
for (i = 0; i < n_items; i++)
{
// don't change values not in the mask
if (!gtk_bitset_contains (mask, i))
continue;
if (gtk_bitset_contains (selected, i))
select_item (i);
else
unselect_item (i);
}
gtk_selection_model_selection_changed (model,
first_changed_item,
n_changed_items);
@mask and @selected must not be modified. They may refer to the same bitset, which would mean that every item in the set should be selected.
selected
bitmask specifying if items should be selected or unselected
mask
bitmask specifying which items should be updated
Returns
true
if this action was supported and no fallback should be
tried. This does not mean that all items were updated according
to the inputs.
sourcefn unselect_all(&self) -> bool
fn unselect_all(&self) -> bool
sourcefn unselect_item(&self, position: u32) -> bool
fn unselect_item(&self, position: u32) -> bool
sourcefn unselect_range(&self, position: u32, n_items: u32) -> bool
fn unselect_range(&self, position: u32, n_items: u32) -> bool
sourcefn connect_selection_changed<F: Fn(&Self, u32, u32) + 'static>(
&self,
f: F
) -> SignalHandlerId
fn connect_selection_changed<F: Fn(&Self, u32, u32) + 'static>( &self, f: F ) -> SignalHandlerId
Emitted when the selection state of some of the items in @model changes.
Note that this signal does not specify the new selection state of the items, they need to be queried manually. It is also not necessary for a model to change the selection state of any of the items in the selection model, though it would be rather useless to emit such a signal.
position
The first item that may have changed
n_items
number of items with changes