Skip to main content

gtk4/auto/
builder_list_item_factory.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::{BuilderScope, ListItemFactory, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    ///
10    /// ```text
11    ///
12    /// A common approach is to embed such templates as CDATA marked sections into
13    /// a surrounding UI file. Note that if you use this approach, extracting
14    /// translatable strings with xgettext will not work for strings inside the
15    /// marked section.
16    ///
17    /// ## Properties
18    ///
19    ///
20    /// #### `bytes`
21    ///  `GBytes` containing the UI definition.
22    ///
23    /// Readable | Writable | Construct Only
24    ///
25    ///
26    /// #### `resource`
27    ///  Path of the resource containing the UI definition.
28    ///
29    /// Readable | Writable | Construct Only
30    ///
31    ///
32    /// #### `scope`
33    ///  [`BuilderScope`][crate::BuilderScope] to use when instantiating listitems
34    ///
35    /// Readable | Writable | Construct Only
36    ///
37    /// # Implements
38    ///
39    /// [`ListItemFactoryExt`][trait@crate::prelude::ListItemFactoryExt], [`trait@glib::ObjectExt`]
40    #[doc(alias = "GtkBuilderListItemFactory")]
41    pub struct BuilderListItemFactory(Object<ffi::GtkBuilderListItemFactory, ffi::GtkBuilderListItemFactoryClass>) @extends ListItemFactory;
42
43    match fn {
44        type_ => || ffi::gtk_builder_list_item_factory_get_type(),
45    }
46}
47
48impl BuilderListItemFactory {
49    /// Creates a new [`BuilderListItemFactory`][crate::BuilderListItemFactory] that instantiates widgets
50    /// using @bytes as the data to pass to [`Builder`][crate::Builder].
51    /// ## `scope`
52    /// A scope to use when instantiating
53    /// ## `bytes`
54    /// the `GBytes` containing the UI definition to instantiate
55    ///
56    /// # Returns
57    ///
58    /// a new [`BuilderListItemFactory`][crate::BuilderListItemFactory]
59    #[doc(alias = "gtk_builder_list_item_factory_new_from_bytes")]
60    #[doc(alias = "new_from_bytes")]
61    pub fn from_bytes(
62        scope: Option<&impl IsA<BuilderScope>>,
63        bytes: &glib::Bytes,
64    ) -> BuilderListItemFactory {
65        assert_initialized_main_thread!();
66        unsafe {
67            ListItemFactory::from_glib_full(ffi::gtk_builder_list_item_factory_new_from_bytes(
68                scope.map(|p| p.as_ref()).to_glib_none().0,
69                bytes.to_glib_none().0,
70            ))
71            .unsafe_cast()
72        }
73    }
74
75    /// Creates a new [`BuilderListItemFactory`][crate::BuilderListItemFactory] that instantiates widgets
76    /// using data read from the given @resource_path to pass to [`Builder`][crate::Builder].
77    /// ## `scope`
78    /// A scope to use when instantiating
79    /// ## `resource_path`
80    /// valid path to a resource that contains the UI definition
81    ///
82    /// # Returns
83    ///
84    /// a new [`BuilderListItemFactory`][crate::BuilderListItemFactory]
85    #[doc(alias = "gtk_builder_list_item_factory_new_from_resource")]
86    #[doc(alias = "new_from_resource")]
87    pub fn from_resource(
88        scope: Option<&impl IsA<BuilderScope>>,
89        resource_path: &str,
90    ) -> BuilderListItemFactory {
91        assert_initialized_main_thread!();
92        unsafe {
93            ListItemFactory::from_glib_full(ffi::gtk_builder_list_item_factory_new_from_resource(
94                scope.map(|p| p.as_ref()).to_glib_none().0,
95                resource_path.to_glib_none().0,
96            ))
97            .unsafe_cast()
98        }
99    }
100
101    /// Gets the data used as the [`Builder`][crate::Builder] UI template for constructing
102    /// listitems.
103    ///
104    /// # Returns
105    ///
106    /// The [`Builder`][crate::Builder] data
107    #[doc(alias = "gtk_builder_list_item_factory_get_bytes")]
108    #[doc(alias = "get_bytes")]
109    pub fn bytes(&self) -> glib::Bytes {
110        unsafe {
111            from_glib_none(ffi::gtk_builder_list_item_factory_get_bytes(
112                self.to_glib_none().0,
113            ))
114        }
115    }
116
117    /// If the data references a resource, gets the path of that resource.
118    ///
119    /// # Returns
120    ///
121    /// The path to the resource
122    #[doc(alias = "gtk_builder_list_item_factory_get_resource")]
123    #[doc(alias = "get_resource")]
124    pub fn resource(&self) -> Option<glib::GString> {
125        unsafe {
126            from_glib_none(ffi::gtk_builder_list_item_factory_get_resource(
127                self.to_glib_none().0,
128            ))
129        }
130    }
131
132    /// Gets the scope used when constructing listitems.
133    ///
134    /// # Returns
135    ///
136    /// The scope used when constructing listitems
137    #[doc(alias = "gtk_builder_list_item_factory_get_scope")]
138    #[doc(alias = "get_scope")]
139    pub fn scope(&self) -> Option<BuilderScope> {
140        unsafe {
141            from_glib_none(ffi::gtk_builder_list_item_factory_get_scope(
142                self.to_glib_none().0,
143            ))
144        }
145    }
146}