gtk/auto/cell_layout.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::{CellArea, CellRenderer, TreeIter, TreeModel, ffi};
6use glib::{prelude::*, translate::*};
7use std::boxed::Box as Box_;
8
9glib::wrapper! {
10 /// [`CellLayout`][crate::CellLayout] is an interface to be implemented by all objects which
11 /// want to provide a [`TreeViewColumn`][crate::TreeViewColumn] like API for packing cells,
12 /// setting attributes and data funcs.
13 ///
14 /// One of the notable features provided by implementations of
15 /// GtkCellLayout are attributes. Attributes let you set the properties
16 /// in flexible ways. They can just be set to constant values like regular
17 /// properties. But they can also be mapped to a column of the underlying
18 /// tree model with `gtk_cell_layout_set_attributes()`, which means that the value
19 /// of the attribute can change from cell to cell as they are rendered by
20 /// the cell renderer. Finally, it is possible to specify a function with
21 /// [`CellLayoutExt::set_cell_data_func()`][crate::prelude::CellLayoutExt::set_cell_data_func()] that is called to determine the
22 /// value of the attribute for each cell that is rendered.
23 ///
24 /// # GtkCellLayouts as GtkBuildable
25 ///
26 /// Implementations of GtkCellLayout which also implement the GtkBuildable
27 /// interface ([`CellView`][crate::CellView], [`IconView`][crate::IconView], [`ComboBox`][crate::ComboBox],
28 /// [`EntryCompletion`][crate::EntryCompletion], [`TreeViewColumn`][crate::TreeViewColumn]) accept GtkCellRenderer objects
29 /// as ``<child>`` elements in UI definitions. They support a custom ``<attributes>``
30 /// element for their children, which can contain multiple ``<attribute>``
31 /// elements. Each ``<attribute>`` element has a name attribute which specifies
32 /// a property of the cell renderer; the content of the element is the
33 /// attribute value.
34 ///
35 /// This is an example of a UI definition fragment specifying attributes:
36 ///
37 ///
38 ///
39 /// **⚠️ The following code is in xml ⚠️**
40 ///
41 /// ```xml
42 /// <object class="GtkCellView">
43 /// <child>
44 /// <object class="GtkCellRendererText"/>
45 /// <attributes>
46 /// <attribute name="text">0</attribute>
47 /// </attributes>
48 /// </child>
49 /// </object>
50 /// ```
51 ///
52 /// Furthermore for implementations of GtkCellLayout that use a [`CellArea`][crate::CellArea]
53 /// to lay out cells (all GtkCellLayouts in GTK+ use a GtkCellArea)
54 /// [cell properties][cell-properties] can also be defined in the format by
55 /// specifying the custom ``<cell-packing>`` attribute which can contain multiple
56 /// ``<property>`` elements defined in the normal way.
57 ///
58 /// Here is a UI definition fragment specifying cell properties:
59 ///
60 ///
61 ///
62 /// **⚠️ The following code is in xml ⚠️**
63 ///
64 /// ```xml
65 /// <object class="GtkTreeViewColumn">
66 /// <child>
67 /// <object class="GtkCellRendererText"/>
68 /// <cell-packing>
69 /// <property name="align">True</property>
70 /// <property name="expand">False</property>
71 /// </cell-packing>
72 /// </child>
73 /// </object>
74 /// ```
75 ///
76 /// # Subclassing GtkCellLayout implementations
77 ///
78 /// When subclassing a widget that implements [`CellLayout`][crate::CellLayout] like
79 /// [`IconView`][crate::IconView] or [`ComboBox`][crate::ComboBox], there are some considerations related
80 /// to the fact that these widgets internally use a [`CellArea`][crate::CellArea].
81 /// The cell area is exposed as a construct-only property by these
82 /// widgets. This means that it is possible to e.g. do
83 ///
84 ///
85 ///
86 /// **⚠️ The following code is in C ⚠️**
87 ///
88 /// ```C
89 /// combo = g_object_new (GTK_TYPE_COMBO_BOX, "cell-area", my_cell_area, NULL);
90 /// ```
91 ///
92 /// to use a custom cell area with a combo box. But construct properties
93 /// are only initialized after instance `init()`
94 /// functions have run, which means that using functions which rely on
95 /// the existence of the cell area in your subclass’ `init()` function will
96 /// cause the default cell area to be instantiated. In this case, a provided
97 /// construct property value will be ignored (with a warning, to alert
98 /// you to the problem).
99 ///
100 ///
101 ///
102 /// **⚠️ The following code is in C ⚠️**
103 ///
104 /// ```C
105 /// static void
106 /// my_combo_box_init (MyComboBox *b)
107 /// {
108 /// GtkCellRenderer *cell;
109 ///
110 /// cell = gtk_cell_renderer_pixbuf_new ();
111 /// // The following call causes the default cell area for combo boxes,
112 /// // a GtkCellAreaBox, to be instantiated
113 /// gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (b), cell, FALSE);
114 /// ...
115 /// }
116 ///
117 /// GtkWidget *
118 /// my_combo_box_new (GtkCellArea *area)
119 /// {
120 /// // This call is going to cause a warning about area being ignored
121 /// return g_object_new (MY_TYPE_COMBO_BOX, "cell-area", area, NULL);
122 /// }
123 /// ```
124 ///
125 /// If supporting alternative cell areas with your derived widget is
126 /// not important, then this does not have to concern you. If you want
127 /// to support alternative cell areas, you can do so by moving the
128 /// problematic calls out of `init()` and into a `constructor()`
129 /// for your class.
130 ///
131 /// # Implements
132 ///
133 /// [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt]
134 #[doc(alias = "GtkCellLayout")]
135 pub struct CellLayout(Interface<ffi::GtkCellLayout, ffi::GtkCellLayoutIface>);
136
137 match fn {
138 type_ => || ffi::gtk_cell_layout_get_type(),
139 }
140}
141
142impl CellLayout {
143 pub const NONE: Option<&'static CellLayout> = None;
144}
145
146/// Trait containing all [`struct@CellLayout`] methods.
147///
148/// # Implementors
149///
150/// [`AppChooserButton`][struct@crate::AppChooserButton], [`CellAreaBox`][struct@crate::CellAreaBox], [`CellArea`][struct@crate::CellArea], [`CellLayout`][struct@crate::CellLayout], [`CellView`][struct@crate::CellView], [`ComboBoxText`][struct@crate::ComboBoxText], [`ComboBox`][struct@crate::ComboBox], [`EntryCompletion`][struct@crate::EntryCompletion], [`IconView`][struct@crate::IconView], [`TreeViewColumn`][struct@crate::TreeViewColumn]
151pub trait CellLayoutExt: IsA<CellLayout> + 'static {
152 /// Adds an attribute mapping to the list in `self`.
153 ///
154 /// The `column` is the column of the model to get a value from, and the
155 /// `attribute` is the parameter on `cell` to be set from the value. So for
156 /// example if column 2 of the model contains strings, you could have the
157 /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
158 /// ## `cell`
159 /// a [`CellRenderer`][crate::CellRenderer]
160 /// ## `attribute`
161 /// an attribute on the renderer
162 /// ## `column`
163 /// the column position on the model to get the attribute from
164 #[doc(alias = "gtk_cell_layout_add_attribute")]
165 fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
166 unsafe {
167 ffi::gtk_cell_layout_add_attribute(
168 self.as_ref().to_glib_none().0,
169 cell.as_ref().to_glib_none().0,
170 attribute.to_glib_none().0,
171 column,
172 );
173 }
174 }
175
176 /// Unsets all the mappings on all renderers on `self` and
177 /// removes all renderers from `self`.
178 #[doc(alias = "gtk_cell_layout_clear")]
179 fn clear(&self) {
180 unsafe {
181 ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
182 }
183 }
184
185 /// Clears all existing attributes previously set with
186 /// `gtk_cell_layout_set_attributes()`.
187 /// ## `cell`
188 /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
189 #[doc(alias = "gtk_cell_layout_clear_attributes")]
190 fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
191 unsafe {
192 ffi::gtk_cell_layout_clear_attributes(
193 self.as_ref().to_glib_none().0,
194 cell.as_ref().to_glib_none().0,
195 );
196 }
197 }
198
199 /// Returns the underlying [`CellArea`][crate::CellArea] which might be `self`
200 /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
201 /// is used by `self`.
202 ///
203 /// # Returns
204 ///
205 /// the cell area used by `self`,
206 /// or [`None`] in case no cell area is used.
207 #[doc(alias = "gtk_cell_layout_get_area")]
208 #[doc(alias = "get_area")]
209 fn area(&self) -> Option<CellArea> {
210 unsafe {
211 from_glib_none(ffi::gtk_cell_layout_get_area(
212 self.as_ref().to_glib_none().0,
213 ))
214 }
215 }
216
217 /// Returns the cell renderers which have been added to `self`.
218 ///
219 /// # Returns
220 ///
221 ///
222 /// a list of cell renderers. The list, but not the renderers has
223 /// been newly allocated and should be freed with `g_list_free()`
224 /// when no longer needed.
225 #[doc(alias = "gtk_cell_layout_get_cells")]
226 #[doc(alias = "get_cells")]
227 fn cells(&self) -> Vec<CellRenderer> {
228 unsafe {
229 FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
230 self.as_ref().to_glib_none().0,
231 ))
232 }
233 }
234
235 /// Adds the `cell` to the end of `self`. If `expand` is [`false`], then the
236 /// `cell` is allocated no more space than it needs. Any unused space is
237 /// divided evenly between cells for which `expand` is [`true`].
238 ///
239 /// Note that reusing the same cell renderer is not supported.
240 /// ## `cell`
241 /// a [`CellRenderer`][crate::CellRenderer]
242 /// ## `expand`
243 /// [`true`] if `cell` is to be given extra space allocated to `self`
244 #[doc(alias = "gtk_cell_layout_pack_end")]
245 fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
246 unsafe {
247 ffi::gtk_cell_layout_pack_end(
248 self.as_ref().to_glib_none().0,
249 cell.as_ref().to_glib_none().0,
250 expand.into_glib(),
251 );
252 }
253 }
254
255 /// Packs the `cell` into the beginning of `self`. If `expand` is [`false`],
256 /// then the `cell` is allocated no more space than it needs. Any unused space
257 /// is divided evenly between cells for which `expand` is [`true`].
258 ///
259 /// Note that reusing the same cell renderer is not supported.
260 /// ## `cell`
261 /// a [`CellRenderer`][crate::CellRenderer]
262 /// ## `expand`
263 /// [`true`] if `cell` is to be given extra space allocated to `self`
264 #[doc(alias = "gtk_cell_layout_pack_start")]
265 fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
266 unsafe {
267 ffi::gtk_cell_layout_pack_start(
268 self.as_ref().to_glib_none().0,
269 cell.as_ref().to_glib_none().0,
270 expand.into_glib(),
271 );
272 }
273 }
274
275 /// Re-inserts `cell` at `position`.
276 ///
277 /// Note that `cell` has already to be packed into `self`
278 /// for this to function properly.
279 /// ## `cell`
280 /// a [`CellRenderer`][crate::CellRenderer] to reorder
281 /// ## `position`
282 /// new position to insert `cell` at
283 #[doc(alias = "gtk_cell_layout_reorder")]
284 fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
285 unsafe {
286 ffi::gtk_cell_layout_reorder(
287 self.as_ref().to_glib_none().0,
288 cell.as_ref().to_glib_none().0,
289 position,
290 );
291 }
292 }
293
294 //#[doc(alias = "gtk_cell_layout_set_attributes")]
295 //fn set_attributes(&self, cell: &impl IsA<CellRenderer>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
296 // unsafe { TODO: call ffi:gtk_cell_layout_set_attributes() }
297 //}
298
299 /// Sets the `GtkCellLayoutDataFunc` to use for `self`.
300 ///
301 /// This function is used instead of the standard attributes mapping
302 /// for setting the column value, and should set the value of `self`’s
303 /// cell renderer(s) as appropriate.
304 ///
305 /// `func` may be [`None`] to remove a previously set function.
306 /// ## `cell`
307 /// a [`CellRenderer`][crate::CellRenderer]
308 /// ## `func`
309 /// the `GtkCellLayoutDataFunc` to use, or [`None`]
310 /// ## `func_data`
311 /// user data for `func`
312 #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
313 fn set_cell_data_func(
314 &self,
315 cell: &impl IsA<CellRenderer>,
316 func: Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
317 ) {
318 let func_data: Box_<
319 Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
320 > = Box_::new(func);
321 unsafe extern "C" fn func_func(
322 cell_layout: *mut ffi::GtkCellLayout,
323 cell: *mut ffi::GtkCellRenderer,
324 tree_model: *mut ffi::GtkTreeModel,
325 iter: *mut ffi::GtkTreeIter,
326 data: glib::ffi::gpointer,
327 ) {
328 unsafe {
329 let cell_layout = from_glib_borrow(cell_layout);
330 let cell = from_glib_borrow(cell);
331 let tree_model = from_glib_borrow(tree_model);
332 let iter = from_glib_borrow(iter);
333 let callback = &*(data as *mut Option<
334 Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>,
335 >);
336 if let Some(ref callback) = *callback {
337 callback(&cell_layout, &cell, &tree_model, &iter)
338 } else {
339 panic!("cannot get closure...")
340 }
341 }
342 }
343 let func = if func_data.is_some() {
344 Some(func_func as _)
345 } else {
346 None
347 };
348 unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
349 unsafe {
350 let _callback = Box_::from_raw(
351 data as *mut Option<
352 Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>,
353 >,
354 );
355 }
356 }
357 let destroy_call4 = Some(destroy_func as _);
358 let super_callback0: Box_<
359 Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
360 > = func_data;
361 unsafe {
362 ffi::gtk_cell_layout_set_cell_data_func(
363 self.as_ref().to_glib_none().0,
364 cell.as_ref().to_glib_none().0,
365 func,
366 Box_::into_raw(super_callback0) as *mut _,
367 destroy_call4,
368 );
369 }
370 }
371}
372
373impl<O: IsA<CellLayout>> CellLayoutExt for O {}