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