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