gtk4/auto/svg.rs
1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{SvgFeatures, SymbolicPaintable, ffi};
6use glib::{
7 object::ObjectType as _,
8 prelude::*,
9 signal::{SignalHandlerId, connect_raw},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 /// A paintable implementation that renders SVG, with animations.
16 ///
17 /// [`Svg`][crate::Svg] objects are created by parsing a subset of SVG,
18 /// including SVG animations.
19 ///
20 /// [`Svg`][crate::Svg] fills or strokes paths with symbolic or fixed colors.
21 /// It can have multiple states, and paths can be included in a subset
22 /// of the states. States can have animations, and the transition
23 /// between different states can also be animated.
24 ///
25 /// To show a static SVG image, it is enough to load the
26 /// the SVG and use it like any other paintable.
27 ///
28 /// To play an SVG animation, use [`set_frame_clock()`][Self::set_frame_clock()]
29 /// to connect the paintable to a frame clock, and call
30 /// [`play()`][Self::play()] after loading the SVG. The animation can
31 /// be paused using [`pause()`][Self::pause()].
32 ///
33 /// To set the current state, use [`set_state()`][Self::set_state()].
34 ///
35 ///
36 /// ## Error handling
37 ///
38 /// Loading an SVG into [`Svg`][crate::Svg] will always produce a (possibly empty)
39 /// paintable. GTK will drop things that it can't handle and try to make
40 /// sense of the rest.
41 ///
42 /// To track errors during parsing or rendering, connect to the
43 /// [`error`][struct@crate::Svg#error] signal.
44 ///
45 /// For parsing errors in the `GTK_SVG_ERROR` domain, the functions
46 /// `Gtk::SvgError::get_start()`, `Gtk::SvgError::get_end()`,
47 /// [`SvgError::element()`][crate::SvgError::element()] and [`SvgError::attribute()`][crate::SvgError::attribute()]
48 /// can be used to obtain information about where the error occurred.
49 ///
50 ///
51 /// ## The supported subset of SVG
52 ///
53 /// The paintable supports much of SVG 2, with some exceptions.
54 ///
55 /// Among the graphical elements, `<textPath>` and `<foreignObject>`
56 /// are not supported.
57 ///
58 /// Among the structural elements, `<a>` and `<view>` are not supported.
59 ///
60 /// In the `<filter>` element, the following primitives are not
61 /// supported: feConvolveMatrix, feDiffuseLighting,
62 /// feMorphology, feSpecularLighting and feTurbulence.
63 ///
64 /// Support for the `mask` attribute is limited to just a url
65 /// referring to the `<mask>` element by ID.
66 ///
67 /// In animation elements, the parsing of `begin` and `end` attributes
68 /// is limited, and the `min` and `max` attributes are not supported.
69 ///
70 /// Lastly, there is only minimal CSS support (the style attribute,
71 /// but not `<style>`), and no interactivity.
72 ///
73 ///
74 /// ## SVG Extensions
75 ///
76 /// The paintable supports a number of [custom attributes](icon-format.html)
77 /// that offer a convenient way to define states, transitions and animations.
78 /// For example,
79 ///
80 /// <circle cx='5' cy='5' r='5'
81 /// gpa:states='0 1'
82 /// gpa:animation-type='automatic'
83 /// gpa:animation-direction='segment'
84 /// gpa:animation-duration='600ms'/>
85 ///
86 /// defines the circle to be shown in states 0 and 1, and animates a segment
87 /// of the circle.
88 ///
89 /// <image src="svg-renderer1.svg">
90 ///
91 /// Note that the generated animations are implemented using standard
92 /// SVG attributes (`visibility`, `stroke-dasharray, `stroke-dashoffset`,
93 /// `pathLength` and `filter`). Setting these attributes in your SVG
94 /// is therefore going to interfere with generated animations.
95 ///
96 /// To connect general SVG animations to the states of the paintable,
97 /// use the custom `gpa:states(...)` condition in the `begin` and `end`
98 /// attributes of SVG animation elements. For example,
99 ///
100 /// <animate href='path1'
101 /// attributeName='fill'
102 /// begin='gpa:states(0).begin'
103 /// dur='300ms'
104 /// fill='freeze'
105 /// from='black'
106 /// to='magenta'/>
107 ///
108 /// will make the fill color of path1 transition from black to
109 /// magenta when the renderer enters state 0.
110 ///
111 /// <image src="svg-renderer2.svg">
112 ///
113 /// The `gpa:states(...)` condition triggers for upcoming state changes
114 /// as well, to support fade-out transitions. For example,
115 ///
116 /// <animate href='path1'
117 /// attributeName='opacity'
118 /// begin='gpa:states(0).end -300ms'
119 /// dur='300ms'
120 /// fill='freeze'
121 /// from='1'
122 /// to='0'/>
123 ///
124 /// will start a fade-out of path1 300ms before state 0 ends.
125 ///
126 /// A variant of the `gpa:states(...)` condition allows specifying
127 /// both before and after states:
128 ///
129 /// <animate href='path1'
130 /// attributeName='opacity'
131 /// begin='gpa:states(0, 1 2)'
132 /// dur='300ms'
133 /// fill='freeze'
134 /// from='1'
135 /// to='0'/>
136 ///
137 /// will start the animation when the state changes from 0 to 1 or
138 /// from 0 to 2, but not when it changes from 0 to 3.
139 ///
140 /// In addition to the `gpa:fill` and `gpa:stroke` attributes, symbolic
141 /// colors can also be specified as a custom paint server reference,
142 /// like this: `url(#gpa:warning)`. This works in `fill` and `stroke`
143 /// attributes, but also when specifying colors in SVG animation
144 /// attributes like `to` or `values`.
145 ///
146 /// Note that the SVG syntax allows for a fallback RGB color to be
147 /// specified after the url, for compatibility with other SVG consumers:
148 ///
149 /// fill='url(#gpa:warning) orange'
150 ///
151 /// In contrast to SVG 1.1 and 2.0, we allow the `transform` attribute
152 /// to be animated with `<animate>`.
153 ///
154 /// ## Properties
155 ///
156 ///
157 /// #### `features`
158 /// Enabled features for this paintable.
159 ///
160 /// Note that features have to be set before
161 /// loading SVG data to take effect.
162 ///
163 /// Readable | Writeable
164 ///
165 ///
166 /// #### `playing`
167 /// Whether the paintable is currently animating its content.
168 ///
169 /// To set this property, use the [`Svg::play()`][crate::Svg::play()] and
170 /// [`Svg::pause()`][crate::Svg::pause()] functions.
171 ///
172 /// Readable | Writeable
173 ///
174 ///
175 /// #### `resource`
176 /// Resource to load SVG data from.
177 ///
178 /// This property is meant to create a paintable
179 /// from a resource in ui files.
180 ///
181 /// Readable | Writeable
182 ///
183 ///
184 /// #### `state`
185 /// The current state of the renderer.
186 ///
187 /// This can be a number between 0 and 63.
188 ///
189 /// Readable | Writeable
190 ///
191 ///
192 /// #### `weight`
193 /// If not set to -1, this value overrides the weight used
194 /// when rendering the paintable.
195 ///
196 /// Readable | Writeable
197 ///
198 /// ## Signals
199 ///
200 ///
201 /// #### `error`
202 /// Signals that an error occurred.
203 ///
204 /// Errors can occur both during parsing and during rendering.
205 ///
206 /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
207 /// context information about the location of parsing errors can
208 /// be obtained with the various `gtk_svg_error` functions.
209 ///
210 /// Parsing errors are never fatal, so the parsing will resume after
211 /// the error. Errors may however cause parts of the given data or
212 /// even all of it to not be parsed at all. So it is a useful idea
213 /// to check that the parsing succeeds by connecting to this signal.
214 ///
215 /// ::: note
216 /// This signal is emitted in the middle of parsing or rendering,
217 /// and if you handle it, you must be careful. Logging the errors
218 /// you receive is fine, but modifying the widget hierarchy or
219 /// changing the paintable state definitively isn't.
220 ///
221 /// If in doubt, defer to an idle.
222 ///
223 ///
224 /// <details><summary><h4>Paintable</h4></summary>
225 ///
226 ///
227 /// #### `invalidate-contents`
228 /// Emitted when the contents of the @paintable change.
229 ///
230 /// Examples for such an event would be videos changing to the next frame or
231 /// the icon theme for an icon changing.
232 ///
233 ///
234 ///
235 ///
236 /// #### `invalidate-size`
237 /// Emitted when the intrinsic size of the @paintable changes.
238 ///
239 /// This means the values reported by at least one of
240 /// [`PaintableExtManual::intrinsic_width()`][crate::gdk::prelude::PaintableExtManual::intrinsic_width()],
241 /// [`PaintableExtManual::intrinsic_height()`][crate::gdk::prelude::PaintableExtManual::intrinsic_height()] or
242 /// [`PaintableExtManual::intrinsic_aspect_ratio()`][crate::gdk::prelude::PaintableExtManual::intrinsic_aspect_ratio()]
243 /// has changed.
244 ///
245 /// Examples for such an event would be a paintable displaying
246 /// the contents of a toplevel surface being resized.
247 ///
248 ///
249 /// </details>
250 ///
251 /// # Implements
252 ///
253 /// [`trait@glib::ObjectExt`], [`trait@gdk::prelude::PaintableExt`], [`SymbolicPaintableExt`][trait@crate::prelude::SymbolicPaintableExt]
254 #[doc(alias = "GtkSvg")]
255 pub struct Svg(Object<ffi::GtkSvg, ffi::GtkSvgClass>) @implements gdk::Paintable, SymbolicPaintable;
256
257 match fn {
258 type_ => || ffi::gtk_svg_get_type(),
259 }
260}
261
262impl Svg {
263 /// Creates a new, empty SVG paintable.
264 ///
265 /// # Returns
266 ///
267 /// the paintable
268 #[doc(alias = "gtk_svg_new")]
269 pub fn new() -> Svg {
270 assert_initialized_main_thread!();
271 unsafe { from_glib_full(ffi::gtk_svg_new()) }
272 }
273
274 /// Parses the SVG data in @bytes and creates a paintable.
275 /// ## `bytes`
276 /// the data
277 ///
278 /// # Returns
279 ///
280 /// the paintable
281 #[doc(alias = "gtk_svg_new_from_bytes")]
282 #[doc(alias = "new_from_bytes")]
283 pub fn from_bytes(bytes: &glib::Bytes) -> Svg {
284 assert_initialized_main_thread!();
285 unsafe { from_glib_full(ffi::gtk_svg_new_from_bytes(bytes.to_glib_none().0)) }
286 }
287
288 /// Parses the SVG data in the resource and creates a paintable.
289 /// ## `path`
290 /// the resource path
291 ///
292 /// # Returns
293 ///
294 /// the paintable
295 #[doc(alias = "gtk_svg_new_from_resource")]
296 #[doc(alias = "new_from_resource")]
297 pub fn from_resource(path: &str) -> Svg {
298 assert_initialized_main_thread!();
299 unsafe { from_glib_full(ffi::gtk_svg_new_from_resource(path.to_glib_none().0)) }
300 }
301
302 /// Returns the currently enabled features.
303 ///
304 /// # Returns
305 ///
306 /// the enabled features
307 #[doc(alias = "gtk_svg_get_features")]
308 #[doc(alias = "get_features")]
309 pub fn features(&self) -> SvgFeatures {
310 unsafe { from_glib(ffi::gtk_svg_get_features(self.to_glib_none().0)) }
311 }
312
313 /// Gets the current state of the paintable.
314 ///
315 /// # Returns
316 ///
317 /// the state
318 #[doc(alias = "gtk_svg_get_state")]
319 #[doc(alias = "get_state")]
320 pub fn state(&self) -> u32 {
321 unsafe { ffi::gtk_svg_get_state(self.to_glib_none().0) }
322 }
323
324 /// Returns a `NULL`-terminated array of
325 /// state names, if available.
326 ///
327 /// Note that the returned array and the strings
328 /// contained in it will only be valid until the
329 /// [`Svg`][crate::Svg] is cleared or reloaded, so if you
330 /// want to keep it around, you should make a copy.
331 ///
332 /// # Returns
333 ///
334 /// the state names
335 ///
336 /// ## `length`
337 /// return location for the number
338 /// of strings that are returned
339 #[doc(alias = "gtk_svg_get_state_names")]
340 #[doc(alias = "get_state_names")]
341 pub fn state_names(&self) -> (Vec<glib::GString>, u32) {
342 unsafe {
343 let mut length = std::mem::MaybeUninit::uninit();
344 let ret = FromGlibPtrContainer::from_glib_none(ffi::gtk_svg_get_state_names(
345 self.to_glib_none().0,
346 length.as_mut_ptr(),
347 ));
348 (ret, length.assume_init())
349 }
350 }
351
352 /// Gets the value of the weight property.
353 ///
354 /// # Returns
355 ///
356 /// the weight
357 #[doc(alias = "gtk_svg_get_weight")]
358 #[doc(alias = "get_weight")]
359 pub fn weight(&self) -> f64 {
360 unsafe { ffi::gtk_svg_get_weight(self.to_glib_none().0) }
361 }
362
363 /// Loads SVG content into an existing SVG paintable.
364 ///
365 /// To track errors while loading SVG content,
366 /// connect to the [`error`][struct@crate::Svg#error] signal.
367 ///
368 /// This clears any previously loaded content.
369 /// ## `bytes`
370 /// the data to load
371 #[doc(alias = "gtk_svg_load_from_bytes")]
372 pub fn load_from_bytes(&self, bytes: &glib::Bytes) {
373 unsafe {
374 ffi::gtk_svg_load_from_bytes(self.to_glib_none().0, bytes.to_glib_none().0);
375 }
376 }
377
378 /// Loads SVG content into an existing SVG paintable.
379 ///
380 /// To track errors while loading SVG content,
381 /// connect to the [`error`][struct@crate::Svg#error] signal.
382 ///
383 /// This clears any previously loaded content.
384 /// ## `path`
385 /// the resource path
386 #[doc(alias = "gtk_svg_load_from_resource")]
387 pub fn load_from_resource(&self, path: &str) {
388 unsafe {
389 ffi::gtk_svg_load_from_resource(self.to_glib_none().0, path.to_glib_none().0);
390 }
391 }
392
393 /// Stop any playing animations and state transitions.
394 ///
395 /// Animations can be paused and started repeatedly.
396 #[doc(alias = "gtk_svg_pause")]
397 pub fn pause(&self) {
398 unsafe {
399 ffi::gtk_svg_pause(self.to_glib_none().0);
400 }
401 }
402
403 /// Start playing animations and state transitions.
404 ///
405 /// Animations can be paused and started repeatedly.
406 #[doc(alias = "gtk_svg_play")]
407 pub fn play(&self) {
408 unsafe {
409 ffi::gtk_svg_play(self.to_glib_none().0);
410 }
411 }
412
413 /// Serializes the content of the renderer as SVG.
414 ///
415 /// The SVG will be similar to the orignally loaded one,
416 /// but is not guaranteed to be 100% identical.
417 ///
418 /// This function serializes the DOM, i.e. the results
419 /// of parsing the SVG. It does not reflect the effect
420 /// of applying animations.
421 ///
422 /// # Returns
423 ///
424 /// the serialized contents
425 #[doc(alias = "gtk_svg_serialize")]
426 pub fn serialize(&self) -> glib::Bytes {
427 unsafe { from_glib_full(ffi::gtk_svg_serialize(self.to_glib_none().0)) }
428 }
429
430 /// Enables or disables features of the SVG paintable.
431 ///
432 /// By default, all features are enabled.
433 ///
434 /// Note that this call only has an effect before the
435 /// SVG is loaded.
436 /// ## `features`
437 /// features to enable
438 #[doc(alias = "gtk_svg_set_features")]
439 #[doc(alias = "features")]
440 pub fn set_features(&self, features: SvgFeatures) {
441 unsafe {
442 ffi::gtk_svg_set_features(self.to_glib_none().0, features.into_glib());
443 }
444 }
445
446 /// Sets a frame clock.
447 ///
448 /// Without a frame clock, GtkSvg will not advance animations.
449 /// ## `clock`
450 /// the frame clock
451 #[doc(alias = "gtk_svg_set_frame_clock")]
452 pub fn set_frame_clock(&self, clock: &gdk::FrameClock) {
453 unsafe {
454 ffi::gtk_svg_set_frame_clock(self.to_glib_none().0, clock.to_glib_none().0);
455 }
456 }
457
458 /// Sets the state of the paintable.
459 ///
460 /// If the paintable is currently playing, the state change
461 /// will apply transitions that are defined in the SVG. If
462 /// the paintable is not playing, the state change will take
463 /// effect instantaneously.
464 /// ## `state`
465 /// the state to set, as a value between 0 and 63
466 #[doc(alias = "gtk_svg_set_state")]
467 #[doc(alias = "state")]
468 pub fn set_state(&self, state: u32) {
469 unsafe {
470 ffi::gtk_svg_set_state(self.to_glib_none().0, state);
471 }
472 }
473
474 /// Sets the weight that is used when rendering.
475 ///
476 /// The weight affects the effective linewidth when stroking
477 /// paths.
478 ///
479 /// The default value of -1 means to use the font weight
480 /// from CSS.
481 /// ## `weight`
482 /// the font weight, as a value between -1 and 1000
483 #[doc(alias = "gtk_svg_set_weight")]
484 #[doc(alias = "weight")]
485 pub fn set_weight(&self, weight: f64) {
486 unsafe {
487 ffi::gtk_svg_set_weight(self.to_glib_none().0, weight);
488 }
489 }
490
491 /// Serializes the paintable, and saves the result to a file.
492 /// ## `filename`
493 /// the file to save to
494 ///
495 /// # Returns
496 ///
497 /// true, unless an error occurred
498 #[doc(alias = "gtk_svg_write_to_file")]
499 pub fn write_to_file(&self, filename: &str) -> Result<(), glib::Error> {
500 unsafe {
501 let mut error = std::ptr::null_mut();
502 let is_ok = ffi::gtk_svg_write_to_file(
503 self.to_glib_none().0,
504 filename.to_glib_none().0,
505 &mut error,
506 );
507 debug_assert_eq!(is_ok == glib::ffi::GFALSE, !error.is_null());
508 if error.is_null() {
509 Ok(())
510 } else {
511 Err(from_glib_full(error))
512 }
513 }
514 }
515
516 /// Whether the paintable is currently animating its content.
517 ///
518 /// To set this property, use the [`play()`][Self::play()] and
519 /// [`pause()`][Self::pause()] functions.
520 #[cfg(feature = "v4_22")]
521 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
522 pub fn is_playing(&self) -> bool {
523 ObjectExt::property(self, "playing")
524 }
525
526 /// Whether the paintable is currently animating its content.
527 ///
528 /// To set this property, use the [`play()`][Self::play()] and
529 /// [`pause()`][Self::pause()] functions.
530 #[cfg(feature = "v4_22")]
531 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
532 pub fn set_playing(&self, playing: bool) {
533 ObjectExt::set_property(self, "playing", playing)
534 }
535
536 /// Resource to load SVG data from.
537 ///
538 /// This property is meant to create a paintable
539 /// from a resource in ui files.
540 #[cfg(feature = "v4_22")]
541 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
542 pub fn resource(&self) -> Option<glib::GString> {
543 ObjectExt::property(self, "resource")
544 }
545
546 /// Resource to load SVG data from.
547 ///
548 /// This property is meant to create a paintable
549 /// from a resource in ui files.
550 #[cfg(feature = "v4_22")]
551 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
552 pub fn set_resource(&self, resource: Option<&str>) {
553 ObjectExt::set_property(self, "resource", resource)
554 }
555
556 /// Signals that an error occurred.
557 ///
558 /// Errors can occur both during parsing and during rendering.
559 ///
560 /// The expected error values are in the [`SvgError`][crate::SvgError] enumeration,
561 /// context information about the location of parsing errors can
562 /// be obtained with the various `gtk_svg_error` functions.
563 ///
564 /// Parsing errors are never fatal, so the parsing will resume after
565 /// the error. Errors may however cause parts of the given data or
566 /// even all of it to not be parsed at all. So it is a useful idea
567 /// to check that the parsing succeeds by connecting to this signal.
568 ///
569 /// ::: note
570 /// This signal is emitted in the middle of parsing or rendering,
571 /// and if you handle it, you must be careful. Logging the errors
572 /// you receive is fine, but modifying the widget hierarchy or
573 /// changing the paintable state definitively isn't.
574 ///
575 /// If in doubt, defer to an idle.
576 /// ## `error`
577 /// the error
578 #[cfg(feature = "v4_22")]
579 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
580 #[doc(alias = "error")]
581 pub fn connect_error<F: Fn(&Self, &glib::Error) + 'static>(&self, f: F) -> SignalHandlerId {
582 unsafe extern "C" fn error_trampoline<F: Fn(&Svg, &glib::Error) + 'static>(
583 this: *mut ffi::GtkSvg,
584 error: *mut glib::ffi::GError,
585 f: glib::ffi::gpointer,
586 ) {
587 unsafe {
588 let f: &F = &*(f as *const F);
589 f(&from_glib_borrow(this), &from_glib_borrow(error))
590 }
591 }
592 unsafe {
593 let f: Box_<F> = Box_::new(f);
594 connect_raw(
595 self.as_ptr() as *mut _,
596 c"error".as_ptr(),
597 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
598 error_trampoline::<F> as *const (),
599 )),
600 Box_::into_raw(f),
601 )
602 }
603 }
604
605 #[cfg(feature = "v4_22")]
606 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
607 #[doc(alias = "features")]
608 pub fn connect_features_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
609 unsafe extern "C" fn notify_features_trampoline<F: Fn(&Svg) + 'static>(
610 this: *mut ffi::GtkSvg,
611 _param_spec: glib::ffi::gpointer,
612 f: glib::ffi::gpointer,
613 ) {
614 unsafe {
615 let f: &F = &*(f as *const F);
616 f(&from_glib_borrow(this))
617 }
618 }
619 unsafe {
620 let f: Box_<F> = Box_::new(f);
621 connect_raw(
622 self.as_ptr() as *mut _,
623 c"notify::features".as_ptr(),
624 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
625 notify_features_trampoline::<F> as *const (),
626 )),
627 Box_::into_raw(f),
628 )
629 }
630 }
631
632 #[cfg(feature = "v4_22")]
633 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
634 #[doc(alias = "playing")]
635 pub fn connect_playing_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
636 unsafe extern "C" fn notify_playing_trampoline<F: Fn(&Svg) + 'static>(
637 this: *mut ffi::GtkSvg,
638 _param_spec: glib::ffi::gpointer,
639 f: glib::ffi::gpointer,
640 ) {
641 unsafe {
642 let f: &F = &*(f as *const F);
643 f(&from_glib_borrow(this))
644 }
645 }
646 unsafe {
647 let f: Box_<F> = Box_::new(f);
648 connect_raw(
649 self.as_ptr() as *mut _,
650 c"notify::playing".as_ptr(),
651 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
652 notify_playing_trampoline::<F> as *const (),
653 )),
654 Box_::into_raw(f),
655 )
656 }
657 }
658
659 #[cfg(feature = "v4_22")]
660 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
661 #[doc(alias = "resource")]
662 pub fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
663 unsafe extern "C" fn notify_resource_trampoline<F: Fn(&Svg) + 'static>(
664 this: *mut ffi::GtkSvg,
665 _param_spec: glib::ffi::gpointer,
666 f: glib::ffi::gpointer,
667 ) {
668 unsafe {
669 let f: &F = &*(f as *const F);
670 f(&from_glib_borrow(this))
671 }
672 }
673 unsafe {
674 let f: Box_<F> = Box_::new(f);
675 connect_raw(
676 self.as_ptr() as *mut _,
677 c"notify::resource".as_ptr(),
678 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
679 notify_resource_trampoline::<F> as *const (),
680 )),
681 Box_::into_raw(f),
682 )
683 }
684 }
685
686 #[cfg(feature = "v4_22")]
687 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
688 #[doc(alias = "state")]
689 pub fn connect_state_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
690 unsafe extern "C" fn notify_state_trampoline<F: Fn(&Svg) + 'static>(
691 this: *mut ffi::GtkSvg,
692 _param_spec: glib::ffi::gpointer,
693 f: glib::ffi::gpointer,
694 ) {
695 unsafe {
696 let f: &F = &*(f as *const F);
697 f(&from_glib_borrow(this))
698 }
699 }
700 unsafe {
701 let f: Box_<F> = Box_::new(f);
702 connect_raw(
703 self.as_ptr() as *mut _,
704 c"notify::state".as_ptr(),
705 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
706 notify_state_trampoline::<F> as *const (),
707 )),
708 Box_::into_raw(f),
709 )
710 }
711 }
712
713 #[cfg(feature = "v4_22")]
714 #[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
715 #[doc(alias = "weight")]
716 pub fn connect_weight_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
717 unsafe extern "C" fn notify_weight_trampoline<F: Fn(&Svg) + 'static>(
718 this: *mut ffi::GtkSvg,
719 _param_spec: glib::ffi::gpointer,
720 f: glib::ffi::gpointer,
721 ) {
722 unsafe {
723 let f: &F = &*(f as *const F);
724 f(&from_glib_borrow(this))
725 }
726 }
727 unsafe {
728 let f: Box_<F> = Box_::new(f);
729 connect_raw(
730 self.as_ptr() as *mut _,
731 c"notify::weight".as_ptr(),
732 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
733 notify_weight_trampoline::<F> as *const (),
734 )),
735 Box_::into_raw(f),
736 )
737 }
738 }
739}
740
741#[cfg(feature = "v4_22")]
742#[cfg_attr(docsrs, doc(cfg(feature = "v4_22")))]
743impl Default for Svg {
744 fn default() -> Self {
745 Self::new()
746 }
747}