gtk/combo_box.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use crate::ComboBox;
4use glib::object::IsA;
5use glib::translate::*;
6
7mod sealed {
8 pub trait Sealed {}
9 impl<T: glib::IsA<crate::ComboBox>> Sealed for T {}
10}
11
12pub trait ComboBoxExtManual: IsA<ComboBox> + sealed::Sealed + 'static {
13 /// Sets the active item of `self` to be the item at `index`.
14 /// ## `index_`
15 /// An index in the model passed during construction, or -1 to have
16 /// no active item
17 #[doc(alias = "gtk_combo_box_set_active")]
18 fn set_active(&self, index_: Option<u32>) {
19 let index_ = match index_ {
20 Some(i) => i as _,
21 None => -1,
22 };
23 unsafe {
24 ffi::gtk_combo_box_set_active(self.as_ref().to_glib_none().0, index_);
25 }
26 }
27
28 /// Returns the index of the currently active item, or -1 if there’s no
29 /// active item. If the model is a non-flat treemodel, and the active item
30 /// is not an immediate child of the root of the tree, this function returns
31 /// `gtk_tree_path_get_indices (path)[0]`, where
32 /// `path` is the [`TreePath`][crate::TreePath] of the active item.
33 ///
34 /// # Returns
35 ///
36 /// An integer which is the index of the currently active item,
37 /// or -1 if there’s no active item.
38 #[doc(alias = "gtk_combo_box_get_active")]
39 #[doc(alias = "get_active")]
40 fn active(&self) -> Option<u32> {
41 match unsafe { ffi::gtk_combo_box_get_active(self.as_ref().to_glib_none().0) } {
42 -1 => None,
43 x => Some(x as _),
44 }
45 }
46}
47
48impl<O: IsA<ComboBox>> ComboBoxExtManual for O {}