Skip to main content

gtk4/auto/
string_list.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::{Buildable, ffi};
6use glib::translate::*;
7
8glib::wrapper! {
9    ///
10    /// ```text
11    ///
12    ///
13    /// ## Properties
14    ///
15    ///
16    /// #### `item-type`
17    ///  The type of items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
18    ///
19    /// Readable
20    ///
21    ///
22    /// #### `n-items`
23    ///  The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
24    ///
25    /// Readable
26    ///
27    ///
28    /// #### `strings`
29    ///  The strings in the model.
30    ///
31    /// Writable | Construct Only
32    ///
33    /// # Implements
34    ///
35    /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt]
36    #[doc(alias = "GtkStringList")]
37    pub struct StringList(Object<ffi::GtkStringList, ffi::GtkStringListClass>) @implements gio::ListModel, Buildable;
38
39    match fn {
40        type_ => || ffi::gtk_string_list_get_type(),
41    }
42}
43
44impl StringList {
45    /// Creates a new [`StringList`][crate::StringList] with the given @strings.
46    /// ## `strings`
47    /// The strings to put in the model
48    ///
49    /// # Returns
50    ///
51    /// a new [`StringList`][crate::StringList]
52    #[doc(alias = "gtk_string_list_new")]
53    pub fn new(strings: &[&str]) -> StringList {
54        assert_initialized_main_thread!();
55        unsafe { from_glib_full(ffi::gtk_string_list_new(strings.to_glib_none().0)) }
56    }
57
58    /// Appends @string to @self.
59    ///
60    /// The @string will be copied. See
61    /// `Gtk::StringList::take()` for a way to avoid that.
62    /// ## `string`
63    /// the string to insert
64    #[doc(alias = "gtk_string_list_append")]
65    pub fn append(&self, string: &str) {
66        unsafe {
67            ffi::gtk_string_list_append(self.to_glib_none().0, string.to_glib_none().0);
68        }
69    }
70
71    /// Gets the position of the @string in @self.
72    ///
73    /// If @self does not contain @string item, `G_MAXUINT` is returned.
74    /// ## `string`
75    /// the string to find
76    ///
77    /// # Returns
78    ///
79    /// the position of the string
80    #[cfg(feature = "v4_18")]
81    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
82    #[doc(alias = "gtk_string_list_find")]
83    pub fn find(&self, string: &str) -> u32 {
84        unsafe { ffi::gtk_string_list_find(self.to_glib_none().0, string.to_glib_none().0) }
85    }
86
87    /// Gets the string that is at @position in @self.
88    ///
89    /// If @self does not contain @position items, [`None`] is returned.
90    ///
91    /// This function returns the const char *. To get the
92    /// object wrapping it, use g_list_model_get_item().
93    /// ## `position`
94    /// the position to get the string for
95    ///
96    /// # Returns
97    ///
98    /// the string at the given position
99    #[doc(alias = "gtk_string_list_get_string")]
100    #[doc(alias = "get_string")]
101    pub fn string(&self, position: u32) -> Option<glib::GString> {
102        unsafe {
103            from_glib_none(ffi::gtk_string_list_get_string(
104                self.to_glib_none().0,
105                position,
106            ))
107        }
108    }
109
110    /// Removes the string at @position from @self.
111    ///
112    /// @position must be smaller than the current
113    /// length of the list.
114    /// ## `position`
115    /// the position of the string that is to be removed
116    #[doc(alias = "gtk_string_list_remove")]
117    pub fn remove(&self, position: u32) {
118        unsafe {
119            ffi::gtk_string_list_remove(self.to_glib_none().0, position);
120        }
121    }
122
123    /// Changes @self by removing @n_removals strings and adding @additions
124    /// to it.
125    ///
126    /// This function is more efficient than [`append()`][Self::append()]
127    /// and [`remove()`][Self::remove()], because it only emits the
128    /// ::items-changed signal once for the change.
129    ///
130    /// This function copies the strings in @additions.
131    ///
132    /// The parameters @position and @n_removals must be correct (ie:
133    /// @position + @n_removals must be less than or equal to the length
134    /// of the list at the time this function is called).
135    /// ## `position`
136    /// the position at which to make the change
137    /// ## `n_removals`
138    /// the number of strings to remove
139    /// ## `additions`
140    /// The strings to add
141    #[doc(alias = "gtk_string_list_splice")]
142    pub fn splice(&self, position: u32, n_removals: u32, additions: &[&str]) {
143        unsafe {
144            ffi::gtk_string_list_splice(
145                self.to_glib_none().0,
146                position,
147                n_removals,
148                additions.to_glib_none().0,
149            );
150        }
151    }
152}