Skip to content

Commit 13e5bfa

Browse files
committed
Add gsk::RenderReplay bindings manually
Generated by temporarily adding glib:get-type to the gir file, moving he generated file to src and replacing the glib::wrapper macro with `struct` and `impl Drop`. We also replace `mut self` with `self` in function arguments.
1 parent 5ba4629 commit 13e5bfa

File tree

3 files changed

+269
-0
lines changed

3 files changed

+269
-0
lines changed

gsk4/Gir.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ status = "generate"
230230
name = "cr"
231231
const = true
232232

233+
[[object]]
234+
name = "Gsk.RenderReplay"
235+
status = "manual"
236+
233237
[[object]]
234238
name = "Gsk.RoundedRect"
235239
status = "manual"

gsk4/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ mod path_builder;
8484
#[cfg_attr(docsrs, doc(cfg(feature = "v4_14")))]
8585
mod path_point;
8686
mod radial_gradient_node;
87+
#[cfg(feature = "v4_22")]
88+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
89+
mod render_replay;
8790
mod repeat_node;
8891
mod repeating_linear_gradient_node;
8992
mod repeating_radial_gradient_node;
@@ -109,5 +112,8 @@ pub use color_stop::ColorStop;
109112
#[cfg_attr(feature = "v4_4", deprecated = "Since 4.4")]
110113
pub use ngl_renderer::NglRenderer;
111114
pub use parse_location::ParseLocation;
115+
#[cfg(feature = "v4_22")]
116+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
117+
pub use render_replay::RenderReplay;
112118
pub use rounded_rect::RoundedRect;
113119
pub use shadow::Shadow;

gsk4/src/render_replay.rs

Lines changed: 259 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,259 @@
1+
// Take a look at the license at the top of the repository in the LICENSE file.
2+
3+
use crate::{ffi, RenderNode};
4+
use glib::{prelude::*, translate::*};
5+
use std::boxed::Box as Box_;
6+
7+
#[repr(C)]
8+
pub struct RenderReplay(std::ptr::NonNull<ffi::GskRenderPlay>);
9+
10+
impl Drop for RenderReplay {
11+
fn drop(&mut self) {
12+
unsafe {
13+
ffi::gsk_render_replay_free(self.ptr.as_ptr());
14+
}
15+
}
16+
}
17+
18+
impl RenderReplay {
19+
#[doc(alias = "gsk_render_replay_default")]
20+
#[allow(clippy::should_implement_trait)]
21+
pub fn default(&self, node: impl AsRef<RenderNode>) -> Option<RenderNode> {
22+
unsafe {
23+
from_glib_full(ffi::gsk_render_replay_default(
24+
self.to_glib_none_mut().0,
25+
node.as_ref().to_glib_none().0,
26+
))
27+
}
28+
}
29+
30+
#[doc(alias = "gsk_render_replay_filter_font")]
31+
pub fn filter_font(&self, font: &impl IsA<pango::Font>) -> pango::Font {
32+
unsafe {
33+
from_glib_full(ffi::gsk_render_replay_filter_font(
34+
self.to_glib_none_mut().0,
35+
font.as_ref().to_glib_none().0,
36+
))
37+
}
38+
}
39+
40+
#[doc(alias = "gsk_render_replay_filter_node")]
41+
pub fn filter_node(&self, node: impl AsRef<RenderNode>) -> Option<RenderNode> {
42+
unsafe {
43+
from_glib_full(ffi::gsk_render_replay_filter_node(
44+
self.to_glib_none_mut().0,
45+
node.as_ref().to_glib_none().0,
46+
))
47+
}
48+
}
49+
50+
#[doc(alias = "gsk_render_replay_filter_texture")]
51+
pub fn filter_texture(&self, texture: &impl IsA<gdk::Texture>) -> gdk::Texture {
52+
unsafe {
53+
from_glib_full(ffi::gsk_render_replay_filter_texture(
54+
self.to_glib_none_mut().0,
55+
texture.as_ref().to_glib_none().0,
56+
))
57+
}
58+
}
59+
60+
#[doc(alias = "gsk_render_replay_foreach_node")]
61+
pub fn foreach_node(&self, node: impl AsRef<RenderNode>) {
62+
unsafe {
63+
ffi::gsk_render_replay_foreach_node(
64+
self.to_glib_none_mut().0,
65+
node.as_ref().to_glib_none().0,
66+
);
67+
}
68+
}
69+
70+
#[doc(alias = "gsk_render_replay_set_font_filter")]
71+
pub fn set_font_filter(
72+
&self,
73+
filter: Option<Box_<dyn Fn(&RenderReplay, &pango::Font) -> pango::Font + 'static>>,
74+
) {
75+
let filter_data: Box_<
76+
Option<Box_<dyn Fn(&RenderReplay, &pango::Font) -> pango::Font + 'static>>,
77+
> = Box_::new(filter);
78+
unsafe extern "C" fn filter_func(
79+
replay: *mut ffi::GskRenderReplay,
80+
font: *mut pango::ffi::PangoFont,
81+
user_data: glib::ffi::gpointer,
82+
) -> *mut pango::ffi::PangoFont {
83+
let replay = from_glib_borrow(replay);
84+
let font = from_glib_borrow(font);
85+
let callback = &*(user_data
86+
as *mut Option<Box_<dyn Fn(&RenderReplay, &pango::Font) -> pango::Font + 'static>>);
87+
if let Some(ref callback) = *callback {
88+
callback(&replay, &font)
89+
} else {
90+
panic!("cannot get closure...")
91+
}
92+
.to_glib_full()
93+
}
94+
let filter = if filter_data.is_some() {
95+
Some(filter_func as _)
96+
} else {
97+
None
98+
};
99+
unsafe extern "C" fn user_destroy_func(data: glib::ffi::gpointer) {
100+
let _callback = Box_::from_raw(
101+
data as *mut Option<
102+
Box_<dyn Fn(&RenderReplay, &pango::Font) -> pango::Font + 'static>,
103+
>,
104+
);
105+
}
106+
let destroy_call3 = Some(user_destroy_func as _);
107+
let super_callback0: Box_<
108+
Option<Box_<dyn Fn(&RenderReplay, &pango::Font) -> pango::Font + 'static>>,
109+
> = filter_data;
110+
unsafe {
111+
ffi::gsk_render_replay_set_font_filter(
112+
self.to_glib_none_mut().0,
113+
filter,
114+
Box_::into_raw(super_callback0) as *mut _,
115+
destroy_call3,
116+
);
117+
}
118+
}
119+
120+
#[doc(alias = "gsk_render_replay_set_node_filter")]
121+
pub fn set_node_filter<P: Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static>(
122+
&self,
123+
filter: P,
124+
) {
125+
let filter_data: Box_<P> = Box_::new(filter);
126+
unsafe extern "C" fn filter_func<
127+
P: Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static,
128+
>(
129+
replay: *mut ffi::GskRenderReplay,
130+
node: *mut ffi::GskRenderNode,
131+
user_data: glib::ffi::gpointer,
132+
) -> *mut ffi::GskRenderNode {
133+
let replay = from_glib_borrow(replay);
134+
let node = from_glib_borrow(node);
135+
let callback = &*(user_data as *mut P);
136+
(*callback)(&replay, &node).to_glib_full()
137+
}
138+
let filter = Some(filter_func::<P> as _);
139+
unsafe extern "C" fn user_destroy_func<
140+
P: Fn(&RenderReplay, &RenderNode) -> Option<RenderNode> + 'static,
141+
>(
142+
data: glib::ffi::gpointer,
143+
) {
144+
let _callback = Box_::from_raw(data as *mut P);
145+
}
146+
let destroy_call3 = Some(user_destroy_func::<P> as _);
147+
let super_callback0: Box_<P> = filter_data;
148+
unsafe {
149+
ffi::gsk_render_replay_set_node_filter(
150+
self.to_glib_none_mut().0,
151+
filter,
152+
Box_::into_raw(super_callback0) as *mut _,
153+
destroy_call3,
154+
);
155+
}
156+
}
157+
158+
#[doc(alias = "gsk_render_replay_set_node_foreach")]
159+
pub fn set_node_foreach<P: Fn(&RenderReplay, &RenderNode) -> bool + 'static>(
160+
&self,
161+
foreach: P,
162+
) {
163+
let foreach_data: Box_<P> = Box_::new(foreach);
164+
unsafe extern "C" fn foreach_func<P: Fn(&RenderReplay, &RenderNode) -> bool + 'static>(
165+
replay: *mut ffi::GskRenderReplay,
166+
node: *mut ffi::GskRenderNode,
167+
user_data: glib::ffi::gpointer,
168+
) -> glib::ffi::gboolean {
169+
let replay = from_glib_borrow(replay);
170+
let node = from_glib_borrow(node);
171+
let callback = &*(user_data as *mut P);
172+
(*callback)(&replay, &node).into_glib()
173+
}
174+
let foreach = Some(foreach_func::<P> as _);
175+
unsafe extern "C" fn user_destroy_func<
176+
P: Fn(&RenderReplay, &RenderNode) -> bool + 'static,
177+
>(
178+
data: glib::ffi::gpointer,
179+
) {
180+
let _callback = Box_::from_raw(data as *mut P);
181+
}
182+
let destroy_call3 = Some(user_destroy_func::<P> as _);
183+
let super_callback0: Box_<P> = foreach_data;
184+
unsafe {
185+
ffi::gsk_render_replay_set_node_foreach(
186+
self.to_glib_none_mut().0,
187+
foreach,
188+
Box_::into_raw(super_callback0) as *mut _,
189+
destroy_call3,
190+
);
191+
}
192+
}
193+
194+
#[doc(alias = "gsk_render_replay_set_texture_filter")]
195+
pub fn set_texture_filter(
196+
&self,
197+
filter: Option<Box_<dyn Fn(&RenderReplay, &gdk::Texture) -> gdk::Texture + 'static>>,
198+
) {
199+
let filter_data: Box_<
200+
Option<Box_<dyn Fn(&RenderReplay, &gdk::Texture) -> gdk::Texture + 'static>>,
201+
> = Box_::new(filter);
202+
unsafe extern "C" fn filter_func(
203+
replay: *mut ffi::GskRenderReplay,
204+
texture: *mut gdk::ffi::GdkTexture,
205+
user_data: glib::ffi::gpointer,
206+
) -> *mut gdk::ffi::GdkTexture {
207+
let replay = from_glib_borrow(replay);
208+
let texture = from_glib_borrow(texture);
209+
let callback = &*(user_data
210+
as *mut Option<
211+
Box_<dyn Fn(&RenderReplay, &gdk::Texture) -> gdk::Texture + 'static>,
212+
>);
213+
if let Some(ref callback) = *callback {
214+
callback(&replay, &texture)
215+
} else {
216+
panic!("cannot get closure...")
217+
}
218+
.to_glib_full()
219+
}
220+
let filter = if filter_data.is_some() {
221+
Some(filter_func as _)
222+
} else {
223+
None
224+
};
225+
unsafe extern "C" fn user_destroy_func(data: glib::ffi::gpointer) {
226+
let _callback = Box_::from_raw(
227+
data as *mut Option<
228+
Box_<dyn Fn(&RenderReplay, &gdk::Texture) -> gdk::Texture + 'static>,
229+
>,
230+
);
231+
}
232+
let destroy_call3 = Some(user_destroy_func as _);
233+
let super_callback0: Box_<
234+
Option<Box_<dyn Fn(&RenderReplay, &gdk::Texture) -> gdk::Texture + 'static>>,
235+
> = filter_data;
236+
unsafe {
237+
ffi::gsk_render_replay_set_texture_filter(
238+
self.to_glib_none_mut().0,
239+
filter,
240+
Box_::into_raw(super_callback0) as *mut _,
241+
destroy_call3,
242+
);
243+
}
244+
}
245+
246+
#[doc(alias = "gsk_render_replay_new")]
247+
pub fn new() -> RenderReplay {
248+
assert_initialized_main_thread!();
249+
unsafe { from_glib_none(ffi::gsk_render_replay_new()) }
250+
}
251+
}
252+
253+
#[cfg(feature = "v4_22")]
254+
#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
255+
impl Default for RenderReplay {
256+
fn default() -> Self {
257+
Self::new()
258+
}
259+
}

0 commit comments

Comments
 (0)