gtk4/auto/column_view_cell.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::{ListItem, Widget, ffi};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// Represents items in a cell in [`ColumnView`][crate::ColumnView].
10 ///
11 /// The [`ColumnViewCell`][crate::ColumnViewCell]s are managed by the [`ColumnView`][crate::ColumnView]
12 /// widget (with its factory) and cannot be created by applications, but
13 /// they need to be populated by application code. This is done by calling
14 /// [`set_child()`][Self::set_child()].
15 ///
16 /// [`ColumnViewCell`][crate::ColumnViewCell]s exist in 2 stages:
17 ///
18 /// 1. The unbound stage where the listitem is not currently connected to
19 /// an item in the list. In that case, the [`item`][struct@crate::ColumnViewCell#item]
20 /// property is set to [`None`].
21 ///
22 /// 2. The bound stage where the listitem references an item from the list.
23 /// The [`item`][struct@crate::ColumnViewCell#item] property is not [`None`].
24 ///
25 /// ## Properties
26 ///
27 ///
28 /// #### `child`
29 /// Widget used for display.
30 ///
31 /// Readable | Writable
32 ///
33 ///
34 /// #### `focusable`
35 /// If the item can be focused with the keyboard.
36 ///
37 /// Readable | Writable
38 ///
39 ///
40 /// #### `item`
41 /// Displayed item.
42 ///
43 /// Readable
44 ///
45 ///
46 /// #### `position`
47 /// Position of the item.
48 ///
49 /// Readable
50 ///
51 ///
52 /// #### `selected`
53 /// If the item is currently selected.
54 ///
55 /// Readable
56 /// <details><summary><h4>ListItem</h4></summary>
57 ///
58 ///
59 /// #### `accessible-description`
60 /// The accessible description to set on the listitem.
61 ///
62 /// Readable | Writable
63 ///
64 ///
65 /// #### `accessible-label`
66 /// The accessible label to set on the listitem.
67 ///
68 /// Readable | Writable
69 ///
70 ///
71 /// #### `activatable`
72 /// If the item can be activated by the user.
73 ///
74 /// Readable | Writable
75 ///
76 ///
77 /// #### `child`
78 /// Widget used for display.
79 ///
80 /// Readable | Writable
81 ///
82 ///
83 /// #### `focusable`
84 /// If the item can be focused with the keyboard.
85 ///
86 /// Readable | Writable
87 ///
88 ///
89 /// #### `item`
90 /// Displayed item.
91 ///
92 /// Readable
93 ///
94 ///
95 /// #### `position`
96 /// Position of the item.
97 ///
98 /// Readable
99 ///
100 ///
101 /// #### `selectable`
102 /// If the item can be selected by the user.
103 ///
104 /// Readable | Writable
105 ///
106 ///
107 /// #### `selected`
108 /// If the item is currently selected.
109 ///
110 /// Readable
111 /// </details>
112 ///
113 /// # Implements
114 ///
115 /// [`ListItemExt`][trait@crate::prelude::ListItemExt], [`trait@glib::ObjectExt`]
116 #[doc(alias = "GtkColumnViewCell")]
117 pub struct ColumnViewCell(Object<ffi::GtkColumnViewCell, ffi::GtkColumnViewCellClass>) @extends ListItem;
118
119 match fn {
120 type_ => || ffi::gtk_column_view_cell_get_type(),
121 }
122}
123
124impl ColumnViewCell {
125 // rustdoc-stripper-ignore-next
126 /// Creates a new builder-pattern struct instance to construct [`ColumnViewCell`] objects.
127 ///
128 /// This method returns an instance of [`ColumnViewCellBuilder`](crate::builders::ColumnViewCellBuilder) which can be used to create [`ColumnViewCell`] objects.
129 pub fn builder() -> ColumnViewCellBuilder {
130 ColumnViewCellBuilder::new()
131 }
132
133 /// Gets the child previously set via gtk_column_view_cell_set_child() or
134 /// [`None`] if none was set.
135 ///
136 /// # Returns
137 ///
138 /// The child
139 #[doc(alias = "gtk_column_view_cell_get_child")]
140 #[doc(alias = "get_child")]
141 pub fn child(&self) -> Option<Widget> {
142 unsafe { from_glib_none(ffi::gtk_column_view_cell_get_child(self.to_glib_none().0)) }
143 }
144
145 /// Checks if a list item has been set to be focusable via
146 /// gtk_column_view_cell_set_focusable().
147 ///
148 /// # Returns
149 ///
150 /// [`true`] if the item is focusable
151 #[doc(alias = "gtk_column_view_cell_get_focusable")]
152 #[doc(alias = "get_focusable")]
153 #[doc(alias = "focusable")]
154 pub fn is_focusable(&self) -> bool {
155 unsafe {
156 from_glib(ffi::gtk_column_view_cell_get_focusable(
157 self.to_glib_none().0,
158 ))
159 }
160 }
161
162 /// Gets the model item that associated with @self.
163 ///
164 /// If @self is unbound, this function returns [`None`].
165 ///
166 /// # Returns
167 ///
168 /// The item displayed
169 #[doc(alias = "gtk_column_view_cell_get_item")]
170 #[doc(alias = "get_item")]
171 pub fn item(&self) -> Option<glib::Object> {
172 unsafe { from_glib_none(ffi::gtk_column_view_cell_get_item(self.to_glib_none().0)) }
173 }
174
175 /// Gets the position in the model that @self currently displays.
176 ///
177 /// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
178 ///
179 /// # Returns
180 ///
181 /// The position of this item
182 #[doc(alias = "gtk_column_view_cell_get_position")]
183 #[doc(alias = "get_position")]
184 pub fn position(&self) -> u32 {
185 unsafe { ffi::gtk_column_view_cell_get_position(self.to_glib_none().0) }
186 }
187
188 /// Checks if the item is displayed as selected.
189 ///
190 /// The selected state is maintained by the list widget and its model
191 /// and cannot be set otherwise.
192 ///
193 /// # Returns
194 ///
195 /// [`true`] if the item is selected.
196 #[doc(alias = "gtk_column_view_cell_get_selected")]
197 #[doc(alias = "get_selected")]
198 #[doc(alias = "selected")]
199 pub fn is_selected(&self) -> bool {
200 unsafe {
201 from_glib(ffi::gtk_column_view_cell_get_selected(
202 self.to_glib_none().0,
203 ))
204 }
205 }
206
207 /// Sets the child to be used for this listitem.
208 ///
209 /// This function is typically called by applications when
210 /// setting up a listitem so that the widget can be reused when
211 /// binding it multiple times.
212 /// ## `child`
213 /// The list item's child or [`None`] to unset
214 #[doc(alias = "gtk_column_view_cell_set_child")]
215 #[doc(alias = "child")]
216 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
217 unsafe {
218 ffi::gtk_column_view_cell_set_child(
219 self.to_glib_none().0,
220 child.map(|p| p.as_ref()).to_glib_none().0,
221 );
222 }
223 }
224
225 /// Sets @self to be focusable.
226 ///
227 /// If an item is focusable, it can be focused using the keyboard.
228 /// This works similar to [`WidgetExt::set_focusable()`][crate::prelude::WidgetExt::set_focusable()].
229 ///
230 /// Note that if items are not focusable, the keyboard cannot be used to activate
231 /// them and selecting only works if one of the listitem's children is focusable.
232 ///
233 /// By default, list items are focusable.
234 /// ## `focusable`
235 /// if the item should be focusable
236 #[doc(alias = "gtk_column_view_cell_set_focusable")]
237 #[doc(alias = "focusable")]
238 pub fn set_focusable(&self, focusable: bool) {
239 unsafe {
240 ffi::gtk_column_view_cell_set_focusable(self.to_glib_none().0, focusable.into_glib());
241 }
242 }
243}
244
245// rustdoc-stripper-ignore-next
246/// A [builder-pattern] type to construct [`ColumnViewCell`] objects.
247///
248/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
249#[must_use = "The builder must be built to be used"]
250pub struct ColumnViewCellBuilder {
251 builder: glib::object::ObjectBuilder<'static, ColumnViewCell>,
252}
253
254impl ColumnViewCellBuilder {
255 fn new() -> Self {
256 Self {
257 builder: glib::object::Object::builder(),
258 }
259 }
260
261 /// Widget used for display.
262 #[cfg(feature = "v4_12")]
263 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
264 pub fn child(self, child: &impl IsA<Widget>) -> Self {
265 Self {
266 builder: self.builder.property("child", child.clone().upcast()),
267 }
268 }
269
270 /// If the item can be focused with the keyboard.
271 #[cfg(feature = "v4_12")]
272 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
273 pub fn focusable(self, focusable: bool) -> Self {
274 Self {
275 builder: self.builder.property("focusable", focusable),
276 }
277 }
278
279 /// The accessible description to set on the listitem.
280 #[cfg(feature = "v4_12")]
281 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
282 pub fn accessible_description(self, accessible_description: impl Into<glib::GString>) -> Self {
283 Self {
284 builder: self
285 .builder
286 .property("accessible-description", accessible_description.into()),
287 }
288 }
289
290 /// The accessible label to set on the listitem.
291 #[cfg(feature = "v4_12")]
292 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
293 pub fn accessible_label(self, accessible_label: impl Into<glib::GString>) -> Self {
294 Self {
295 builder: self
296 .builder
297 .property("accessible-label", accessible_label.into()),
298 }
299 }
300
301 /// If the item can be activated by the user.
302 pub fn activatable(self, activatable: bool) -> Self {
303 Self {
304 builder: self.builder.property("activatable", activatable),
305 }
306 }
307
308 /// If the item can be selected by the user.
309 pub fn selectable(self, selectable: bool) -> Self {
310 Self {
311 builder: self.builder.property("selectable", selectable),
312 }
313 }
314
315 // rustdoc-stripper-ignore-next
316 /// Build the [`ColumnViewCell`].
317 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
318 pub fn build(self) -> ColumnViewCell {
319 assert_initialized_main_thread!();
320 self.builder.build()
321 }
322}