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