Skip to content

Commit 831a94b

Browse files
gtk: Add SymbolicPaintable.snapshot_with_weight vfunc support
1 parent d53f4d8 commit 831a94b

File tree

1 file changed

+77
-1
lines changed

1 file changed

+77
-1
lines changed

gtk4/src/subclass/symbolic_paintable.rs

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ pub trait SymbolicPaintableImpl:
1919
) {
2020
self.parent_snapshot_symbolic(snapshot, width, height, colors)
2121
}
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+
}
2235
}
2336

2437
pub trait SymbolicPaintableImplExt: SymbolicPaintableImpl {
@@ -43,8 +56,39 @@ pub trait SymbolicPaintableImplExt: SymbolicPaintableImpl {
4356
snapshot.to_glib_none().0,
4457
width,
4558
height,
46-
colors.to_glib_none().0,
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,
4790
colors.len() as _,
91+
weight,
4892
)
4993
}
5094
}
@@ -59,6 +103,10 @@ unsafe impl<T: SymbolicPaintableImpl> IsImplementable<T> for SymbolicPaintable {
59103
assert_initialized_main_thread!();
60104

61105
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+
}
62110
}
63111
}
64112

@@ -86,3 +134,31 @@ unsafe extern "C" fn symbolic_paintable_snapshot_symbolic<T: SymbolicPaintableIm
86134
},
87135
)
88136
}
137+
138+
#[cfg(feature = "v4_22")]
139+
unsafe 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+
}

0 commit comments

Comments
 (0)