Skip to main content

gtk/auto/
image.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::{Buildable, IconSize, ImageType, Misc, Widget, ffi};
6use glib::{
7    prelude::*,
8    signal::{SignalHandlerId, connect_raw},
9    translate::*,
10};
11use std::boxed::Box as Box_;
12
13glib::wrapper! {
14    /// The [`Image`][crate::Image] widget displays an image. Various kinds of object
15    /// can be displayed as an image; most typically, you would load a
16    /// [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] ("pixel buffer") from a file, and then display that.
17    /// There’s a convenience function to do this, [`from_file()`][Self::from_file()],
18    /// used as follows:
19    ///
20    ///
21    /// **⚠️ The following code is in C ⚠️**
22    ///
23    /// ```C
24    ///   GtkWidget *image;
25    ///   image = gtk_image_new_from_file ("myfile.png");
26    /// ```
27    /// If the file isn’t loaded successfully, the image will contain a
28    /// “broken image” icon similar to that used in many web browsers.
29    /// If you want to handle errors in loading the file yourself,
30    /// for example by displaying an error message, then load the image with
31    /// [`gdk_pixbuf::Pixbuf::from_file()`][crate::gdk_pixbuf::Pixbuf::from_file()], then create the [`Image`][crate::Image] with
32    /// [`from_pixbuf()`][Self::from_pixbuf()].
33    ///
34    /// The image file may contain an animation, if so the [`Image`][crate::Image] will
35    /// display an animation ([`gdk_pixbuf::PixbufAnimation`][crate::gdk_pixbuf::PixbufAnimation]) instead of a static image.
36    ///
37    /// [`Image`][crate::Image] is a subclass of [`Misc`][crate::Misc], which implies that you can
38    /// align it (center, left, right) and add padding to it, using
39    /// [`Misc`][crate::Misc] methods.
40    ///
41    /// [`Image`][crate::Image] is a “no window” widget (has no [`gdk::Window`][crate::gdk::Window] of its own),
42    /// so by default does not receive events. If you want to receive events
43    /// on the image, such as button clicks, place the image inside a
44    /// [`EventBox`][crate::EventBox], then connect to the event signals on the event box.
45    ///
46    /// ## Handling button press events on a [`Image`][crate::Image].
47    ///
48    ///
49    ///
50    /// **⚠️ The following code is in C ⚠️**
51    ///
52    /// ```C
53    ///   static gboolean
54    ///   button_press_callback (GtkWidget      *event_box,
55    ///                          GdkEventButton *event,
56    ///                          gpointer        data)
57    ///   {
58    ///     g_print ("Event box clicked at coordinates %f,%f\n",
59    ///              event->x, event->y);
60    ///
61    ///     // Returning TRUE means we handled the event, so the signal
62    ///     // emission should be stopped (don’t call any further callbacks
63    ///     // that may be connected). Return FALSE to continue invoking callbacks.
64    ///     return TRUE;
65    ///   }
66    ///
67    ///   static GtkWidget*
68    ///   create_image (void)
69    ///   {
70    ///     GtkWidget *image;
71    ///     GtkWidget *event_box;
72    ///
73    ///     image = gtk_image_new_from_file ("myfile.png");
74    ///
75    ///     event_box = gtk_event_box_new ();
76    ///
77    ///     gtk_container_add (GTK_CONTAINER (event_box), image);
78    ///
79    ///     g_signal_connect (G_OBJECT (event_box),
80    ///                       "button_press_event",
81    ///                       G_CALLBACK (button_press_callback),
82    ///                       image);
83    ///
84    ///     return image;
85    ///   }
86    /// ```
87    ///
88    /// When handling events on the event box, keep in mind that coordinates
89    /// in the image may be different from event box coordinates due to
90    /// the alignment and padding settings on the image (see [`Misc`][crate::Misc]).
91    /// The simplest way to solve this is to set the alignment to 0.0
92    /// (left/top), and set the padding to zero. Then the origin of
93    /// the image will be the same as the origin of the event box.
94    ///
95    /// Sometimes an application will want to avoid depending on external data
96    /// files, such as image files. GTK+ comes with a program to avoid this,
97    /// called “gdk-pixbuf-csource”. This library
98    /// allows you to convert an image into a C variable declaration, which
99    /// can then be loaded into a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] using
100    /// `gdk_pixbuf_new_from_inline()`.
101    ///
102    /// # CSS nodes
103    ///
104    /// GtkImage has a single CSS node with the name image. The style classes
105    /// may appear on image CSS nodes: .icon-dropshadow, .lowres-icon.
106    ///
107    /// ## Properties
108    ///
109    ///
110    /// #### `file`
111    ///  Readable | Writable
112    ///
113    ///
114    /// #### `gicon`
115    ///  The GIcon displayed in the GtkImage. For themed icons,
116    /// If the icon theme is changed, the image will be updated
117    /// automatically.
118    ///
119    /// Readable | Writable
120    ///
121    ///
122    /// #### `icon-name`
123    ///  The name of the icon in the icon theme. If the icon theme is
124    /// changed, the image will be updated automatically.
125    ///
126    /// Readable | Writable
127    ///
128    ///
129    /// #### `icon-set`
130    ///  Readable | Writable
131    ///
132    ///
133    /// #### `icon-size`
134    ///  Readable | Writable
135    ///
136    ///
137    /// #### `pixbuf`
138    ///  Readable | Writable
139    ///
140    ///
141    /// #### `pixbuf-animation`
142    ///  Readable | Writable
143    ///
144    ///
145    /// #### `pixel-size`
146    ///  The "pixel-size" property can be used to specify a fixed size
147    /// overriding the [`icon-size`][struct@crate::Image#icon-size] property for images of type
148    /// [`ImageType::IconName`][crate::ImageType::IconName].
149    ///
150    /// Readable | Writable
151    ///
152    ///
153    /// #### `resource`
154    ///  A path to a resource file to display.
155    ///
156    /// Readable | Writable
157    ///
158    ///
159    /// #### `stock`
160    ///  Readable | Writable
161    ///
162    ///
163    /// #### `storage-type`
164    ///  Readable
165    ///
166    ///
167    /// #### `surface`
168    ///  Readable | Writable
169    ///
170    ///
171    /// #### `use-fallback`
172    ///  Whether the icon displayed in the GtkImage will use
173    /// standard icon names fallback. The value of this property
174    /// is only relevant for images of type [`ImageType::IconName`][crate::ImageType::IconName]
175    /// and [`ImageType::Gicon`][crate::ImageType::Gicon].
176    ///
177    /// Readable | Writable
178    /// <details><summary><h4>Misc</h4></summary>
179    ///
180    ///
181    /// #### `xalign`
182    ///  The horizontal alignment. A value of 0.0 means left alignment (or right
183    /// on RTL locales); a value of 1.0 means right alignment (or left on RTL
184    /// locales).
185    ///
186    /// Readable | Writable
187    ///
188    ///
189    /// #### `xpad`
190    ///  The amount of space to add on the left and right of the widget, in
191    /// pixels.
192    ///
193    /// Readable | Writable
194    ///
195    ///
196    /// #### `yalign`
197    ///  The vertical alignment. A value of 0.0 means top alignment;
198    /// a value of 1.0 means bottom alignment.
199    ///
200    /// Readable | Writable
201    ///
202    ///
203    /// #### `ypad`
204    ///  The amount of space to add on the top and bottom of the widget, in
205    /// pixels.
206    ///
207    /// Readable | Writable
208    /// </details>
209    /// <details><summary><h4>Widget</h4></summary>
210    ///
211    ///
212    /// #### `app-paintable`
213    ///  Readable | Writable
214    ///
215    ///
216    /// #### `can-default`
217    ///  Readable | Writable
218    ///
219    ///
220    /// #### `can-focus`
221    ///  Readable | Writable
222    ///
223    ///
224    /// #### `composite-child`
225    ///  Readable
226    ///
227    ///
228    /// #### `double-buffered`
229    ///  Whether the widget is double buffered.
230    ///
231    /// Readable | Writable
232    ///
233    ///
234    /// #### `events`
235    ///  Readable | Writable
236    ///
237    ///
238    /// #### `expand`
239    ///  Whether to expand in both directions. Setting this sets both [`hexpand`][struct@crate::Widget#hexpand] and [`vexpand`][struct@crate::Widget#vexpand]
240    ///
241    /// Readable | Writable
242    ///
243    ///
244    /// #### `focus-on-click`
245    ///  Whether the widget should grab focus when it is clicked with the mouse.
246    ///
247    /// This property is only relevant for widgets that can take focus.
248    ///
249    /// Before 3.20, several widgets (GtkButton, GtkFileChooserButton,
250    /// GtkComboBox) implemented this property individually.
251    ///
252    /// Readable | Writable
253    ///
254    ///
255    /// #### `halign`
256    ///  How to distribute horizontal space if widget gets extra space, see [`Align`][crate::Align]
257    ///
258    /// Readable | Writable
259    ///
260    ///
261    /// #### `has-default`
262    ///  Readable | Writable
263    ///
264    ///
265    /// #### `has-focus`
266    ///  Readable | Writable
267    ///
268    ///
269    /// #### `has-tooltip`
270    ///  Enables or disables the emission of [`query-tooltip`][struct@crate::Widget#query-tooltip] on `widget`.
271    /// A value of [`true`] indicates that `widget` can have a tooltip, in this case
272    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to determine
273    /// whether it will provide a tooltip or not.
274    ///
275    /// Note that setting this property to [`true`] for the first time will change
276    /// the event masks of the GdkWindows of this widget to include leave-notify
277    /// and motion-notify events. This cannot and will not be undone when the
278    /// property is set to [`false`] again.
279    ///
280    /// Readable | Writable
281    ///
282    ///
283    /// #### `height-request`
284    ///  Readable | Writable
285    ///
286    ///
287    /// #### `hexpand`
288    ///  Whether to expand horizontally. See [`WidgetExt::set_hexpand()`][crate::prelude::WidgetExt::set_hexpand()].
289    ///
290    /// Readable | Writable
291    ///
292    ///
293    /// #### `hexpand-set`
294    ///  Whether to use the [`hexpand`][struct@crate::Widget#hexpand] property. See [`WidgetExt::is_hexpand_set()`][crate::prelude::WidgetExt::is_hexpand_set()].
295    ///
296    /// Readable | Writable
297    ///
298    ///
299    /// #### `is-focus`
300    ///  Readable | Writable
301    ///
302    ///
303    /// #### `margin`
304    ///  Sets all four sides' margin at once. If read, returns max
305    /// margin on any side.
306    ///
307    /// Readable | Writable
308    ///
309    ///
310    /// #### `margin-bottom`
311    ///  Margin on bottom side of widget.
312    ///
313    /// This property adds margin outside of the widget's normal size
314    /// request, the margin will be added in addition to the size from
315    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
316    ///
317    /// Readable | Writable
318    ///
319    ///
320    /// #### `margin-end`
321    ///  Margin on end of widget, horizontally. This property supports
322    /// left-to-right and right-to-left text directions.
323    ///
324    /// This property adds margin outside of the widget's normal size
325    /// request, the margin will be added in addition to the size from
326    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
327    ///
328    /// Readable | Writable
329    ///
330    ///
331    /// #### `margin-left`
332    ///  Margin on left side of widget.
333    ///
334    /// This property adds margin outside of the widget's normal size
335    /// request, the margin will be added in addition to the size from
336    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
337    ///
338    /// Readable | Writable
339    ///
340    ///
341    /// #### `margin-right`
342    ///  Margin on right side of widget.
343    ///
344    /// This property adds margin outside of the widget's normal size
345    /// request, the margin will be added in addition to the size from
346    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
347    ///
348    /// Readable | Writable
349    ///
350    ///
351    /// #### `margin-start`
352    ///  Margin on start of widget, horizontally. This property supports
353    /// left-to-right and right-to-left text directions.
354    ///
355    /// This property adds margin outside of the widget's normal size
356    /// request, the margin will be added in addition to the size from
357    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
358    ///
359    /// Readable | Writable
360    ///
361    ///
362    /// #### `margin-top`
363    ///  Margin on top side of widget.
364    ///
365    /// This property adds margin outside of the widget's normal size
366    /// request, the margin will be added in addition to the size from
367    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
368    ///
369    /// Readable | Writable
370    ///
371    ///
372    /// #### `name`
373    ///  Readable | Writable
374    ///
375    ///
376    /// #### `no-show-all`
377    ///  Readable | Writable
378    ///
379    ///
380    /// #### `opacity`
381    ///  The requested opacity of the widget. See [`WidgetExt::set_opacity()`][crate::prelude::WidgetExt::set_opacity()] for
382    /// more details about window opacity.
383    ///
384    /// Before 3.8 this was only available in GtkWindow
385    ///
386    /// Readable | Writable
387    ///
388    ///
389    /// #### `parent`
390    ///  Readable | Writable
391    ///
392    ///
393    /// #### `receives-default`
394    ///  Readable | Writable
395    ///
396    ///
397    /// #### `scale-factor`
398    ///  The scale factor of the widget. See [`WidgetExt::scale_factor()`][crate::prelude::WidgetExt::scale_factor()] for
399    /// more details about widget scaling.
400    ///
401    /// Readable
402    ///
403    ///
404    /// #### `sensitive`
405    ///  Readable | Writable
406    ///
407    ///
408    /// #### `style`
409    ///  The style of the widget, which contains information about how it will look (colors, etc).
410    ///
411    /// Readable | Writable
412    ///
413    ///
414    /// #### `tooltip-markup`
415    ///  Sets the text of tooltip to be the given string, which is marked up
416    /// with the [Pango text markup language][PangoMarkupFormat].
417    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
418    ///
419    /// This is a convenience property which will take care of getting the
420    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
421    /// will automatically be set to [`true`] and there will be taken care of
422    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
423    ///
424    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
425    /// are set, the last one wins.
426    ///
427    /// Readable | Writable
428    ///
429    ///
430    /// #### `tooltip-text`
431    ///  Sets the text of tooltip to be the given string.
432    ///
433    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
434    ///
435    /// This is a convenience property which will take care of getting the
436    /// tooltip shown if the given string is not [`None`]: [`has-tooltip`][struct@crate::Widget#has-tooltip]
437    /// will automatically be set to [`true`] and there will be taken care of
438    /// [`query-tooltip`][struct@crate::Widget#query-tooltip] in the default signal handler.
439    ///
440    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and [`tooltip-markup`][struct@crate::Widget#tooltip-markup]
441    /// are set, the last one wins.
442    ///
443    /// Readable | Writable
444    ///
445    ///
446    /// #### `valign`
447    ///  How to distribute vertical space if widget gets extra space, see [`Align`][crate::Align]
448    ///
449    /// Readable | Writable
450    ///
451    ///
452    /// #### `vexpand`
453    ///  Whether to expand vertically. See [`WidgetExt::set_vexpand()`][crate::prelude::WidgetExt::set_vexpand()].
454    ///
455    /// Readable | Writable
456    ///
457    ///
458    /// #### `vexpand-set`
459    ///  Whether to use the [`vexpand`][struct@crate::Widget#vexpand] property. See [`WidgetExt::is_vexpand_set()`][crate::prelude::WidgetExt::is_vexpand_set()].
460    ///
461    /// Readable | Writable
462    ///
463    ///
464    /// #### `visible`
465    ///  Readable | Writable
466    ///
467    ///
468    /// #### `width-request`
469    ///  Readable | Writable
470    ///
471    ///
472    /// #### `window`
473    ///  The widget's window if it is realized, [`None`] otherwise.
474    ///
475    /// Readable
476    /// </details>
477    ///
478    /// # Implements
479    ///
480    /// [`ImageExt`][trait@crate::prelude::ImageExt], [`MiscExt`][trait@crate::prelude::MiscExt], [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ImageExtManual`][trait@crate::prelude::ImageExtManual], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`BuildableExtManual`][trait@crate::prelude::BuildableExtManual]
481    #[doc(alias = "GtkImage")]
482    pub struct Image(Object<ffi::GtkImage, ffi::GtkImageClass>) @extends Misc, Widget, @implements Buildable;
483
484    match fn {
485        type_ => || ffi::gtk_image_get_type(),
486    }
487}
488
489impl Image {
490    pub const NONE: Option<&'static Image> = None;
491
492    /// Creates a new empty [`Image`][crate::Image] widget.
493    ///
494    /// # Returns
495    ///
496    /// a newly created [`Image`][crate::Image] widget.
497    #[doc(alias = "gtk_image_new")]
498    pub fn new() -> Image {
499        assert_initialized_main_thread!();
500        unsafe { Widget::from_glib_none(ffi::gtk_image_new()).unsafe_cast() }
501    }
502
503    /// Creates a [`Image`][crate::Image] displaying the given animation.
504    /// The [`Image`][crate::Image] does not assume a reference to the
505    /// animation; you still need to unref it if you own references.
506    /// [`Image`][crate::Image] will add its own reference rather than adopting yours.
507    ///
508    /// Note that the animation frames are shown using a timeout with
509    /// `G_PRIORITY_DEFAULT`. When using animations to indicate busyness,
510    /// keep in mind that the animation will only be shown if the main loop
511    /// is not busy with something that has a higher priority.
512    /// ## `animation`
513    /// an animation
514    ///
515    /// # Returns
516    ///
517    /// a new [`Image`][crate::Image] widget
518    #[doc(alias = "gtk_image_new_from_animation")]
519    #[doc(alias = "new_from_animation")]
520    pub fn from_animation(animation: &impl IsA<gdk_pixbuf::PixbufAnimation>) -> Image {
521        assert_initialized_main_thread!();
522        unsafe {
523            Widget::from_glib_none(ffi::gtk_image_new_from_animation(
524                animation.as_ref().to_glib_none().0,
525            ))
526            .unsafe_cast()
527        }
528    }
529
530    /// Creates a new [`Image`][crate::Image] displaying the file `filename`. If the file
531    /// isn’t found or can’t be loaded, the resulting [`Image`][crate::Image] will
532    /// display a “broken image” icon. This function never returns [`None`],
533    /// it always returns a valid [`Image`][crate::Image] widget.
534    ///
535    /// If the file contains an animation, the image will contain an
536    /// animation.
537    ///
538    /// If you need to detect failures to load the file, use
539    /// [`gdk_pixbuf::Pixbuf::from_file()`][crate::gdk_pixbuf::Pixbuf::from_file()] to load the file yourself, then create
540    /// the [`Image`][crate::Image] from the pixbuf. (Or for animations, use
541    /// `gdk_pixbuf_animation_new_from_file()`).
542    ///
543    /// The storage type ([`ImageExt::storage_type()`][crate::prelude::ImageExt::storage_type()]) of the returned
544    /// image is not defined, it will be whatever is appropriate for
545    /// displaying the file.
546    /// ## `filename`
547    /// a filename
548    ///
549    /// # Returns
550    ///
551    /// a new [`Image`][crate::Image]
552    #[doc(alias = "gtk_image_new_from_file")]
553    #[doc(alias = "new_from_file")]
554    pub fn from_file(filename: impl AsRef<std::path::Path>) -> Image {
555        assert_initialized_main_thread!();
556        unsafe {
557            Widget::from_glib_none(ffi::gtk_image_new_from_file(
558                filename.as_ref().to_glib_none().0,
559            ))
560            .unsafe_cast()
561        }
562    }
563
564    /// Creates a [`Image`][crate::Image] displaying an icon from the current icon theme.
565    /// If the icon name isn’t known, a “broken image” icon will be
566    /// displayed instead. If the current icon theme is changed, the icon
567    /// will be updated appropriately.
568    /// ## `icon`
569    /// an icon
570    /// ## `size`
571    /// a stock icon size ([`IconSize`][crate::IconSize])
572    ///
573    /// # Returns
574    ///
575    /// a new [`Image`][crate::Image] displaying the themed icon
576    #[doc(alias = "gtk_image_new_from_gicon")]
577    #[doc(alias = "new_from_gicon")]
578    pub fn from_gicon(icon: &impl IsA<gio::Icon>, size: IconSize) -> Image {
579        assert_initialized_main_thread!();
580        unsafe {
581            Widget::from_glib_none(ffi::gtk_image_new_from_gicon(
582                icon.as_ref().to_glib_none().0,
583                size.into_glib(),
584            ))
585            .unsafe_cast()
586        }
587    }
588
589    /// Creates a [`Image`][crate::Image] displaying an icon from the current icon theme.
590    /// If the icon name isn’t known, a “broken image” icon will be
591    /// displayed instead. If the current icon theme is changed, the icon
592    /// will be updated appropriately.
593    /// ## `icon_name`
594    /// an icon name or [`None`]
595    /// ## `size`
596    /// a stock icon size ([`IconSize`][crate::IconSize])
597    ///
598    /// # Returns
599    ///
600    /// a new [`Image`][crate::Image] displaying the themed icon
601    #[doc(alias = "gtk_image_new_from_icon_name")]
602    #[doc(alias = "new_from_icon_name")]
603    pub fn from_icon_name(icon_name: Option<&str>, size: IconSize) -> Image {
604        assert_initialized_main_thread!();
605        unsafe {
606            Widget::from_glib_none(ffi::gtk_image_new_from_icon_name(
607                icon_name.to_glib_none().0,
608                size.into_glib(),
609            ))
610            .unsafe_cast()
611        }
612    }
613
614    /// Creates a new [`Image`][crate::Image] displaying `pixbuf`.
615    /// The [`Image`][crate::Image] does not assume a reference to the
616    /// pixbuf; you still need to unref it if you own references.
617    /// [`Image`][crate::Image] will add its own reference rather than adopting yours.
618    ///
619    /// Note that this function just creates an [`Image`][crate::Image] from the pixbuf. The
620    /// [`Image`][crate::Image] created will not react to state changes. Should you want that,
621    /// you should use [`from_icon_name()`][Self::from_icon_name()].
622    /// ## `pixbuf`
623    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf], or [`None`]
624    ///
625    /// # Returns
626    ///
627    /// a new [`Image`][crate::Image]
628    #[doc(alias = "gtk_image_new_from_pixbuf")]
629    #[doc(alias = "new_from_pixbuf")]
630    pub fn from_pixbuf(pixbuf: Option<&gdk_pixbuf::Pixbuf>) -> Image {
631        assert_initialized_main_thread!();
632        unsafe {
633            Widget::from_glib_none(ffi::gtk_image_new_from_pixbuf(pixbuf.to_glib_none().0))
634                .unsafe_cast()
635        }
636    }
637
638    /// Creates a new [`Image`][crate::Image] displaying the resource file `resource_path`. If the file
639    /// isn’t found or can’t be loaded, the resulting [`Image`][crate::Image] will
640    /// display a “broken image” icon. This function never returns [`None`],
641    /// it always returns a valid [`Image`][crate::Image] widget.
642    ///
643    /// If the file contains an animation, the image will contain an
644    /// animation.
645    ///
646    /// If you need to detect failures to load the file, use
647    /// [`gdk_pixbuf::Pixbuf::from_file()`][crate::gdk_pixbuf::Pixbuf::from_file()] to load the file yourself, then create
648    /// the [`Image`][crate::Image] from the pixbuf. (Or for animations, use
649    /// `gdk_pixbuf_animation_new_from_file()`).
650    ///
651    /// The storage type ([`ImageExt::storage_type()`][crate::prelude::ImageExt::storage_type()]) of the returned
652    /// image is not defined, it will be whatever is appropriate for
653    /// displaying the file.
654    /// ## `resource_path`
655    /// a resource path
656    ///
657    /// # Returns
658    ///
659    /// a new [`Image`][crate::Image]
660    #[doc(alias = "gtk_image_new_from_resource")]
661    #[doc(alias = "new_from_resource")]
662    pub fn from_resource(resource_path: &str) -> Image {
663        assert_initialized_main_thread!();
664        unsafe {
665            Widget::from_glib_none(ffi::gtk_image_new_from_resource(
666                resource_path.to_glib_none().0,
667            ))
668            .unsafe_cast()
669        }
670    }
671
672    /// Creates a new [`Image`][crate::Image] displaying `surface`.
673    /// The [`Image`][crate::Image] does not assume a reference to the
674    /// surface; you still need to unref it if you own references.
675    /// [`Image`][crate::Image] will add its own reference rather than adopting yours.
676    /// ## `surface`
677    /// a [`cairo::Surface`][crate::cairo::Surface], or [`None`]
678    ///
679    /// # Returns
680    ///
681    /// a new [`Image`][crate::Image]
682    #[doc(alias = "gtk_image_new_from_surface")]
683    #[doc(alias = "new_from_surface")]
684    pub fn from_surface(surface: Option<&cairo::Surface>) -> Image {
685        assert_initialized_main_thread!();
686        unsafe {
687            Widget::from_glib_none(ffi::gtk_image_new_from_surface(mut_override(
688                surface.to_glib_none().0,
689            )))
690            .unsafe_cast()
691        }
692    }
693}
694
695impl Default for Image {
696    fn default() -> Self {
697        Self::new()
698    }
699}
700
701/// Trait containing all [`struct@Image`] methods.
702///
703/// # Implementors
704///
705/// [`Image`][struct@crate::Image]
706pub trait ImageExt: IsA<Image> + 'static {
707    /// Resets the image to be empty.
708    #[doc(alias = "gtk_image_clear")]
709    fn clear(&self) {
710        unsafe {
711            ffi::gtk_image_clear(self.as_ref().to_glib_none().0);
712        }
713    }
714
715    /// Gets the [`gdk_pixbuf::PixbufAnimation`][crate::gdk_pixbuf::PixbufAnimation] being displayed by the [`Image`][crate::Image].
716    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
717    /// [`ImageType::Animation`][crate::ImageType::Animation] (see [`storage_type()`][Self::storage_type()]).
718    /// The caller of this function does not own a reference to the
719    /// returned animation.
720    ///
721    /// # Returns
722    ///
723    /// the displayed animation, or [`None`] if
724    /// the image is empty
725    #[doc(alias = "gtk_image_get_animation")]
726    #[doc(alias = "get_animation")]
727    fn animation(&self) -> Option<gdk_pixbuf::PixbufAnimation> {
728        unsafe { from_glib_none(ffi::gtk_image_get_animation(self.as_ref().to_glib_none().0)) }
729    }
730
731    /// Gets the [`gio::Icon`][crate::gio::Icon] and size being displayed by the [`Image`][crate::Image].
732    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
733    /// [`ImageType::Gicon`][crate::ImageType::Gicon] (see [`storage_type()`][Self::storage_type()]).
734    /// The caller of this function does not own a reference to the
735    /// returned [`gio::Icon`][crate::gio::Icon].
736    ///
737    /// # Returns
738    ///
739    ///
740    /// ## `gicon`
741    /// place to store a
742    ///  [`gio::Icon`][crate::gio::Icon], or [`None`]
743    ///
744    /// ## `size`
745    /// place to store an icon size
746    ///  ([`IconSize`][crate::IconSize]), or [`None`]
747    #[doc(alias = "gtk_image_get_gicon")]
748    #[doc(alias = "get_gicon")]
749    fn gicon(&self) -> (gio::Icon, IconSize) {
750        unsafe {
751            let mut gicon = std::ptr::null_mut();
752            let mut size = std::mem::MaybeUninit::uninit();
753            ffi::gtk_image_get_gicon(
754                self.as_ref().to_glib_none().0,
755                &mut gicon,
756                size.as_mut_ptr(),
757            );
758            (from_glib_none(gicon), from_glib(size.assume_init()))
759        }
760    }
761
762    /// Gets the [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] being displayed by the [`Image`][crate::Image].
763    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
764    /// [`ImageType::Pixbuf`][crate::ImageType::Pixbuf] (see [`storage_type()`][Self::storage_type()]).
765    /// The caller of this function does not own a reference to the
766    /// returned pixbuf.
767    ///
768    /// # Returns
769    ///
770    /// the displayed pixbuf, or [`None`] if
771    /// the image is empty
772    #[doc(alias = "gtk_image_get_pixbuf")]
773    #[doc(alias = "get_pixbuf")]
774    fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
775        unsafe { from_glib_none(ffi::gtk_image_get_pixbuf(self.as_ref().to_glib_none().0)) }
776    }
777
778    /// Gets the pixel size used for named icons.
779    ///
780    /// # Returns
781    ///
782    /// the pixel size used for named icons.
783    #[doc(alias = "gtk_image_get_pixel_size")]
784    #[doc(alias = "get_pixel_size")]
785    #[doc(alias = "pixel-size")]
786    fn pixel_size(&self) -> i32 {
787        unsafe { ffi::gtk_image_get_pixel_size(self.as_ref().to_glib_none().0) }
788    }
789
790    /// Gets the type of representation being used by the [`Image`][crate::Image]
791    /// to store image data. If the [`Image`][crate::Image] has no image data,
792    /// the return value will be [`ImageType::Empty`][crate::ImageType::Empty].
793    ///
794    /// # Returns
795    ///
796    /// image representation being used
797    #[doc(alias = "gtk_image_get_storage_type")]
798    #[doc(alias = "get_storage_type")]
799    #[doc(alias = "storage-type")]
800    fn storage_type(&self) -> ImageType {
801        unsafe {
802            from_glib(ffi::gtk_image_get_storage_type(
803                self.as_ref().to_glib_none().0,
804            ))
805        }
806    }
807
808    /// Causes the [`Image`][crate::Image] to display the given animation (or display
809    /// nothing, if you set the animation to [`None`]).
810    /// ## `animation`
811    /// the [`gdk_pixbuf::PixbufAnimation`][crate::gdk_pixbuf::PixbufAnimation]
812    #[doc(alias = "gtk_image_set_from_animation")]
813    fn set_from_animation(&self, animation: &impl IsA<gdk_pixbuf::PixbufAnimation>) {
814        unsafe {
815            ffi::gtk_image_set_from_animation(
816                self.as_ref().to_glib_none().0,
817                animation.as_ref().to_glib_none().0,
818            );
819        }
820    }
821
822    /// See [`Image::from_file()`][crate::Image::from_file()] for details.
823    /// ## `filename`
824    /// a filename or [`None`]
825    #[doc(alias = "gtk_image_set_from_file")]
826    fn set_from_file(&self, filename: Option<impl AsRef<std::path::Path>>) {
827        unsafe {
828            ffi::gtk_image_set_from_file(
829                self.as_ref().to_glib_none().0,
830                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
831            );
832        }
833    }
834
835    /// See [`Image::from_gicon()`][crate::Image::from_gicon()] for details.
836    /// ## `icon`
837    /// an icon
838    /// ## `size`
839    /// an icon size ([`IconSize`][crate::IconSize])
840    #[doc(alias = "gtk_image_set_from_gicon")]
841    fn set_from_gicon(&self, icon: &impl IsA<gio::Icon>, size: IconSize) {
842        unsafe {
843            ffi::gtk_image_set_from_gicon(
844                self.as_ref().to_glib_none().0,
845                icon.as_ref().to_glib_none().0,
846                size.into_glib(),
847            );
848        }
849    }
850
851    /// See [`Image::from_icon_name()`][crate::Image::from_icon_name()] for details.
852    /// ## `icon_name`
853    /// an icon name or [`None`]
854    /// ## `size`
855    /// an icon size ([`IconSize`][crate::IconSize])
856    #[doc(alias = "gtk_image_set_from_icon_name")]
857    fn set_from_icon_name(&self, icon_name: Option<&str>, size: IconSize) {
858        unsafe {
859            ffi::gtk_image_set_from_icon_name(
860                self.as_ref().to_glib_none().0,
861                icon_name.to_glib_none().0,
862                size.into_glib(),
863            );
864        }
865    }
866
867    /// See [`Image::from_pixbuf()`][crate::Image::from_pixbuf()] for details.
868    /// ## `pixbuf`
869    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] or [`None`]
870    #[doc(alias = "gtk_image_set_from_pixbuf")]
871    fn set_from_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
872        unsafe {
873            ffi::gtk_image_set_from_pixbuf(self.as_ref().to_glib_none().0, pixbuf.to_glib_none().0);
874        }
875    }
876
877    /// See [`Image::from_resource()`][crate::Image::from_resource()] for details.
878    /// ## `resource_path`
879    /// a resource path or [`None`]
880    #[doc(alias = "gtk_image_set_from_resource")]
881    fn set_from_resource(&self, resource_path: Option<&str>) {
882        unsafe {
883            ffi::gtk_image_set_from_resource(
884                self.as_ref().to_glib_none().0,
885                resource_path.to_glib_none().0,
886            );
887        }
888    }
889
890    /// See [`Image::from_surface()`][crate::Image::from_surface()] for details.
891    /// ## `surface`
892    /// a cairo_surface_t or [`None`]
893    #[doc(alias = "gtk_image_set_from_surface")]
894    fn set_from_surface(&self, surface: Option<&cairo::Surface>) {
895        unsafe {
896            ffi::gtk_image_set_from_surface(
897                self.as_ref().to_glib_none().0,
898                mut_override(surface.to_glib_none().0),
899            );
900        }
901    }
902
903    /// Sets the pixel size to use for named icons. If the pixel size is set
904    /// to a value != -1, it is used instead of the icon size set by
905    /// [`set_from_icon_name()`][Self::set_from_icon_name()].
906    /// ## `pixel_size`
907    /// the new pixel size
908    #[doc(alias = "gtk_image_set_pixel_size")]
909    #[doc(alias = "pixel-size")]
910    fn set_pixel_size(&self, pixel_size: i32) {
911        unsafe {
912            ffi::gtk_image_set_pixel_size(self.as_ref().to_glib_none().0, pixel_size);
913        }
914    }
915
916    fn file(&self) -> Option<glib::GString> {
917        ObjectExt::property(self.as_ref(), "file")
918    }
919
920    fn set_file(&self, file: Option<&str>) {
921        ObjectExt::set_property(self.as_ref(), "file", file)
922    }
923
924    /// The GIcon displayed in the GtkImage. For themed icons,
925    /// If the icon theme is changed, the image will be updated
926    /// automatically.
927    fn set_gicon<P: IsA<gio::Icon>>(&self, gicon: Option<&P>) {
928        ObjectExt::set_property(self.as_ref(), "gicon", gicon)
929    }
930
931    #[doc(alias = "icon-name")]
932    fn icon_name(&self) -> Option<glib::GString> {
933        ObjectExt::property(self.as_ref(), "icon-name")
934    }
935
936    /// The name of the icon in the icon theme. If the icon theme is
937    /// changed, the image will be updated automatically.
938    #[doc(alias = "icon-name")]
939    fn set_icon_name(&self, icon_name: Option<&str>) {
940        ObjectExt::set_property(self.as_ref(), "icon-name", icon_name)
941    }
942
943    fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
944        ObjectExt::set_property(self.as_ref(), "pixbuf", pixbuf)
945    }
946
947    #[doc(alias = "pixbuf-animation")]
948    fn pixbuf_animation(&self) -> Option<gdk_pixbuf::PixbufAnimation> {
949        ObjectExt::property(self.as_ref(), "pixbuf-animation")
950    }
951
952    #[doc(alias = "pixbuf-animation")]
953    fn set_pixbuf_animation<P: IsA<gdk_pixbuf::PixbufAnimation>>(
954        &self,
955        pixbuf_animation: Option<&P>,
956    ) {
957        ObjectExt::set_property(self.as_ref(), "pixbuf-animation", pixbuf_animation)
958    }
959
960    /// A path to a resource file to display.
961    fn resource(&self) -> Option<glib::GString> {
962        ObjectExt::property(self.as_ref(), "resource")
963    }
964
965    /// A path to a resource file to display.
966    fn set_resource(&self, resource: Option<&str>) {
967        ObjectExt::set_property(self.as_ref(), "resource", resource)
968    }
969
970    fn surface(&self) -> Option<cairo::Surface> {
971        ObjectExt::property(self.as_ref(), "surface")
972    }
973
974    fn set_surface(&self, surface: Option<&cairo::Surface>) {
975        ObjectExt::set_property(self.as_ref(), "surface", surface)
976    }
977
978    /// Whether the icon displayed in the GtkImage will use
979    /// standard icon names fallback. The value of this property
980    /// is only relevant for images of type [`ImageType::IconName`][crate::ImageType::IconName]
981    /// and [`ImageType::Gicon`][crate::ImageType::Gicon].
982    #[doc(alias = "use-fallback")]
983    fn uses_fallback(&self) -> bool {
984        ObjectExt::property(self.as_ref(), "use-fallback")
985    }
986
987    /// Whether the icon displayed in the GtkImage will use
988    /// standard icon names fallback. The value of this property
989    /// is only relevant for images of type [`ImageType::IconName`][crate::ImageType::IconName]
990    /// and [`ImageType::Gicon`][crate::ImageType::Gicon].
991    #[doc(alias = "use-fallback")]
992    fn set_use_fallback(&self, use_fallback: bool) {
993        ObjectExt::set_property(self.as_ref(), "use-fallback", use_fallback)
994    }
995
996    #[doc(alias = "file")]
997    fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
998        unsafe extern "C" fn notify_file_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
999            this: *mut ffi::GtkImage,
1000            _param_spec: glib::ffi::gpointer,
1001            f: glib::ffi::gpointer,
1002        ) {
1003            unsafe {
1004                let f: &F = &*(f as *const F);
1005                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1006            }
1007        }
1008        unsafe {
1009            let f: Box_<F> = Box_::new(f);
1010            connect_raw(
1011                self.as_ptr() as *mut _,
1012                c"notify::file".as_ptr(),
1013                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1014                    notify_file_trampoline::<Self, F> as *const (),
1015                )),
1016                Box_::into_raw(f),
1017            )
1018        }
1019    }
1020
1021    #[doc(alias = "gicon")]
1022    fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1023        unsafe extern "C" fn notify_gicon_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1024            this: *mut ffi::GtkImage,
1025            _param_spec: glib::ffi::gpointer,
1026            f: glib::ffi::gpointer,
1027        ) {
1028            unsafe {
1029                let f: &F = &*(f as *const F);
1030                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1031            }
1032        }
1033        unsafe {
1034            let f: Box_<F> = Box_::new(f);
1035            connect_raw(
1036                self.as_ptr() as *mut _,
1037                c"notify::gicon".as_ptr(),
1038                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1039                    notify_gicon_trampoline::<Self, F> as *const (),
1040                )),
1041                Box_::into_raw(f),
1042            )
1043        }
1044    }
1045
1046    #[doc(alias = "icon-name")]
1047    fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1048        unsafe extern "C" fn notify_icon_name_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1049            this: *mut ffi::GtkImage,
1050            _param_spec: glib::ffi::gpointer,
1051            f: glib::ffi::gpointer,
1052        ) {
1053            unsafe {
1054                let f: &F = &*(f as *const F);
1055                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1056            }
1057        }
1058        unsafe {
1059            let f: Box_<F> = Box_::new(f);
1060            connect_raw(
1061                self.as_ptr() as *mut _,
1062                c"notify::icon-name".as_ptr(),
1063                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1064                    notify_icon_name_trampoline::<Self, F> as *const (),
1065                )),
1066                Box_::into_raw(f),
1067            )
1068        }
1069    }
1070
1071    #[doc(alias = "pixbuf")]
1072    fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1073        unsafe extern "C" fn notify_pixbuf_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1074            this: *mut ffi::GtkImage,
1075            _param_spec: glib::ffi::gpointer,
1076            f: glib::ffi::gpointer,
1077        ) {
1078            unsafe {
1079                let f: &F = &*(f as *const F);
1080                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1081            }
1082        }
1083        unsafe {
1084            let f: Box_<F> = Box_::new(f);
1085            connect_raw(
1086                self.as_ptr() as *mut _,
1087                c"notify::pixbuf".as_ptr(),
1088                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1089                    notify_pixbuf_trampoline::<Self, F> as *const (),
1090                )),
1091                Box_::into_raw(f),
1092            )
1093        }
1094    }
1095
1096    #[doc(alias = "pixbuf-animation")]
1097    fn connect_pixbuf_animation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1098        unsafe extern "C" fn notify_pixbuf_animation_trampoline<
1099            P: IsA<Image>,
1100            F: Fn(&P) + 'static,
1101        >(
1102            this: *mut ffi::GtkImage,
1103            _param_spec: glib::ffi::gpointer,
1104            f: glib::ffi::gpointer,
1105        ) {
1106            unsafe {
1107                let f: &F = &*(f as *const F);
1108                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1109            }
1110        }
1111        unsafe {
1112            let f: Box_<F> = Box_::new(f);
1113            connect_raw(
1114                self.as_ptr() as *mut _,
1115                c"notify::pixbuf-animation".as_ptr(),
1116                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1117                    notify_pixbuf_animation_trampoline::<Self, F> as *const (),
1118                )),
1119                Box_::into_raw(f),
1120            )
1121        }
1122    }
1123
1124    #[doc(alias = "pixel-size")]
1125    fn connect_pixel_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1126        unsafe extern "C" fn notify_pixel_size_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1127            this: *mut ffi::GtkImage,
1128            _param_spec: glib::ffi::gpointer,
1129            f: glib::ffi::gpointer,
1130        ) {
1131            unsafe {
1132                let f: &F = &*(f as *const F);
1133                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1134            }
1135        }
1136        unsafe {
1137            let f: Box_<F> = Box_::new(f);
1138            connect_raw(
1139                self.as_ptr() as *mut _,
1140                c"notify::pixel-size".as_ptr(),
1141                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1142                    notify_pixel_size_trampoline::<Self, F> as *const (),
1143                )),
1144                Box_::into_raw(f),
1145            )
1146        }
1147    }
1148
1149    #[doc(alias = "resource")]
1150    fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1151        unsafe extern "C" fn notify_resource_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1152            this: *mut ffi::GtkImage,
1153            _param_spec: glib::ffi::gpointer,
1154            f: glib::ffi::gpointer,
1155        ) {
1156            unsafe {
1157                let f: &F = &*(f as *const F);
1158                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1159            }
1160        }
1161        unsafe {
1162            let f: Box_<F> = Box_::new(f);
1163            connect_raw(
1164                self.as_ptr() as *mut _,
1165                c"notify::resource".as_ptr(),
1166                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1167                    notify_resource_trampoline::<Self, F> as *const (),
1168                )),
1169                Box_::into_raw(f),
1170            )
1171        }
1172    }
1173
1174    #[doc(alias = "storage-type")]
1175    fn connect_storage_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1176        unsafe extern "C" fn notify_storage_type_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1177            this: *mut ffi::GtkImage,
1178            _param_spec: glib::ffi::gpointer,
1179            f: glib::ffi::gpointer,
1180        ) {
1181            unsafe {
1182                let f: &F = &*(f as *const F);
1183                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1184            }
1185        }
1186        unsafe {
1187            let f: Box_<F> = Box_::new(f);
1188            connect_raw(
1189                self.as_ptr() as *mut _,
1190                c"notify::storage-type".as_ptr(),
1191                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1192                    notify_storage_type_trampoline::<Self, F> as *const (),
1193                )),
1194                Box_::into_raw(f),
1195            )
1196        }
1197    }
1198
1199    #[doc(alias = "surface")]
1200    fn connect_surface_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1201        unsafe extern "C" fn notify_surface_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1202            this: *mut ffi::GtkImage,
1203            _param_spec: glib::ffi::gpointer,
1204            f: glib::ffi::gpointer,
1205        ) {
1206            unsafe {
1207                let f: &F = &*(f as *const F);
1208                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1209            }
1210        }
1211        unsafe {
1212            let f: Box_<F> = Box_::new(f);
1213            connect_raw(
1214                self.as_ptr() as *mut _,
1215                c"notify::surface".as_ptr(),
1216                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1217                    notify_surface_trampoline::<Self, F> as *const (),
1218                )),
1219                Box_::into_raw(f),
1220            )
1221        }
1222    }
1223
1224    #[doc(alias = "use-fallback")]
1225    fn connect_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1226        unsafe extern "C" fn notify_use_fallback_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
1227            this: *mut ffi::GtkImage,
1228            _param_spec: glib::ffi::gpointer,
1229            f: glib::ffi::gpointer,
1230        ) {
1231            unsafe {
1232                let f: &F = &*(f as *const F);
1233                f(Image::from_glib_borrow(this).unsafe_cast_ref())
1234            }
1235        }
1236        unsafe {
1237            let f: Box_<F> = Box_::new(f);
1238            connect_raw(
1239                self.as_ptr() as *mut _,
1240                c"notify::use-fallback".as_ptr(),
1241                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1242                    notify_use_fallback_trampoline::<Self, F> as *const (),
1243                )),
1244                Box_::into_raw(f),
1245            )
1246        }
1247    }
1248}
1249
1250impl<O: IsA<Image>> ImageExt for O {}