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