gtk4/auto/multi_sorter.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, Buildable, Sorter};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// [`MultiSorter`][crate::MultiSorter] combines multiple sorters by trying them
10 /// in turn.
11 ///
12 /// If the first sorter compares two items as equal,
13 /// the second is tried next, and so on.
14 ///
15 /// ## Properties
16 ///
17 ///
18 /// #### `item-type`
19 /// The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
20 ///
21 /// Readable
22 ///
23 ///
24 /// #### `n-items`
25 /// The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
26 ///
27 /// Readable
28 ///
29 /// # Implements
30 ///
31 /// [`SorterExt`][trait@crate::prelude::SorterExt], [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
32 #[doc(alias = "GtkMultiSorter")]
33 pub struct MultiSorter(Object<ffi::GtkMultiSorter, ffi::GtkMultiSorterClass>) @extends Sorter, @implements gio::ListModel, Buildable;
34
35 match fn {
36 type_ => || ffi::gtk_multi_sorter_get_type(),
37 }
38}
39
40impl MultiSorter {
41 /// Creates a new multi sorter.
42 ///
43 /// This sorter compares items by trying each of the sorters
44 /// in turn, until one returns non-zero. In particular, if
45 /// no sorter has been added to it, it will always compare
46 /// items as equal.
47 ///
48 /// # Returns
49 ///
50 /// a new [`MultiSorter`][crate::MultiSorter]
51 #[doc(alias = "gtk_multi_sorter_new")]
52 pub fn new() -> MultiSorter {
53 assert_initialized_main_thread!();
54 unsafe { from_glib_full(ffi::gtk_multi_sorter_new()) }
55 }
56
57 /// Add @sorter to @self to use for sorting at the end.
58 ///
59 /// @self will consult all existing sorters before it will
60 /// sort with the given @sorter.
61 /// ## `sorter`
62 /// a sorter to add
63 #[doc(alias = "gtk_multi_sorter_append")]
64 pub fn append(&self, sorter: impl IsA<Sorter>) {
65 unsafe {
66 ffi::gtk_multi_sorter_append(self.to_glib_none().0, sorter.upcast().into_glib_ptr());
67 }
68 }
69
70 /// Removes the sorter at the given @position from the list of sorter
71 /// used by @self.
72 ///
73 /// If @position is larger than the number of sorters, nothing happens.
74 /// ## `position`
75 /// position of sorter to remove
76 #[doc(alias = "gtk_multi_sorter_remove")]
77 pub fn remove(&self, position: u32) {
78 unsafe {
79 ffi::gtk_multi_sorter_remove(self.to_glib_none().0, position);
80 }
81 }
82}
83
84impl Default for MultiSorter {
85 fn default() -> Self {
86 Self::new()
87 }
88}