Skip to content

Commit 16cf7ee

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 modifying the glib::wrapper macro.
1 parent 54be5cb commit 16cf7ee

File tree

3 files changed

+265
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)