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`].
5
6use glib::translate::*;
7
8use crate::{ffi, prelude::*, subclass::prelude::*, FlowBoxChild};
9
10pub trait FlowBoxChildImpl: WidgetImpl + ObjectSubclass<Type: IsA<FlowBoxChild>> {
11 fn activate(&self) {
12 self.parent_activate()
13 }
14}
15
16pub trait FlowBoxChildImplExt: FlowBoxChildImpl {
17 fn parent_activate(&self) {
18 unsafe {
19 let data = Self::type_data();
20 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkFlowBoxChildClass;
21 if let Some(f) = (*parent_class).activate {
22 f(self
23 .obj()
24 .unsafe_cast_ref::<FlowBoxChild>()
25 .to_glib_none()
26 .0)
27 }
28 }
29 }
30}
31
32impl<T: FlowBoxChildImpl> FlowBoxChildImplExt for T {}
33
34unsafe impl<T: FlowBoxChildImpl> IsSubclassable<T> for FlowBoxChild {
35 fn class_init(class: &mut glib::Class<Self>) {
36 Self::parent_class_init::<T>(class);
37
38 let klass = class.as_mut();
39 klass.activate = Some(child_activate::<T>);
40 }
41}
42
43unsafe extern "C" fn child_activate<T: FlowBoxChildImpl>(ptr: *mut ffi::GtkFlowBoxChild) {
44 let instance = &*(ptr as *mut T::Instance);
45 let imp = instance.imp();
46
47 imp.activate()
48}