gtk/auto/tree_path.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 glib::translate::*;
6use std::{cmp, fmt, mem};
7
8glib::wrapper! {
9 #[derive(Debug, Hash)]
10 pub struct TreePath(Boxed<ffi::GtkTreePath>);
11
12 match fn {
13 copy => |ptr| ffi::gtk_tree_path_copy(ptr),
14 free => |ptr| ffi::gtk_tree_path_free(ptr),
15 type_ => || ffi::gtk_tree_path_get_type(),
16 }
17}
18
19impl TreePath {
20 /// Creates a new [`TreePath`][crate::TreePath]-struct.
21 /// This refers to a row.
22 ///
23 /// # Returns
24 ///
25 /// A newly created [`TreePath`][crate::TreePath]-struct.
26 #[doc(alias = "gtk_tree_path_new")]
27 pub fn new() -> TreePath {
28 assert_initialized_main_thread!();
29 unsafe { from_glib_full(ffi::gtk_tree_path_new()) }
30 }
31
32 /// Creates a new [`TreePath`][crate::TreePath]-struct.
33 ///
34 /// The string representation of this path is “0”.
35 ///
36 /// # Returns
37 ///
38 /// A new [`TreePath`][crate::TreePath]-struct
39 #[doc(alias = "gtk_tree_path_new_first")]
40 pub fn new_first() -> TreePath {
41 assert_initialized_main_thread!();
42 unsafe { from_glib_full(ffi::gtk_tree_path_new_first()) }
43 }
44
45 //#[doc(alias = "gtk_tree_path_new_from_indices")]
46 //#[doc(alias = "new_from_indices")]
47 //pub fn from_indices(first_index: i32, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) -> TreePath {
48 // unsafe { TODO: call ffi:gtk_tree_path_new_from_indices() }
49 //}
50
51 /// Creates a new path with the given `indices` array of `length`.
52 /// ## `indices`
53 /// array of indices
54 ///
55 /// # Returns
56 ///
57 /// A newly created [`TreePath`][crate::TreePath]-struct
58 #[doc(alias = "gtk_tree_path_new_from_indicesv")]
59 #[doc(alias = "new_from_indicesv")]
60 pub fn from_indicesv(indices: &[i32]) -> TreePath {
61 assert_initialized_main_thread!();
62 let length = indices.len() as _;
63 unsafe {
64 from_glib_full(ffi::gtk_tree_path_new_from_indicesv(
65 indices.to_glib_none().0,
66 length,
67 ))
68 }
69 }
70
71 /// Creates a new [`TreePath`][crate::TreePath]-struct initialized to `path`.
72 ///
73 /// `path` is expected to be a colon separated list of numbers.
74 /// For example, the string “10:4:0” would create a path of depth
75 /// 3 pointing to the 11th child of the root node, the 5th
76 /// child of that 11th child, and the 1st child of that 5th child.
77 /// If an invalid path string is passed in, [`None`] is returned.
78 /// ## `path`
79 /// The string representation of a path
80 ///
81 /// # Returns
82 ///
83 /// A newly-created [`TreePath`][crate::TreePath]-struct, or [`None`]
84 #[doc(alias = "gtk_tree_path_new_from_string")]
85 #[doc(alias = "new_from_string")]
86 pub fn from_string(path: &str) -> TreePath {
87 assert_initialized_main_thread!();
88 unsafe { from_glib_full(ffi::gtk_tree_path_new_from_string(path.to_glib_none().0)) }
89 }
90
91 /// Appends a new index to a path.
92 ///
93 /// As a result, the depth of the path is increased.
94 /// ## `index_`
95 /// the index
96 #[doc(alias = "gtk_tree_path_append_index")]
97 pub fn append_index(&mut self, index_: i32) {
98 unsafe {
99 ffi::gtk_tree_path_append_index(self.to_glib_none_mut().0, index_);
100 }
101 }
102
103 #[doc(alias = "gtk_tree_path_compare")]
104 fn compare(&self, b: &TreePath) -> i32 {
105 unsafe { ffi::gtk_tree_path_compare(self.to_glib_none().0, b.to_glib_none().0) }
106 }
107
108 /// Moves `self` to point to the first child of the current path.
109 #[doc(alias = "gtk_tree_path_down")]
110 pub fn down(&mut self) {
111 unsafe {
112 ffi::gtk_tree_path_down(self.to_glib_none_mut().0);
113 }
114 }
115
116 /// Returns the current depth of `self`.
117 ///
118 /// # Returns
119 ///
120 /// The depth of `self`
121 #[doc(alias = "gtk_tree_path_get_depth")]
122 #[doc(alias = "get_depth")]
123 pub fn depth(&self) -> i32 {
124 unsafe { ffi::gtk_tree_path_get_depth(mut_override(self.to_glib_none().0)) }
125 }
126
127 /// Returns the current indices of `self`.
128 ///
129 /// This is an array of integers, each representing a node in a tree.
130 /// It also returns the number of elements in the array.
131 /// The array should not be freed.
132 ///
133 /// # Returns
134 ///
135 /// The current
136 /// indices, or [`None`]
137 #[doc(alias = "gtk_tree_path_get_indices_with_depth")]
138 #[doc(alias = "get_indices_with_depth")]
139 pub fn indices_with_depth(&mut self) -> Vec<i32> {
140 unsafe {
141 let mut depth = mem::MaybeUninit::uninit();
142 let ret = FromGlibContainer::from_glib_none_num(
143 ffi::gtk_tree_path_get_indices_with_depth(
144 self.to_glib_none_mut().0,
145 depth.as_mut_ptr(),
146 ),
147 depth.assume_init() as _,
148 );
149 ret
150 }
151 }
152
153 /// Returns [`true`] if `descendant` is a descendant of `self`.
154 /// ## `descendant`
155 /// another [`TreePath`][crate::TreePath]-struct
156 ///
157 /// # Returns
158 ///
159 /// [`true`] if `descendant` is contained inside `self`
160 #[doc(alias = "gtk_tree_path_is_ancestor")]
161 pub fn is_ancestor(&self, descendant: &TreePath) -> bool {
162 unsafe {
163 from_glib(ffi::gtk_tree_path_is_ancestor(
164 mut_override(self.to_glib_none().0),
165 mut_override(descendant.to_glib_none().0),
166 ))
167 }
168 }
169
170 /// Returns [`true`] if `self` is a descendant of `ancestor`.
171 /// ## `ancestor`
172 /// another [`TreePath`][crate::TreePath]-struct
173 ///
174 /// # Returns
175 ///
176 /// [`true`] if `ancestor` contains `self` somewhere below it
177 #[doc(alias = "gtk_tree_path_is_descendant")]
178 pub fn is_descendant(&self, ancestor: &TreePath) -> bool {
179 unsafe {
180 from_glib(ffi::gtk_tree_path_is_descendant(
181 mut_override(self.to_glib_none().0),
182 mut_override(ancestor.to_glib_none().0),
183 ))
184 }
185 }
186
187 /// Moves the `self` to point to the next node at the current depth.
188 #[doc(alias = "gtk_tree_path_next")]
189 pub fn next(&mut self) {
190 unsafe {
191 ffi::gtk_tree_path_next(self.to_glib_none_mut().0);
192 }
193 }
194
195 /// Prepends a new index to a path.
196 ///
197 /// As a result, the depth of the path is increased.
198 /// ## `index_`
199 /// the index
200 #[doc(alias = "gtk_tree_path_prepend_index")]
201 pub fn prepend_index(&mut self, index_: i32) {
202 unsafe {
203 ffi::gtk_tree_path_prepend_index(self.to_glib_none_mut().0, index_);
204 }
205 }
206
207 /// Moves the `self` to point to the previous node at the
208 /// current depth, if it exists.
209 ///
210 /// # Returns
211 ///
212 /// [`true`] if `self` has a previous node, and
213 /// the move was made
214 #[doc(alias = "gtk_tree_path_prev")]
215 pub fn prev(&mut self) -> bool {
216 unsafe { from_glib(ffi::gtk_tree_path_prev(self.to_glib_none_mut().0)) }
217 }
218
219 /// Generates a string representation of the path.
220 ///
221 /// This string is a “:” separated list of numbers.
222 /// For example, “4:10:0:3” would be an acceptable
223 /// return value for this string.
224 ///
225 /// # Returns
226 ///
227 /// A newly-allocated string.
228 /// Must be freed with `g_free()`.
229 #[doc(alias = "gtk_tree_path_to_string")]
230 #[doc(alias = "to_string")]
231 pub fn to_str(&self) -> glib::GString {
232 unsafe {
233 from_glib_full(ffi::gtk_tree_path_to_string(mut_override(
234 self.to_glib_none().0,
235 )))
236 }
237 }
238
239 /// Moves the `self` to point to its parent node, if it has a parent.
240 ///
241 /// # Returns
242 ///
243 /// [`true`] if `self` has a parent, and the move was made
244 #[doc(alias = "gtk_tree_path_up")]
245 pub fn up(&mut self) -> bool {
246 unsafe { from_glib(ffi::gtk_tree_path_up(self.to_glib_none_mut().0)) }
247 }
248}
249
250impl Default for TreePath {
251 fn default() -> Self {
252 Self::new()
253 }
254}
255
256impl PartialEq for TreePath {
257 #[inline]
258 fn eq(&self, other: &Self) -> bool {
259 self.compare(other) == 0
260 }
261}
262
263impl Eq for TreePath {}
264
265impl PartialOrd for TreePath {
266 #[inline]
267 fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
268 self.compare(other).partial_cmp(&0)
269 }
270}
271
272impl Ord for TreePath {
273 #[inline]
274 fn cmp(&self, other: &Self) -> cmp::Ordering {
275 self.compare(other).cmp(&0)
276 }
277}
278
279impl fmt::Display for TreePath {
280 #[inline]
281 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
282 f.write_str(&self.to_str())
283 }
284}