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