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