gtk4/subclass/
drawing_area.rs
1use glib::translate::*;
7
8use crate::{ffi, prelude::*, subclass::prelude::*, DrawingArea};
9
10pub trait DrawingAreaImpl: DrawingAreaImplExt + WidgetImpl {
11 fn resize(&self, width: i32, height: i32) {
12 self.parent_resize(width, height)
13 }
14}
15
16mod sealed {
17 pub trait Sealed {}
18 impl<T: super::DrawingAreaImplExt> Sealed for T {}
19}
20pub trait DrawingAreaImplExt: sealed::Sealed + ObjectSubclass {
21 fn parent_resize(&self, width: i32, height: i32) {
22 unsafe {
23 let data = Self::type_data();
24 let parent_class = data.as_ref().parent_class() as *mut ffi::GtkDrawingAreaClass;
25 if let Some(f) = (*parent_class).resize {
26 f(
27 self.obj().unsafe_cast_ref::<DrawingArea>().to_glib_none().0,
28 width,
29 height,
30 )
31 }
32 }
33 }
34}
35
36impl<T: DrawingAreaImpl> DrawingAreaImplExt for T {}
37
38unsafe impl<T: DrawingAreaImpl> IsSubclassable<T> for DrawingArea {
39 fn class_init(class: &mut glib::Class<Self>) {
40 Self::parent_class_init::<T>(class);
41
42 let klass = class.as_mut();
43 klass.resize = Some(drawing_area_resize::<T>);
44 }
45}
46
47unsafe extern "C" fn drawing_area_resize<T: DrawingAreaImpl>(
48 ptr: *mut ffi::GtkDrawingArea,
49 width: i32,
50 height: i32,
51) {
52 let instance = &*(ptr as *mut T::Instance);
53 let imp = instance.imp();
54
55 imp.resize(width, height)
56}