gtk4/subclass/
frame.rs
1use glib::translate::*;
7
8use crate::{ffi, prelude::*, subclass::prelude::*, Allocation, Frame};
9
10#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
11#[allow(deprecated)]
12pub trait FrameImpl: FrameImplExt + WidgetImpl {
13 fn compute_child_allocation(&self) -> Allocation {
14 self.parent_compute_child_allocation()
15 }
16}
17
18#[cfg_attr(feature = "v4_10", deprecated = "Since 4.10")]
19#[allow(deprecated)]
20pub trait FrameImplExt: ObjectSubclass {
21 fn parent_compute_child_allocation(&self) -> Allocation {
22 unsafe {
23 let data = Self::type_data();
24 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkFrameClass;
25 let f = (*parent_class)
26 .compute_child_allocation
27 .expect("No parent class impl for \"compute_child_allocation\"");
28 let mut allocation = Allocation::uninitialized();
29 f(
30 self.obj().unsafe_cast_ref::<Frame>().to_glib_none().0,
31 allocation.to_glib_none_mut().0,
32 );
33 allocation
34 }
35 }
36}
37
38impl<T: FrameImpl> FrameImplExt for T {}
39
40unsafe impl<T: FrameImpl> IsSubclassable<T> for Frame {
41 fn class_init(class: &mut glib::Class<Self>) {
42 Self::parent_class_init::<T>(class);
43
44 let klass = class.as_mut();
45 klass.compute_child_allocation = Some(frame_compute_child_allocation::<T>);
46 }
47}
48
49unsafe extern "C" fn frame_compute_child_allocation<T: FrameImpl>(
50 ptr: *mut ffi::GtkFrame,
51 allocationptr: *mut ffi::GtkAllocation,
52) {
53 let instance = &*(ptr as *mut T::Instance);
54 let imp = instance.imp();
55
56 let allocation = imp.compute_child_allocation();
57 *allocationptr = *allocation.to_glib_none().0;
58}