Skip to main content

gtk/auto/
cell_area_context.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;
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem, mem::transmute};
12
13glib::wrapper! {
14    /// The [`CellAreaContext`][crate::CellAreaContext] object is created by a given [`CellArea`][crate::CellArea]
15    /// implementation via its `GtkCellAreaClass.create_context()` virtual
16    /// method and is used to store cell sizes and alignments for a series of
17    /// [`TreeModel`][crate::TreeModel] rows that are requested and rendered in the same context.
18    ///
19    /// [`CellLayout`][crate::CellLayout] widgets can create any number of contexts in which to
20    /// request and render groups of data rows. However, it’s important that the
21    /// same context which was used to request sizes for a given [`TreeModel`][crate::TreeModel]
22    /// row also be used for the same row when calling other [`CellArea`][crate::CellArea] APIs
23    /// such as [`CellAreaExt::render()`][crate::prelude::CellAreaExt::render()] and [`CellAreaExt::event()`][crate::prelude::CellAreaExt::event()].
24    ///
25    /// ## Properties
26    ///
27    ///
28    /// #### `area`
29    ///  The [`CellArea`][crate::CellArea] this context was created by
30    ///
31    /// Readable | Writeable | Construct Only
32    ///
33    ///
34    /// #### `minimum-height`
35    ///  The minimum height for the [`CellArea`][crate::CellArea] in this context
36    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
37    /// for using [`CellAreaExt::preferred_height()`][crate::prelude::CellAreaExt::preferred_height()].
38    ///
39    /// Readable
40    ///
41    ///
42    /// #### `minimum-width`
43    ///  The minimum width for the [`CellArea`][crate::CellArea] in this context
44    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
45    /// for using [`CellAreaExt::preferred_width()`][crate::prelude::CellAreaExt::preferred_width()].
46    ///
47    /// Readable
48    ///
49    ///
50    /// #### `natural-height`
51    ///  The natural height for the [`CellArea`][crate::CellArea] in this context
52    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
53    /// for using [`CellAreaExt::preferred_height()`][crate::prelude::CellAreaExt::preferred_height()].
54    ///
55    /// Readable
56    ///
57    ///
58    /// #### `natural-width`
59    ///  The natural width for the [`CellArea`][crate::CellArea] in this context
60    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
61    /// for using [`CellAreaExt::preferred_width()`][crate::prelude::CellAreaExt::preferred_width()].
62    ///
63    /// Readable
64    ///
65    /// # Implements
66    ///
67    /// [`CellAreaContextExt`][trait@crate::prelude::CellAreaContextExt], [`trait@glib::ObjectExt`]
68    #[doc(alias = "GtkCellAreaContext")]
69    pub struct CellAreaContext(Object<ffi::GtkCellAreaContext, ffi::GtkCellAreaContextClass>);
70
71    match fn {
72        type_ => || ffi::gtk_cell_area_context_get_type(),
73    }
74}
75
76impl CellAreaContext {
77    pub const NONE: Option<&'static CellAreaContext> = None;
78}
79
80mod sealed {
81    pub trait Sealed {}
82    impl<T: super::IsA<super::CellAreaContext>> Sealed for T {}
83}
84
85/// Trait containing all [`struct@CellAreaContext`] methods.
86///
87/// # Implementors
88///
89/// [`CellAreaContext`][struct@crate::CellAreaContext]
90pub trait CellAreaContextExt: IsA<CellAreaContext> + sealed::Sealed + 'static {
91    /// Allocates a width and/or a height for all rows which are to be
92    /// rendered with `self`.
93    ///
94    /// Usually allocation is performed only horizontally or sometimes
95    /// vertically since a group of rows are usually rendered side by
96    /// side vertically or horizontally and share either the same width
97    /// or the same height. Sometimes they are allocated in both horizontal
98    /// and vertical orientations producing a homogeneous effect of the
99    /// rows. This is generally the case for [`TreeView`][crate::TreeView] when
100    /// [`fixed-height-mode`][struct@crate::TreeView#fixed-height-mode] is enabled.
101    ///
102    /// Since 3.0
103    /// ## `width`
104    /// the allocated width for all [`TreeModel`][crate::TreeModel] rows rendered
105    ///  with `self`, or -1.
106    /// ## `height`
107    /// the allocated height for all [`TreeModel`][crate::TreeModel] rows rendered
108    ///  with `self`, or -1.
109    #[doc(alias = "gtk_cell_area_context_allocate")]
110    fn allocate(&self, width: i32, height: i32) {
111        unsafe {
112            ffi::gtk_cell_area_context_allocate(self.as_ref().to_glib_none().0, width, height);
113        }
114    }
115
116    /// Fetches the current allocation size for `self`.
117    ///
118    /// If the context was not allocated in width or height, or if the
119    /// context was recently reset with [`reset()`][Self::reset()],
120    /// the returned value will be -1.
121    ///
122    /// # Returns
123    ///
124    ///
125    /// ## `width`
126    /// location to store the allocated width, or [`None`]
127    ///
128    /// ## `height`
129    /// location to store the allocated height, or [`None`]
130    #[doc(alias = "gtk_cell_area_context_get_allocation")]
131    #[doc(alias = "get_allocation")]
132    fn allocation(&self) -> (i32, i32) {
133        unsafe {
134            let mut width = mem::MaybeUninit::uninit();
135            let mut height = mem::MaybeUninit::uninit();
136            ffi::gtk_cell_area_context_get_allocation(
137                self.as_ref().to_glib_none().0,
138                width.as_mut_ptr(),
139                height.as_mut_ptr(),
140            );
141            (width.assume_init(), height.assume_init())
142        }
143    }
144
145    /// Fetches the [`CellArea`][crate::CellArea] this `self` was created by.
146    ///
147    /// This is generally unneeded by layouting widgets; however,
148    /// it is important for the context implementation itself to
149    /// fetch information about the area it is being used for.
150    ///
151    /// For instance at `GtkCellAreaContextClass.allocate()` time
152    /// it’s important to know details about any cell spacing
153    /// that the [`CellArea`][crate::CellArea] is configured with in order to
154    /// compute a proper allocation.
155    ///
156    /// # Returns
157    ///
158    /// the [`CellArea`][crate::CellArea] this context was created by.
159    #[doc(alias = "gtk_cell_area_context_get_area")]
160    #[doc(alias = "get_area")]
161    fn area(&self) -> Option<CellArea> {
162        unsafe {
163            from_glib_none(ffi::gtk_cell_area_context_get_area(
164                self.as_ref().to_glib_none().0,
165            ))
166        }
167    }
168
169    /// Gets the accumulative preferred height for all rows which have been
170    /// requested with this context.
171    ///
172    /// After [`reset()`][Self::reset()] is called and/or before ever
173    /// requesting the size of a [`CellArea`][crate::CellArea], the returned values are 0.
174    ///
175    /// # Returns
176    ///
177    ///
178    /// ## `minimum_height`
179    /// location to store the minimum height,
180    ///  or [`None`]
181    ///
182    /// ## `natural_height`
183    /// location to store the natural height,
184    ///  or [`None`]
185    #[doc(alias = "gtk_cell_area_context_get_preferred_height")]
186    #[doc(alias = "get_preferred_height")]
187    fn preferred_height(&self) -> (i32, i32) {
188        unsafe {
189            let mut minimum_height = mem::MaybeUninit::uninit();
190            let mut natural_height = mem::MaybeUninit::uninit();
191            ffi::gtk_cell_area_context_get_preferred_height(
192                self.as_ref().to_glib_none().0,
193                minimum_height.as_mut_ptr(),
194                natural_height.as_mut_ptr(),
195            );
196            (minimum_height.assume_init(), natural_height.assume_init())
197        }
198    }
199
200    /// Gets the accumulative preferred height for `width` for all rows
201    /// which have been requested for the same said `width` with this context.
202    ///
203    /// After [`reset()`][Self::reset()] is called and/or before ever
204    /// requesting the size of a [`CellArea`][crate::CellArea], the returned values are -1.
205    /// ## `width`
206    /// a proposed width for allocation
207    ///
208    /// # Returns
209    ///
210    ///
211    /// ## `minimum_height`
212    /// location to store the minimum height,
213    ///  or [`None`]
214    ///
215    /// ## `natural_height`
216    /// location to store the natural height,
217    ///  or [`None`]
218    #[doc(alias = "gtk_cell_area_context_get_preferred_height_for_width")]
219    #[doc(alias = "get_preferred_height_for_width")]
220    fn preferred_height_for_width(&self, width: i32) -> (i32, i32) {
221        unsafe {
222            let mut minimum_height = mem::MaybeUninit::uninit();
223            let mut natural_height = mem::MaybeUninit::uninit();
224            ffi::gtk_cell_area_context_get_preferred_height_for_width(
225                self.as_ref().to_glib_none().0,
226                width,
227                minimum_height.as_mut_ptr(),
228                natural_height.as_mut_ptr(),
229            );
230            (minimum_height.assume_init(), natural_height.assume_init())
231        }
232    }
233
234    /// Gets the accumulative preferred width for all rows which have been
235    /// requested with this context.
236    ///
237    /// After [`reset()`][Self::reset()] is called and/or before ever
238    /// requesting the size of a [`CellArea`][crate::CellArea], the returned values are 0.
239    ///
240    /// # Returns
241    ///
242    ///
243    /// ## `minimum_width`
244    /// location to store the minimum width,
245    ///  or [`None`]
246    ///
247    /// ## `natural_width`
248    /// location to store the natural width,
249    ///  or [`None`]
250    #[doc(alias = "gtk_cell_area_context_get_preferred_width")]
251    #[doc(alias = "get_preferred_width")]
252    fn preferred_width(&self) -> (i32, i32) {
253        unsafe {
254            let mut minimum_width = mem::MaybeUninit::uninit();
255            let mut natural_width = mem::MaybeUninit::uninit();
256            ffi::gtk_cell_area_context_get_preferred_width(
257                self.as_ref().to_glib_none().0,
258                minimum_width.as_mut_ptr(),
259                natural_width.as_mut_ptr(),
260            );
261            (minimum_width.assume_init(), natural_width.assume_init())
262        }
263    }
264
265    /// Gets the accumulative preferred width for `height` for all rows which
266    /// have been requested for the same said `height` with this context.
267    ///
268    /// After [`reset()`][Self::reset()] is called and/or before ever
269    /// requesting the size of a [`CellArea`][crate::CellArea], the returned values are -1.
270    /// ## `height`
271    /// a proposed height for allocation
272    ///
273    /// # Returns
274    ///
275    ///
276    /// ## `minimum_width`
277    /// location to store the minimum width,
278    ///  or [`None`]
279    ///
280    /// ## `natural_width`
281    /// location to store the natural width,
282    ///  or [`None`]
283    #[doc(alias = "gtk_cell_area_context_get_preferred_width_for_height")]
284    #[doc(alias = "get_preferred_width_for_height")]
285    fn preferred_width_for_height(&self, height: i32) -> (i32, i32) {
286        unsafe {
287            let mut minimum_width = mem::MaybeUninit::uninit();
288            let mut natural_width = mem::MaybeUninit::uninit();
289            ffi::gtk_cell_area_context_get_preferred_width_for_height(
290                self.as_ref().to_glib_none().0,
291                height,
292                minimum_width.as_mut_ptr(),
293                natural_width.as_mut_ptr(),
294            );
295            (minimum_width.assume_init(), natural_width.assume_init())
296        }
297    }
298
299    /// Causes the minimum and/or natural height to grow if the new
300    /// proposed sizes exceed the current minimum and natural height.
301    ///
302    /// This is used by [`CellAreaContext`][crate::CellAreaContext] implementations during
303    /// the request process over a series of [`TreeModel`][crate::TreeModel] rows to
304    /// progressively push the requested height over a series of
305    /// [`CellAreaExt::preferred_height()`][crate::prelude::CellAreaExt::preferred_height()] requests.
306    /// ## `minimum_height`
307    /// the proposed new minimum height for `self`
308    /// ## `natural_height`
309    /// the proposed new natural height for `self`
310    #[doc(alias = "gtk_cell_area_context_push_preferred_height")]
311    fn push_preferred_height(&self, minimum_height: i32, natural_height: i32) {
312        unsafe {
313            ffi::gtk_cell_area_context_push_preferred_height(
314                self.as_ref().to_glib_none().0,
315                minimum_height,
316                natural_height,
317            );
318        }
319    }
320
321    /// Causes the minimum and/or natural width to grow if the new
322    /// proposed sizes exceed the current minimum and natural width.
323    ///
324    /// This is used by [`CellAreaContext`][crate::CellAreaContext] implementations during
325    /// the request process over a series of [`TreeModel`][crate::TreeModel] rows to
326    /// progressively push the requested width over a series of
327    /// [`CellAreaExt::preferred_width()`][crate::prelude::CellAreaExt::preferred_width()] requests.
328    /// ## `minimum_width`
329    /// the proposed new minimum width for `self`
330    /// ## `natural_width`
331    /// the proposed new natural width for `self`
332    #[doc(alias = "gtk_cell_area_context_push_preferred_width")]
333    fn push_preferred_width(&self, minimum_width: i32, natural_width: i32) {
334        unsafe {
335            ffi::gtk_cell_area_context_push_preferred_width(
336                self.as_ref().to_glib_none().0,
337                minimum_width,
338                natural_width,
339            );
340        }
341    }
342
343    /// Resets any previously cached request and allocation
344    /// data.
345    ///
346    /// When underlying [`TreeModel`][crate::TreeModel] data changes its
347    /// important to reset the context if the content
348    /// size is allowed to shrink. If the content size
349    /// is only allowed to grow (this is usually an option
350    /// for views rendering large data stores as a measure
351    /// of optimization), then only the row that changed
352    /// or was inserted needs to be (re)requested with
353    /// [`CellAreaExt::preferred_width()`][crate::prelude::CellAreaExt::preferred_width()].
354    ///
355    /// When the new overall size of the context requires
356    /// that the allocated size changes (or whenever this
357    /// allocation changes at all), the variable row
358    /// sizes need to be re-requested for every row.
359    ///
360    /// For instance, if the rows are displayed all with
361    /// the same width from top to bottom then a change
362    /// in the allocated width necessitates a recalculation
363    /// of all the displayed row heights using
364    /// [`CellAreaExt::preferred_height_for_width()`][crate::prelude::CellAreaExt::preferred_height_for_width()].
365    ///
366    /// Since 3.0
367    #[doc(alias = "gtk_cell_area_context_reset")]
368    fn reset(&self) {
369        unsafe {
370            ffi::gtk_cell_area_context_reset(self.as_ref().to_glib_none().0);
371        }
372    }
373
374    /// The minimum height for the [`CellArea`][crate::CellArea] in this context
375    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
376    /// for using [`CellAreaExt::preferred_height()`][crate::prelude::CellAreaExt::preferred_height()].
377    #[doc(alias = "minimum-height")]
378    fn minimum_height(&self) -> i32 {
379        ObjectExt::property(self.as_ref(), "minimum-height")
380    }
381
382    /// The minimum width for the [`CellArea`][crate::CellArea] in this context
383    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
384    /// for using [`CellAreaExt::preferred_width()`][crate::prelude::CellAreaExt::preferred_width()].
385    #[doc(alias = "minimum-width")]
386    fn minimum_width(&self) -> i32 {
387        ObjectExt::property(self.as_ref(), "minimum-width")
388    }
389
390    /// The natural height for the [`CellArea`][crate::CellArea] in this context
391    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
392    /// for using [`CellAreaExt::preferred_height()`][crate::prelude::CellAreaExt::preferred_height()].
393    #[doc(alias = "natural-height")]
394    fn natural_height(&self) -> i32 {
395        ObjectExt::property(self.as_ref(), "natural-height")
396    }
397
398    /// The natural width for the [`CellArea`][crate::CellArea] in this context
399    /// for all [`TreeModel`][crate::TreeModel] rows that this context was requested
400    /// for using [`CellAreaExt::preferred_width()`][crate::prelude::CellAreaExt::preferred_width()].
401    #[doc(alias = "natural-width")]
402    fn natural_width(&self) -> i32 {
403        ObjectExt::property(self.as_ref(), "natural-width")
404    }
405
406    #[doc(alias = "minimum-height")]
407    fn connect_minimum_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
408        unsafe extern "C" fn notify_minimum_height_trampoline<
409            P: IsA<CellAreaContext>,
410            F: Fn(&P) + 'static,
411        >(
412            this: *mut ffi::GtkCellAreaContext,
413            _param_spec: glib::ffi::gpointer,
414            f: glib::ffi::gpointer,
415        ) {
416            let f: &F = &*(f as *const F);
417            f(CellAreaContext::from_glib_borrow(this).unsafe_cast_ref())
418        }
419        unsafe {
420            let f: Box_<F> = Box_::new(f);
421            connect_raw(
422                self.as_ptr() as *mut _,
423                b"notify::minimum-height\0".as_ptr() as *const _,
424                Some(transmute::<_, unsafe extern "C" fn()>(
425                    notify_minimum_height_trampoline::<Self, F> as *const (),
426                )),
427                Box_::into_raw(f),
428            )
429        }
430    }
431
432    #[doc(alias = "minimum-width")]
433    fn connect_minimum_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
434        unsafe extern "C" fn notify_minimum_width_trampoline<
435            P: IsA<CellAreaContext>,
436            F: Fn(&P) + 'static,
437        >(
438            this: *mut ffi::GtkCellAreaContext,
439            _param_spec: glib::ffi::gpointer,
440            f: glib::ffi::gpointer,
441        ) {
442            let f: &F = &*(f as *const F);
443            f(CellAreaContext::from_glib_borrow(this).unsafe_cast_ref())
444        }
445        unsafe {
446            let f: Box_<F> = Box_::new(f);
447            connect_raw(
448                self.as_ptr() as *mut _,
449                b"notify::minimum-width\0".as_ptr() as *const _,
450                Some(transmute::<_, unsafe extern "C" fn()>(
451                    notify_minimum_width_trampoline::<Self, F> as *const (),
452                )),
453                Box_::into_raw(f),
454            )
455        }
456    }
457
458    #[doc(alias = "natural-height")]
459    fn connect_natural_height_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
460        unsafe extern "C" fn notify_natural_height_trampoline<
461            P: IsA<CellAreaContext>,
462            F: Fn(&P) + 'static,
463        >(
464            this: *mut ffi::GtkCellAreaContext,
465            _param_spec: glib::ffi::gpointer,
466            f: glib::ffi::gpointer,
467        ) {
468            let f: &F = &*(f as *const F);
469            f(CellAreaContext::from_glib_borrow(this).unsafe_cast_ref())
470        }
471        unsafe {
472            let f: Box_<F> = Box_::new(f);
473            connect_raw(
474                self.as_ptr() as *mut _,
475                b"notify::natural-height\0".as_ptr() as *const _,
476                Some(transmute::<_, unsafe extern "C" fn()>(
477                    notify_natural_height_trampoline::<Self, F> as *const (),
478                )),
479                Box_::into_raw(f),
480            )
481        }
482    }
483
484    #[doc(alias = "natural-width")]
485    fn connect_natural_width_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
486        unsafe extern "C" fn notify_natural_width_trampoline<
487            P: IsA<CellAreaContext>,
488            F: Fn(&P) + 'static,
489        >(
490            this: *mut ffi::GtkCellAreaContext,
491            _param_spec: glib::ffi::gpointer,
492            f: glib::ffi::gpointer,
493        ) {
494            let f: &F = &*(f as *const F);
495            f(CellAreaContext::from_glib_borrow(this).unsafe_cast_ref())
496        }
497        unsafe {
498            let f: Box_<F> = Box_::new(f);
499            connect_raw(
500                self.as_ptr() as *mut _,
501                b"notify::natural-width\0".as_ptr() as *const _,
502                Some(transmute::<_, unsafe extern "C" fn()>(
503                    notify_natural_width_trampoline::<Self, F> as *const (),
504                )),
505                Box_::into_raw(f),
506            )
507        }
508    }
509}
510
511impl<O: IsA<CellAreaContext>> CellAreaContextExt for O {}
512
513impl fmt::Display for CellAreaContext {
514    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
515        f.write_str("CellAreaContext")
516    }
517}