gtk4/auto/enum_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::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9 /// A [`gio::ListModel`][crate::gio::ListModel] representing values of a given enum.
10 ///
11 /// [`EnumList`][crate::EnumList] contains objects of type [`EnumListItem`][crate::EnumListItem].
12 ///
13 /// A simple way to use a [`EnumList`][crate::EnumList] is to populate a [`DropDown`][crate::DropDown]
14 /// widget using the short name (or "nick") of the values of an
15 /// enumeration type:
16 ///
17 /// **⚠️ The following code is in c ⚠️**
18 ///
19 /// ```c
20 /// choices = gtk_drop_down_new (G_LIST_MODEL (gtk_enum_list_new (type)),
21 /// gtk_property_expression_new (GTK_TYPE_ENUM_LIST_ITEM,
22 /// NULL,
23 /// "nick"));
24 /// ```
25 ///
26 /// ## Properties
27 ///
28 ///
29 /// #### `enum-type`
30 /// The type of the enum represented by the model.
31 ///
32 /// Readable | Writeable | Construct Only
33 ///
34 ///
35 /// #### `item-type`
36 /// The type of the items. See [`ListModelExtManual::item_type()`][crate::gio::prelude::ListModelExtManual::item_type()].
37 ///
38 /// Readable
39 ///
40 ///
41 /// #### `n-items`
42 /// The number of items. See [`ListModelExtManual::n_items()`][crate::gio::prelude::ListModelExtManual::n_items()].
43 ///
44 /// Readable
45 ///
46 /// # Implements
47 ///
48 /// [`trait@glib::ObjectExt`], [`trait@gio::prelude::ListModelExt`]
49 #[doc(alias = "GtkEnumList")]
50 pub struct EnumList(Object<ffi::GtkEnumList, ffi::GtkEnumListClass>) @implements gio::ListModel;
51
52 match fn {
53 type_ => || ffi::gtk_enum_list_get_type(),
54 }
55}
56
57impl EnumList {
58 /// Creates a new [`EnumList`][crate::EnumList] for @enum_type.
59 /// ## `enum_type`
60 /// the type of the enum to construct the model from
61 ///
62 /// # Returns
63 ///
64 /// the newly created [`EnumList`][crate::EnumList]
65 #[doc(alias = "gtk_enum_list_new")]
66 pub fn new(enum_type: glib::types::Type) -> EnumList {
67 assert_initialized_main_thread!();
68 unsafe { from_glib_full(ffi::gtk_enum_list_new(enum_type.into_glib())) }
69 }
70
71 /// Finds the position of a given enum value in @self.
72 ///
73 /// If the value is not found, `Gtk::INVALID_LIST_POSITION` is returned.
74 /// ## `value`
75 /// an enum value
76 ///
77 /// # Returns
78 ///
79 /// the position of the value
80 #[doc(alias = "gtk_enum_list_find")]
81 pub fn find(&self, value: i32) -> u32 {
82 unsafe { ffi::gtk_enum_list_find(self.to_glib_none().0, value) }
83 }
84
85 /// Gets the type of the enum represented by @self.
86 ///
87 /// # Returns
88 ///
89 /// the enum type
90 #[doc(alias = "gtk_enum_list_get_enum_type")]
91 #[doc(alias = "get_enum_type")]
92 #[doc(alias = "enum-type")]
93 pub fn enum_type(&self) -> glib::types::Type {
94 unsafe { from_glib(ffi::gtk_enum_list_get_enum_type(self.to_glib_none().0)) }
95 }
96}