gtk4/subclass/flow_box_child.rs
1// Take a look at the license at the top of the repository in the LICENSE file.
2
3// rustdoc-stripper-ignore-next
4//! Traits intended for subclassing [`FlowBoxChild`](crate::FlowBoxChild).
5
6use glib::translate::*;
7
8use crate::{ffi, prelude::*, subclass::prelude::*, FlowBoxChild};
9
10pub trait FlowBoxChildImpl: FlowBoxChildImplExt + WidgetImpl {
11 fn activate(&self) {
12 self.parent_activate()
13 }
14}
15
16mod sealed {
17 pub trait Sealed {}
18 impl<T: super::FlowBoxChildImplExt> Sealed for T {}
19}
20
21pub trait FlowBoxChildImplExt: sealed::Sealed + ObjectSubclass {
22 fn parent_activate(&self) {
23 unsafe {
24 let data = Self::type_data();
25 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkFlowBoxChildClass;
26 if let Some(f) = (*parent_class).activate {
27 f(self
28 .obj()
29 .unsafe_cast_ref::<FlowBoxChild>()
30 .to_glib_none()
31 .0)
32 }
33 }
34 }
35}
36
37impl<T: FlowBoxChildImpl> FlowBoxChildImplExt for T {}
38
39unsafe impl<T: FlowBoxChildImpl> IsSubclassable<T> for FlowBoxChild {
40 fn class_init(class: &mut glib::Class<Self>) {
41 Self::parent_class_init::<T>(class);
42
43 let klass = class.as_mut();
44 klass.activate = Some(child_activate::<T>);
45 }
46}
47
48unsafe extern "C" fn child_activate<T: FlowBoxChildImpl>(ptr: *mut ffi::GtkFlowBoxChild) {
49 let instance = &*(ptr as *mut T::Instance);
50 let imp = instance.imp();
51
52 imp.activate()
53}