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 /// ## Properties
37 ///
38 ///
39 /// #### `bytes`
40 /// `GBytes` containing the UI definition.
41 ///
42 /// Readable | Writeable | Construct Only
43 ///
44 ///
45 /// #### `resource`
46 /// Path of the resource containing the UI definition.
47 ///
48 /// Readable | Writeable | Construct Only
49 ///
50 ///
51 /// #### `scope`
52 /// [`BuilderScope`][crate::BuilderScope] to use when instantiating listitems
53 ///
54 /// Readable | Writeable | Construct Only
55 ///
56 /// # Implements
57 ///
58 /// [`ListItemFactoryExt`][trait@crate::prelude::ListItemFactoryExt], [`trait@glib::ObjectExt`]
59 #[doc(alias = "GtkBuilderListItemFactory")]
60 pub struct BuilderListItemFactory(Object<ffi::GtkBuilderListItemFactory, ffi::GtkBuilderListItemFactoryClass>) @extends ListItemFactory;
61
62 match fn {
63 type_ => || ffi::gtk_builder_list_item_factory_get_type(),
64 }
65}
66
67impl BuilderListItemFactory {
68 /// Creates a new [`BuilderListItemFactory`][crate::BuilderListItemFactory] that instantiates widgets
69 /// using @bytes as the data to pass to [`Builder`][crate::Builder].
70 /// ## `scope`
71 /// A scope to use when instantiating
72 /// ## `bytes`
73 /// the `GBytes` containing the UI definition to instantiate
74 ///
75 /// # Returns
76 ///
77 /// a new [`BuilderListItemFactory`][crate::BuilderListItemFactory]
78 #[doc(alias = "gtk_builder_list_item_factory_new_from_bytes")]
79 #[doc(alias = "new_from_bytes")]
80 pub fn from_bytes(
81 scope: Option<&impl IsA<BuilderScope>>,
82 bytes: &glib::Bytes,
83 ) -> BuilderListItemFactory {
84 assert_initialized_main_thread!();
85 unsafe {
86 ListItemFactory::from_glib_full(ffi::gtk_builder_list_item_factory_new_from_bytes(
87 scope.map(|p| p.as_ref()).to_glib_none().0,
88 bytes.to_glib_none().0,
89 ))
90 .unsafe_cast()
91 }
92 }
93
94 /// Creates a new [`BuilderListItemFactory`][crate::BuilderListItemFactory] that instantiates widgets
95 /// using data read from the given @resource_path to pass to [`Builder`][crate::Builder].
96 /// ## `scope`
97 /// A scope to use when instantiating
98 /// ## `resource_path`
99 /// valid path to a resource that contains the UI definition
100 ///
101 /// # Returns
102 ///
103 /// a new [`BuilderListItemFactory`][crate::BuilderListItemFactory]
104 #[doc(alias = "gtk_builder_list_item_factory_new_from_resource")]
105 #[doc(alias = "new_from_resource")]
106 pub fn from_resource(
107 scope: Option<&impl IsA<BuilderScope>>,
108 resource_path: &str,
109 ) -> BuilderListItemFactory {
110 assert_initialized_main_thread!();
111 unsafe {
112 ListItemFactory::from_glib_full(ffi::gtk_builder_list_item_factory_new_from_resource(
113 scope.map(|p| p.as_ref()).to_glib_none().0,
114 resource_path.to_glib_none().0,
115 ))
116 .unsafe_cast()
117 }
118 }
119
120 /// Gets the data used as the [`Builder`][crate::Builder] UI template for constructing
121 /// listitems.
122 ///
123 /// # Returns
124 ///
125 /// The [`Builder`][crate::Builder] data
126 #[doc(alias = "gtk_builder_list_item_factory_get_bytes")]
127 #[doc(alias = "get_bytes")]
128 pub fn bytes(&self) -> glib::Bytes {
129 unsafe {
130 from_glib_none(ffi::gtk_builder_list_item_factory_get_bytes(
131 self.to_glib_none().0,
132 ))
133 }
134 }
135
136 /// If the data references a resource, gets the path of that resource.
137 ///
138 /// # Returns
139 ///
140 /// The path to the resource
141 #[doc(alias = "gtk_builder_list_item_factory_get_resource")]
142 #[doc(alias = "get_resource")]
143 pub fn resource(&self) -> Option<glib::GString> {
144 unsafe {
145 from_glib_none(ffi::gtk_builder_list_item_factory_get_resource(
146 self.to_glib_none().0,
147 ))
148 }
149 }
150
151 /// Gets the scope used when constructing listitems.
152 ///
153 /// # Returns
154 ///
155 /// The scope used when constructing listitems
156 #[doc(alias = "gtk_builder_list_item_factory_get_scope")]
157 #[doc(alias = "get_scope")]
158 pub fn scope(&self) -> Option<BuilderScope> {
159 unsafe {
160 from_glib_none(ffi::gtk_builder_list_item_factory_get_scope(
161 self.to_glib_none().0,
162 ))
163 }
164 }
165}