Skip to main content

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};
6use glib::{prelude::*, translate::*};
7use std::{boxed::Box as Box_, fmt};
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
146mod sealed {
147    pub trait Sealed {}
148    impl<T: super::IsA<super::CellLayout>> Sealed for T {}
149}
150
151/// Trait containing all [`struct@CellLayout`] methods.
152///
153/// # Implementors
154///
155/// [`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]
156pub trait CellLayoutExt: IsA<CellLayout> + sealed::Sealed + 'static {
157    /// Adds an attribute mapping to the list in `self`.
158    ///
159    /// The `column` is the column of the model to get a value from, and the
160    /// `attribute` is the parameter on `cell` to be set from the value. So for
161    /// example if column 2 of the model contains strings, you could have the
162    /// “text” attribute of a [`CellRendererText`][crate::CellRendererText] get its values from column 2.
163    /// ## `cell`
164    /// a [`CellRenderer`][crate::CellRenderer]
165    /// ## `attribute`
166    /// an attribute on the renderer
167    /// ## `column`
168    /// the column position on the model to get the attribute from
169    #[doc(alias = "gtk_cell_layout_add_attribute")]
170    fn add_attribute(&self, cell: &impl IsA<CellRenderer>, attribute: &str, column: i32) {
171        unsafe {
172            ffi::gtk_cell_layout_add_attribute(
173                self.as_ref().to_glib_none().0,
174                cell.as_ref().to_glib_none().0,
175                attribute.to_glib_none().0,
176                column,
177            );
178        }
179    }
180
181    /// Unsets all the mappings on all renderers on `self` and
182    /// removes all renderers from `self`.
183    #[doc(alias = "gtk_cell_layout_clear")]
184    fn clear(&self) {
185        unsafe {
186            ffi::gtk_cell_layout_clear(self.as_ref().to_glib_none().0);
187        }
188    }
189
190    /// Clears all existing attributes previously set with
191    /// `gtk_cell_layout_set_attributes()`.
192    /// ## `cell`
193    /// a [`CellRenderer`][crate::CellRenderer] to clear the attribute mapping on
194    #[doc(alias = "gtk_cell_layout_clear_attributes")]
195    fn clear_attributes(&self, cell: &impl IsA<CellRenderer>) {
196        unsafe {
197            ffi::gtk_cell_layout_clear_attributes(
198                self.as_ref().to_glib_none().0,
199                cell.as_ref().to_glib_none().0,
200            );
201        }
202    }
203
204    /// Returns the underlying [`CellArea`][crate::CellArea] which might be `self`
205    /// if called on a [`CellArea`][crate::CellArea] or might be [`None`] if no [`CellArea`][crate::CellArea]
206    /// is used by `self`.
207    ///
208    /// # Returns
209    ///
210    /// the cell area used by `self`,
211    /// or [`None`] in case no cell area is used.
212    #[doc(alias = "gtk_cell_layout_get_area")]
213    #[doc(alias = "get_area")]
214    fn area(&self) -> Option<CellArea> {
215        unsafe {
216            from_glib_none(ffi::gtk_cell_layout_get_area(
217                self.as_ref().to_glib_none().0,
218            ))
219        }
220    }
221
222    /// Returns the cell renderers which have been added to `self`.
223    ///
224    /// # Returns
225    ///
226    ///
227    ///  a list of cell renderers. The list, but not the renderers has
228    ///  been newly allocated and should be freed with `g_list_free()`
229    ///  when no longer needed.
230    #[doc(alias = "gtk_cell_layout_get_cells")]
231    #[doc(alias = "get_cells")]
232    fn cells(&self) -> Vec<CellRenderer> {
233        unsafe {
234            FromGlibPtrContainer::from_glib_container(ffi::gtk_cell_layout_get_cells(
235                self.as_ref().to_glib_none().0,
236            ))
237        }
238    }
239
240    /// Adds the `cell` to the end of `self`. If `expand` is [`false`], then the
241    /// `cell` is allocated no more space than it needs. Any unused space is
242    /// divided evenly between cells for which `expand` is [`true`].
243    ///
244    /// Note that reusing the same cell renderer is not supported.
245    /// ## `cell`
246    /// a [`CellRenderer`][crate::CellRenderer]
247    /// ## `expand`
248    /// [`true`] if `cell` is to be given extra space allocated to `self`
249    #[doc(alias = "gtk_cell_layout_pack_end")]
250    fn pack_end(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
251        unsafe {
252            ffi::gtk_cell_layout_pack_end(
253                self.as_ref().to_glib_none().0,
254                cell.as_ref().to_glib_none().0,
255                expand.into_glib(),
256            );
257        }
258    }
259
260    /// Packs the `cell` into the beginning of `self`. If `expand` is [`false`],
261    /// then the `cell` is allocated no more space than it needs. Any unused space
262    /// is divided evenly between cells for which `expand` is [`true`].
263    ///
264    /// Note that reusing the same cell renderer is not supported.
265    /// ## `cell`
266    /// a [`CellRenderer`][crate::CellRenderer]
267    /// ## `expand`
268    /// [`true`] if `cell` is to be given extra space allocated to `self`
269    #[doc(alias = "gtk_cell_layout_pack_start")]
270    fn pack_start(&self, cell: &impl IsA<CellRenderer>, expand: bool) {
271        unsafe {
272            ffi::gtk_cell_layout_pack_start(
273                self.as_ref().to_glib_none().0,
274                cell.as_ref().to_glib_none().0,
275                expand.into_glib(),
276            );
277        }
278    }
279
280    /// Re-inserts `cell` at `position`.
281    ///
282    /// Note that `cell` has already to be packed into `self`
283    /// for this to function properly.
284    /// ## `cell`
285    /// a [`CellRenderer`][crate::CellRenderer] to reorder
286    /// ## `position`
287    /// new position to insert `cell` at
288    #[doc(alias = "gtk_cell_layout_reorder")]
289    fn reorder(&self, cell: &impl IsA<CellRenderer>, position: i32) {
290        unsafe {
291            ffi::gtk_cell_layout_reorder(
292                self.as_ref().to_glib_none().0,
293                cell.as_ref().to_glib_none().0,
294                position,
295            );
296        }
297    }
298
299    //#[doc(alias = "gtk_cell_layout_set_attributes")]
300    //fn set_attributes(&self, cell: &impl IsA<CellRenderer>, : /*Unknown conversion*//*Unimplemented*/Basic: VarArgs) {
301    //    unsafe { TODO: call ffi:gtk_cell_layout_set_attributes() }
302    //}
303
304    /// Sets the `GtkCellLayoutDataFunc` to use for `self`.
305    ///
306    /// This function is used instead of the standard attributes mapping
307    /// for setting the column value, and should set the value of `self`’s
308    /// cell renderer(s) as appropriate.
309    ///
310    /// `func` may be [`None`] to remove a previously set function.
311    /// ## `cell`
312    /// a [`CellRenderer`][crate::CellRenderer]
313    /// ## `func`
314    /// the `GtkCellLayoutDataFunc` to use, or [`None`]
315    /// ## `func_data`
316    /// user data for `func`
317    #[doc(alias = "gtk_cell_layout_set_cell_data_func")]
318    fn set_cell_data_func(
319        &self,
320        cell: &impl IsA<CellRenderer>,
321        func: Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
322    ) {
323        let func_data: Box_<
324            Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
325        > = Box_::new(func);
326        unsafe extern "C" fn func_func(
327            cell_layout: *mut ffi::GtkCellLayout,
328            cell: *mut ffi::GtkCellRenderer,
329            tree_model: *mut ffi::GtkTreeModel,
330            iter: *mut ffi::GtkTreeIter,
331            data: glib::ffi::gpointer,
332        ) {
333            let cell_layout = from_glib_borrow(cell_layout);
334            let cell = from_glib_borrow(cell);
335            let tree_model = from_glib_borrow(tree_model);
336            let iter = from_glib_borrow(iter);
337            let callback: &Option<
338                Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>,
339            > = &*(data as *mut _);
340            if let Some(ref callback) = *callback {
341                callback(&cell_layout, &cell, &tree_model, &iter)
342            } else {
343                panic!("cannot get closure...")
344            }
345        }
346        let func = if func_data.is_some() {
347            Some(func_func as _)
348        } else {
349            None
350        };
351        unsafe extern "C" fn destroy_func(data: glib::ffi::gpointer) {
352            let _callback: Box_<
353                Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
354            > = Box_::from_raw(data as *mut _);
355        }
356        let destroy_call4 = Some(destroy_func as _);
357        let super_callback0: Box_<
358            Option<Box_<dyn Fn(&CellLayout, &CellRenderer, &TreeModel, &TreeIter) + 'static>>,
359        > = func_data;
360        unsafe {
361            ffi::gtk_cell_layout_set_cell_data_func(
362                self.as_ref().to_glib_none().0,
363                cell.as_ref().to_glib_none().0,
364                func,
365                Box_::into_raw(super_callback0) as *mut _,
366                destroy_call4,
367            );
368        }
369    }
370}
371
372impl<O: IsA<CellLayout>> CellLayoutExt for O {}
373
374impl fmt::Display for CellLayout {
375    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
376        f.write_str("CellLayout")
377    }
378}