gtk4/subclass/
symbolic_paintable.rs1use glib::translate::*;
7
8use crate::{ffi, prelude::*, subclass::prelude::*, SymbolicPaintable};
9
10pub trait SymbolicPaintableImpl:
11 PaintableImpl + ObjectSubclass<Type: IsA<SymbolicPaintable>>
12{
13 fn snapshot_symbolic(
14 &self,
15 snapshot: &gdk::Snapshot,
16 width: f64,
17 height: f64,
18 colors: &[gdk::RGBA],
19 ) {
20 self.parent_snapshot_symbolic(snapshot, width, height, colors)
21 }
22
23 #[cfg(feature = "v4_22")]
24 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
25 fn snapshot_with_weight(
26 &self,
27 snapshot: &gdk::Snapshot,
28 width: f64,
29 height: f64,
30 colors: &[gdk::RGBA],
31 weight: f64,
32 ) {
33 self.parent_snapshot_with_weight(snapshot, width, height, colors, weight)
34 }
35}
36
37pub trait SymbolicPaintableImplExt: SymbolicPaintableImpl {
38 fn parent_snapshot_symbolic(
39 &self,
40 snapshot: &gdk::Snapshot,
41 width: f64,
42 height: f64,
43 colors: &[gdk::RGBA],
44 ) {
45 unsafe {
46 let type_data = Self::type_data();
47 let parent_iface = type_data.as_ref().parent_interface::<SymbolicPaintable>()
48 as *const ffi::GtkSymbolicPaintableInterface;
49
50 let func = (*parent_iface).snapshot_symbolic.unwrap();
51 func(
52 self.obj()
53 .unsafe_cast_ref::<SymbolicPaintable>()
54 .to_glib_none()
55 .0,
56 snapshot.to_glib_none().0,
57 width,
58 height,
59 colors.as_ptr() as *const gdk::ffi::GdkRGBA,
60 colors.len() as _,
61 )
62 }
63 }
64
65 #[cfg(feature = "v4_22")]
66 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
67 fn parent_snapshot_with_weight(
68 &self,
69 snapshot: &gdk::Snapshot,
70 width: f64,
71 height: f64,
72 colors: &[gdk::RGBA],
73 weight: f64,
74 ) {
75 unsafe {
76 let type_data = Self::type_data();
77 let parent_iface = type_data.as_ref().parent_interface::<SymbolicPaintable>()
78 as *const ffi::GtkSymbolicPaintableInterface;
79
80 let func = (*parent_iface).snapshot_with_weight.unwrap();
81 func(
82 self.obj()
83 .unsafe_cast_ref::<SymbolicPaintable>()
84 .to_glib_none()
85 .0,
86 snapshot.to_glib_none().0,
87 width,
88 height,
89 colors.as_ptr() as *const gdk::ffi::GdkRGBA,
90 colors.len() as _,
91 weight,
92 )
93 }
94 }
95}
96
97impl<T: SymbolicPaintableImpl> SymbolicPaintableImplExt for T {}
98
99unsafe impl<T: SymbolicPaintableImpl> IsImplementable<T> for SymbolicPaintable {
100 fn interface_init(iface: &mut glib::Interface<Self>) {
101 let iface = iface.as_mut();
102
103 assert_initialized_main_thread!();
104
105 iface.snapshot_symbolic = Some(symbolic_paintable_snapshot_symbolic::<T>);
106 #[cfg(feature = "v4_22")]
107 {
108 iface.snapshot_with_weight = Some(symbolic_paintable_snapshot_with_weight::<T>);
109 }
110 }
111}
112
113unsafe extern "C" fn symbolic_paintable_snapshot_symbolic<T: SymbolicPaintableImpl>(
114 paintable: *mut ffi::GtkSymbolicPaintable,
115 snapshotptr: *mut gdk::ffi::GdkSnapshot,
116 width: f64,
117 height: f64,
118 colors: *const gdk::ffi::GdkRGBA,
119 n_colors: usize,
120) {
121 let instance = &*(paintable as *mut T::Instance);
122 let imp = instance.imp();
123
124 let snapshot: Borrowed<gdk::Snapshot> = from_glib_borrow(snapshotptr);
125
126 imp.snapshot_symbolic(
127 &snapshot,
128 width,
129 height,
130 if n_colors == 0 {
131 &[]
132 } else {
133 std::slice::from_raw_parts(colors as *const gdk::RGBA, n_colors)
134 },
135 )
136}
137
138#[cfg(feature = "v4_22")]
139unsafe extern "C" fn symbolic_paintable_snapshot_with_weight<T: SymbolicPaintableImpl>(
140 paintable: *mut ffi::GtkSymbolicPaintable,
141 snapshotptr: *mut gdk::ffi::GdkSnapshot,
142 width: f64,
143 height: f64,
144 colors: *const gdk::ffi::GdkRGBA,
145 n_colors: usize,
146 weight: f64,
147) {
148 let instance = &*(paintable as *mut T::Instance);
149 let imp = instance.imp();
150
151 let snapshot: Borrowed<gdk::Snapshot> = from_glib_borrow(snapshotptr);
152
153 imp.snapshot_with_weight(
154 &snapshot,
155 width,
156 height,
157 if n_colors == 0 {
158 &[]
159 } else {
160 std::slice::from_raw_parts(colors as *const gdk::RGBA, n_colors)
161 },
162 weight,
163 )
164}