Skip to main content

gtk/auto/
cell_area_box.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::{Buildable, CellArea, CellLayout, CellRenderer, Orientable, Orientation};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem::transmute};
12
13glib::wrapper! {
14    /// The [`CellAreaBox`][crate::CellAreaBox] renders cell renderers into a row or a column
15    /// depending on its [`Orientation`][crate::Orientation].
16    ///
17    /// GtkCellAreaBox uses a notion of packing. Packing
18    /// refers to adding cell renderers with reference to a particular position
19    /// in a [`CellAreaBox`][crate::CellAreaBox]. There are two reference positions: the
20    /// start and the end of the box.
21    /// When the [`CellAreaBox`][crate::CellAreaBox] is oriented in the [`Orientation::Vertical`][crate::Orientation::Vertical]
22    /// orientation, the start is defined as the top of the box and the end is
23    /// defined as the bottom. In the [`Orientation::Horizontal`][crate::Orientation::Horizontal] orientation
24    /// start is defined as the left side and the end is defined as the right
25    /// side.
26    ///
27    /// Alignments of `GtkCellRenderers` rendered in adjacent rows can be
28    /// configured by configuring the [`CellAreaBox`][crate::CellAreaBox] align child cell property
29    /// with [`CellAreaExt::cell_set_property()`][crate::prelude::CellAreaExt::cell_set_property()] or by specifying the "align"
30    /// argument to [`CellAreaBoxExt::pack_start()`][crate::prelude::CellAreaBoxExt::pack_start()] and [`CellAreaBoxExt::pack_end()`][crate::prelude::CellAreaBoxExt::pack_end()].
31    ///
32    /// ## Properties
33    ///
34    ///
35    /// #### `spacing`
36    ///  The amount of space to reserve between cells.
37    ///
38    /// Readable | Writeable
39    /// <details><summary><h4>CellArea</h4></summary>
40    ///
41    ///
42    /// #### `edit-widget`
43    ///  The widget currently editing the edited cell
44    ///
45    /// This property is read-only and only changes as
46    /// a result of a call [`CellAreaExt::activate_cell()`][crate::prelude::CellAreaExt::activate_cell()].
47    ///
48    /// Readable
49    ///
50    ///
51    /// #### `edited-cell`
52    ///  The cell in the area that is currently edited
53    ///
54    /// This property is read-only and only changes as
55    /// a result of a call [`CellAreaExt::activate_cell()`][crate::prelude::CellAreaExt::activate_cell()].
56    ///
57    /// Readable
58    ///
59    ///
60    /// #### `focus-cell`
61    ///  The cell in the area that currently has focus
62    ///
63    /// Readable | Writeable
64    /// </details>
65    /// <details><summary><h4>Orientable</h4></summary>
66    ///
67    ///
68    /// #### `orientation`
69    ///  The orientation of the orientable.
70    ///
71    /// Readable | Writeable
72    /// </details>
73    ///
74    /// # Implements
75    ///
76    /// [`CellAreaBoxExt`][trait@crate::prelude::CellAreaBoxExt], [`CellAreaExt`][trait@crate::prelude::CellAreaExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`CellLayoutExt`][trait@crate::prelude::CellLayoutExt], [`OrientableExt`][trait@crate::prelude::OrientableExt], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
77    #[doc(alias = "GtkCellAreaBox")]
78    pub struct CellAreaBox(Object<ffi::GtkCellAreaBox, ffi::GtkCellAreaBoxClass>) @extends CellArea, @implements Buildable, CellLayout, Orientable;
79
80    match fn {
81        type_ => || ffi::gtk_cell_area_box_get_type(),
82    }
83}
84
85impl CellAreaBox {
86    pub const NONE: Option<&'static CellAreaBox> = None;
87
88    /// Creates a new [`CellAreaBox`][crate::CellAreaBox].
89    ///
90    /// # Returns
91    ///
92    /// a newly created [`CellAreaBox`][crate::CellAreaBox]
93    #[doc(alias = "gtk_cell_area_box_new")]
94    pub fn new() -> CellAreaBox {
95        assert_initialized_main_thread!();
96        unsafe { CellArea::from_glib_none(ffi::gtk_cell_area_box_new()).unsafe_cast() }
97    }
98
99    // rustdoc-stripper-ignore-next
100    /// Creates a new builder-pattern struct instance to construct [`CellAreaBox`] objects.
101    ///
102    /// This method returns an instance of [`CellAreaBoxBuilder`](crate::builders::CellAreaBoxBuilder) which can be used to create [`CellAreaBox`] objects.
103    pub fn builder() -> CellAreaBoxBuilder {
104        CellAreaBoxBuilder::new()
105    }
106}
107
108impl Default for CellAreaBox {
109    fn default() -> Self {
110        Self::new()
111    }
112}
113
114// rustdoc-stripper-ignore-next
115/// A [builder-pattern] type to construct [`CellAreaBox`] objects.
116///
117/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
118#[must_use = "The builder must be built to be used"]
119pub struct CellAreaBoxBuilder {
120    builder: glib::object::ObjectBuilder<'static, CellAreaBox>,
121}
122
123impl CellAreaBoxBuilder {
124    fn new() -> Self {
125        Self {
126            builder: glib::object::Object::builder(),
127        }
128    }
129
130    /// The amount of space to reserve between cells.
131    pub fn spacing(self, spacing: i32) -> Self {
132        Self {
133            builder: self.builder.property("spacing", spacing),
134        }
135    }
136
137    /// The cell in the area that currently has focus
138    pub fn focus_cell(self, focus_cell: &impl IsA<CellRenderer>) -> Self {
139        Self {
140            builder: self
141                .builder
142                .property("focus-cell", focus_cell.clone().upcast()),
143        }
144    }
145
146    /// The orientation of the orientable.
147    pub fn orientation(self, orientation: Orientation) -> Self {
148        Self {
149            builder: self.builder.property("orientation", orientation),
150        }
151    }
152
153    // rustdoc-stripper-ignore-next
154    /// Build the [`CellAreaBox`].
155    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
156    pub fn build(self) -> CellAreaBox {
157        self.builder.build()
158    }
159}
160
161mod sealed {
162    pub trait Sealed {}
163    impl<T: super::IsA<super::CellAreaBox>> Sealed for T {}
164}
165
166/// Trait containing all [`struct@CellAreaBox`] methods.
167///
168/// # Implementors
169///
170/// [`CellAreaBox`][struct@crate::CellAreaBox]
171pub trait CellAreaBoxExt: IsA<CellAreaBox> + sealed::Sealed + 'static {
172    /// Gets the spacing added between cell renderers.
173    ///
174    /// # Returns
175    ///
176    /// the space added between cell renderers in `self`.
177    #[doc(alias = "gtk_cell_area_box_get_spacing")]
178    #[doc(alias = "get_spacing")]
179    fn spacing(&self) -> i32 {
180        unsafe { ffi::gtk_cell_area_box_get_spacing(self.as_ref().to_glib_none().0) }
181    }
182
183    /// Adds `renderer` to `self`, packed with reference to the end of `self`.
184    ///
185    /// The `renderer` is packed after (away from end of) any other
186    /// [`CellRenderer`][crate::CellRenderer] packed with reference to the end of `self`.
187    /// ## `renderer`
188    /// the [`CellRenderer`][crate::CellRenderer] to add
189    /// ## `expand`
190    /// whether `renderer` should receive extra space when the area receives
191    /// more than its natural size
192    /// ## `align`
193    /// whether `renderer` should be aligned in adjacent rows
194    /// ## `fixed`
195    /// whether `renderer` should have the same size in all rows
196    #[doc(alias = "gtk_cell_area_box_pack_end")]
197    fn pack_end(&self, renderer: &impl IsA<CellRenderer>, expand: bool, align: bool, fixed: bool) {
198        unsafe {
199            ffi::gtk_cell_area_box_pack_end(
200                self.as_ref().to_glib_none().0,
201                renderer.as_ref().to_glib_none().0,
202                expand.into_glib(),
203                align.into_glib(),
204                fixed.into_glib(),
205            );
206        }
207    }
208
209    /// Adds `renderer` to `self`, packed with reference to the start of `self`.
210    ///
211    /// The `renderer` is packed after any other [`CellRenderer`][crate::CellRenderer] packed
212    /// with reference to the start of `self`.
213    /// ## `renderer`
214    /// the [`CellRenderer`][crate::CellRenderer] to add
215    /// ## `expand`
216    /// whether `renderer` should receive extra space when the area receives
217    /// more than its natural size
218    /// ## `align`
219    /// whether `renderer` should be aligned in adjacent rows
220    /// ## `fixed`
221    /// whether `renderer` should have the same size in all rows
222    #[doc(alias = "gtk_cell_area_box_pack_start")]
223    fn pack_start(
224        &self,
225        renderer: &impl IsA<CellRenderer>,
226        expand: bool,
227        align: bool,
228        fixed: bool,
229    ) {
230        unsafe {
231            ffi::gtk_cell_area_box_pack_start(
232                self.as_ref().to_glib_none().0,
233                renderer.as_ref().to_glib_none().0,
234                expand.into_glib(),
235                align.into_glib(),
236                fixed.into_glib(),
237            );
238        }
239    }
240
241    /// Sets the spacing to add between cell renderers in `self`.
242    /// ## `spacing`
243    /// the space to add between `GtkCellRenderers`
244    #[doc(alias = "gtk_cell_area_box_set_spacing")]
245    fn set_spacing(&self, spacing: i32) {
246        unsafe {
247            ffi::gtk_cell_area_box_set_spacing(self.as_ref().to_glib_none().0, spacing);
248        }
249    }
250
251    #[doc(alias = "spacing")]
252    fn connect_spacing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
253        unsafe extern "C" fn notify_spacing_trampoline<P: IsA<CellAreaBox>, F: Fn(&P) + 'static>(
254            this: *mut ffi::GtkCellAreaBox,
255            _param_spec: glib::ffi::gpointer,
256            f: glib::ffi::gpointer,
257        ) {
258            let f: &F = &*(f as *const F);
259            f(CellAreaBox::from_glib_borrow(this).unsafe_cast_ref())
260        }
261        unsafe {
262            let f: Box_<F> = Box_::new(f);
263            connect_raw(
264                self.as_ptr() as *mut _,
265                b"notify::spacing\0".as_ptr() as *const _,
266                Some(transmute::<_, unsafe extern "C" fn()>(
267                    notify_spacing_trampoline::<Self, F> as *const (),
268                )),
269                Box_::into_raw(f),
270            )
271        }
272    }
273}
274
275impl<O: IsA<CellAreaBox>> CellAreaBoxExt for O {}
276
277impl fmt::Display for CellAreaBox {
278    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
279        f.write_str("CellAreaBox")
280    }
281}