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::{ffi, ListItem, Widget};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9 /// [`ColumnViewCell`][crate::ColumnViewCell] is used by [`ColumnViewColumn`][crate::ColumnViewColumn] to represent items
10 /// in a cell in [`ColumnView`][crate::ColumnView].
11 ///
12 /// The [`ColumnViewCell`][crate::ColumnViewCell]s are managed by the columnview widget (with its factory)
13 /// and cannot be created by applications, but they need to be populated
14 /// by application code. This is done by calling [`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 | Writeable
32 ///
33 ///
34 /// #### `focusable`
35 /// If the item can be focused with the keyboard.
36 ///
37 /// Readable | Writeable
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 list item.
61 ///
62 /// Readable | Writeable
63 ///
64 ///
65 /// #### `accessible-label`
66 /// The accessible label to set on the list item.
67 ///
68 /// Readable | Writeable
69 ///
70 ///
71 /// #### `activatable`
72 /// If the item can be activated by the user.
73 ///
74 /// Readable | Writeable
75 ///
76 ///
77 /// #### `child`
78 /// Widget used for display.
79 ///
80 /// Readable | Writeable
81 ///
82 ///
83 /// #### `focusable`
84 /// If the item can be focused with the keyboard.
85 ///
86 /// Readable | Writeable
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 | Writeable
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 #[cfg(not(feature = "v4_12"))]
152 #[cfg_attr(docsrs, doc(cfg(not(feature = "v4_12"))))]
153 #[doc(alias = "gtk_column_view_cell_get_focusable")]
154 #[doc(alias = "get_focusable")]
155 #[doc(alias = "focusable")]
156 pub fn is_focusable(&self) -> bool {
157 unsafe {
158 from_glib(ffi::gtk_column_view_cell_get_focusable(
159 self.to_glib_none().0,
160 ))
161 }
162 }
163
164 /// Gets the model item that associated with @self.
165 ///
166 /// If @self is unbound, this function returns [`None`].
167 ///
168 /// # Returns
169 ///
170 /// The item displayed
171 #[doc(alias = "gtk_column_view_cell_get_item")]
172 #[doc(alias = "get_item")]
173 pub fn item(&self) -> Option<glib::Object> {
174 unsafe { from_glib_none(ffi::gtk_column_view_cell_get_item(self.to_glib_none().0)) }
175 }
176
177 /// Gets the position in the model that @self currently displays.
178 ///
179 /// If @self is unbound, `GTK_INVALID_LIST_POSITION` is returned.
180 ///
181 /// # Returns
182 ///
183 /// The position of this item
184 #[doc(alias = "gtk_column_view_cell_get_position")]
185 #[doc(alias = "get_position")]
186 pub fn position(&self) -> u32 {
187 unsafe { ffi::gtk_column_view_cell_get_position(self.to_glib_none().0) }
188 }
189
190 /// Checks if the item is displayed as selected.
191 ///
192 /// The selected state is maintained by the list widget and its model
193 /// and cannot be set otherwise.
194 ///
195 /// # Returns
196 ///
197 /// [`true`] if the item is selected.
198 #[doc(alias = "gtk_column_view_cell_get_selected")]
199 #[doc(alias = "get_selected")]
200 #[doc(alias = "selected")]
201 pub fn is_selected(&self) -> bool {
202 unsafe {
203 from_glib(ffi::gtk_column_view_cell_get_selected(
204 self.to_glib_none().0,
205 ))
206 }
207 }
208
209 /// Sets the child to be used for this listitem.
210 ///
211 /// This function is typically called by applications when
212 /// setting up a listitem so that the widget can be reused when
213 /// binding it multiple times.
214 /// ## `child`
215 /// The list item's child or [`None`] to unset
216 #[doc(alias = "gtk_column_view_cell_set_child")]
217 #[doc(alias = "child")]
218 pub fn set_child(&self, child: Option<&impl IsA<Widget>>) {
219 unsafe {
220 ffi::gtk_column_view_cell_set_child(
221 self.to_glib_none().0,
222 child.map(|p| p.as_ref()).to_glib_none().0,
223 );
224 }
225 }
226
227 /// Sets @self to be focusable.
228 ///
229 /// If an item is focusable, it can be focused using the keyboard.
230 /// This works similar to [`WidgetExt::set_focusable()`][crate::prelude::WidgetExt::set_focusable()].
231 ///
232 /// Note that if items are not focusable, the keyboard cannot be used to activate
233 /// them and selecting only works if one of the listitem's children is focusable.
234 ///
235 /// By default, list items are focusable.
236 /// ## `focusable`
237 /// if the item should be focusable
238 #[cfg(not(feature = "v4_12"))]
239 #[cfg_attr(docsrs, doc(cfg(not(feature = "v4_12"))))]
240 #[doc(alias = "gtk_column_view_cell_set_focusable")]
241 #[doc(alias = "focusable")]
242 pub fn set_focusable(&self, focusable: bool) {
243 unsafe {
244 ffi::gtk_column_view_cell_set_focusable(self.to_glib_none().0, focusable.into_glib());
245 }
246 }
247}
248
249// rustdoc-stripper-ignore-next
250/// A [builder-pattern] type to construct [`ColumnViewCell`] objects.
251///
252/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
253#[must_use = "The builder must be built to be used"]
254pub struct ColumnViewCellBuilder {
255 builder: glib::object::ObjectBuilder<'static, ColumnViewCell>,
256}
257
258impl ColumnViewCellBuilder {
259 fn new() -> Self {
260 Self {
261 builder: glib::object::Object::builder(),
262 }
263 }
264
265 /// Widget used for display.
266 #[cfg(feature = "v4_12")]
267 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
268 pub fn child(self, child: &impl IsA<Widget>) -> Self {
269 Self {
270 builder: self.builder.property("child", child.clone().upcast()),
271 }
272 }
273
274 /// If the item can be focused with the keyboard.
275 #[cfg(feature = "v4_12")]
276 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
277 pub fn focusable(self, focusable: bool) -> Self {
278 Self {
279 builder: self.builder.property("focusable", focusable),
280 }
281 }
282
283 /// The accessible description to set on the list item.
284 #[cfg(feature = "v4_12")]
285 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
286 pub fn accessible_description(self, accessible_description: impl Into<glib::GString>) -> Self {
287 Self {
288 builder: self
289 .builder
290 .property("accessible-description", accessible_description.into()),
291 }
292 }
293
294 /// The accessible label to set on the list item.
295 #[cfg(feature = "v4_12")]
296 #[cfg_attr(docsrs, doc(cfg(feature = "v4_12")))]
297 pub fn accessible_label(self, accessible_label: impl Into<glib::GString>) -> Self {
298 Self {
299 builder: self
300 .builder
301 .property("accessible-label", accessible_label.into()),
302 }
303 }
304
305 /// If the item can be activated by the user.
306 pub fn activatable(self, activatable: bool) -> Self {
307 Self {
308 builder: self.builder.property("activatable", activatable),
309 }
310 }
311
312 /// If the item can be selected by the user.
313 pub fn selectable(self, selectable: bool) -> Self {
314 Self {
315 builder: self.builder.property("selectable", selectable),
316 }
317 }
318
319 // rustdoc-stripper-ignore-next
320 /// Build the [`ColumnViewCell`].
321 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
322 pub fn build(self) -> ColumnViewCell {
323 assert_initialized_main_thread!();
324 self.builder.build()
325 }
326}