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};
6use glib::{
7    prelude::*,
8    signal::{connect_raw, SignalHandlerId},
9    translate::*,
10};
11use std::{boxed::Box as Box_, fmt, mem, mem::transmute, ptr};
12
13glib::wrapper! {
14    #[doc(alias = "GtkImage")]
15    pub struct Image(Object<ffi::GtkImage, ffi::GtkImageClass>) @extends Misc, Widget, @implements Buildable;
16
17    match fn {
18        type_ => || ffi::gtk_image_get_type(),
19    }
20}
21
22impl Image {
23    pub const NONE: Option<&'static Image> = None;
24
25    #[doc(alias = "gtk_image_new")]
26    pub fn new() -> Image {
27        assert_initialized_main_thread!();
28        unsafe { Widget::from_glib_none(ffi::gtk_image_new()).unsafe_cast() }
29    }
30
31    #[doc(alias = "gtk_image_new_from_animation")]
32    #[doc(alias = "new_from_animation")]
33    pub fn from_animation(animation: &impl IsA<gdk_pixbuf::PixbufAnimation>) -> Image {
34        assert_initialized_main_thread!();
35        unsafe {
36            Widget::from_glib_none(ffi::gtk_image_new_from_animation(
37                animation.as_ref().to_glib_none().0,
38            ))
39            .unsafe_cast()
40        }
41    }
42
43    #[doc(alias = "gtk_image_new_from_file")]
44    #[doc(alias = "new_from_file")]
45    pub fn from_file(filename: impl AsRef<std::path::Path>) -> Image {
46        assert_initialized_main_thread!();
47        unsafe {
48            Widget::from_glib_none(ffi::gtk_image_new_from_file(
49                filename.as_ref().to_glib_none().0,
50            ))
51            .unsafe_cast()
52        }
53    }
54
55    #[doc(alias = "gtk_image_new_from_gicon")]
56    #[doc(alias = "new_from_gicon")]
57    pub fn from_gicon(icon: &impl IsA<gio::Icon>, size: IconSize) -> Image {
58        assert_initialized_main_thread!();
59        unsafe {
60            Widget::from_glib_none(ffi::gtk_image_new_from_gicon(
61                icon.as_ref().to_glib_none().0,
62                size.into_glib(),
63            ))
64            .unsafe_cast()
65        }
66    }
67
68    #[doc(alias = "gtk_image_new_from_icon_name")]
69    #[doc(alias = "new_from_icon_name")]
70    pub fn from_icon_name(icon_name: Option<&str>, size: IconSize) -> Image {
71        assert_initialized_main_thread!();
72        unsafe {
73            Widget::from_glib_none(ffi::gtk_image_new_from_icon_name(
74                icon_name.to_glib_none().0,
75                size.into_glib(),
76            ))
77            .unsafe_cast()
78        }
79    }
80
81    #[doc(alias = "gtk_image_new_from_pixbuf")]
82    #[doc(alias = "new_from_pixbuf")]
83    pub fn from_pixbuf(pixbuf: Option<&gdk_pixbuf::Pixbuf>) -> Image {
84        assert_initialized_main_thread!();
85        unsafe {
86            Widget::from_glib_none(ffi::gtk_image_new_from_pixbuf(pixbuf.to_glib_none().0))
87                .unsafe_cast()
88        }
89    }
90
91    #[doc(alias = "gtk_image_new_from_resource")]
92    #[doc(alias = "new_from_resource")]
93    pub fn from_resource(resource_path: &str) -> Image {
94        assert_initialized_main_thread!();
95        unsafe {
96            Widget::from_glib_none(ffi::gtk_image_new_from_resource(
97                resource_path.to_glib_none().0,
98            ))
99            .unsafe_cast()
100        }
101    }
102
103    #[doc(alias = "gtk_image_new_from_surface")]
104    #[doc(alias = "new_from_surface")]
105    pub fn from_surface(surface: Option<&cairo::Surface>) -> Image {
106        assert_initialized_main_thread!();
107        unsafe {
108            Widget::from_glib_none(ffi::gtk_image_new_from_surface(mut_override(
109                surface.to_glib_none().0,
110            )))
111            .unsafe_cast()
112        }
113    }
114}
115
116impl Default for Image {
117    fn default() -> Self {
118        Self::new()
119    }
120}
121
122mod sealed {
123    pub trait Sealed {}
124    impl<T: super::IsA<super::Image>> Sealed for T {}
125}
126
127pub trait ImageExt: IsA<Image> + sealed::Sealed + 'static {
128    #[doc(alias = "gtk_image_clear")]
129    fn clear(&self) {
130        unsafe {
131            ffi::gtk_image_clear(self.as_ref().to_glib_none().0);
132        }
133    }
134
135    #[doc(alias = "gtk_image_get_animation")]
136    #[doc(alias = "get_animation")]
137    fn animation(&self) -> Option<gdk_pixbuf::PixbufAnimation> {
138        unsafe { from_glib_none(ffi::gtk_image_get_animation(self.as_ref().to_glib_none().0)) }
139    }
140
141    #[doc(alias = "gtk_image_get_gicon")]
142    #[doc(alias = "get_gicon")]
143    fn gicon(&self) -> (gio::Icon, IconSize) {
144        unsafe {
145            let mut gicon = ptr::null_mut();
146            let mut size = mem::MaybeUninit::uninit();
147            ffi::gtk_image_get_gicon(
148                self.as_ref().to_glib_none().0,
149                &mut gicon,
150                size.as_mut_ptr(),
151            );
152            (from_glib_none(gicon), from_glib(size.assume_init()))
153        }
154    }
155
156    #[doc(alias = "gtk_image_get_pixbuf")]
157    #[doc(alias = "get_pixbuf")]
158    fn pixbuf(&self) -> Option<gdk_pixbuf::Pixbuf> {
159        unsafe { from_glib_none(ffi::gtk_image_get_pixbuf(self.as_ref().to_glib_none().0)) }
160    }
161
162    #[doc(alias = "gtk_image_get_pixel_size")]
163    #[doc(alias = "get_pixel_size")]
164    fn pixel_size(&self) -> i32 {
165        unsafe { ffi::gtk_image_get_pixel_size(self.as_ref().to_glib_none().0) }
166    }
167
168    #[doc(alias = "gtk_image_get_storage_type")]
169    #[doc(alias = "get_storage_type")]
170    fn storage_type(&self) -> ImageType {
171        unsafe {
172            from_glib(ffi::gtk_image_get_storage_type(
173                self.as_ref().to_glib_none().0,
174            ))
175        }
176    }
177
178    #[doc(alias = "gtk_image_set_from_animation")]
179    fn set_from_animation(&self, animation: &impl IsA<gdk_pixbuf::PixbufAnimation>) {
180        unsafe {
181            ffi::gtk_image_set_from_animation(
182                self.as_ref().to_glib_none().0,
183                animation.as_ref().to_glib_none().0,
184            );
185        }
186    }
187
188    #[doc(alias = "gtk_image_set_from_file")]
189    fn set_from_file(&self, filename: Option<impl AsRef<std::path::Path>>) {
190        unsafe {
191            ffi::gtk_image_set_from_file(
192                self.as_ref().to_glib_none().0,
193                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
194            );
195        }
196    }
197
198    #[doc(alias = "gtk_image_set_from_gicon")]
199    fn set_from_gicon(&self, icon: &impl IsA<gio::Icon>, size: IconSize) {
200        unsafe {
201            ffi::gtk_image_set_from_gicon(
202                self.as_ref().to_glib_none().0,
203                icon.as_ref().to_glib_none().0,
204                size.into_glib(),
205            );
206        }
207    }
208
209    #[doc(alias = "gtk_image_set_from_icon_name")]
210    fn set_from_icon_name(&self, icon_name: Option<&str>, size: IconSize) {
211        unsafe {
212            ffi::gtk_image_set_from_icon_name(
213                self.as_ref().to_glib_none().0,
214                icon_name.to_glib_none().0,
215                size.into_glib(),
216            );
217        }
218    }
219
220    #[doc(alias = "gtk_image_set_from_pixbuf")]
221    fn set_from_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
222        unsafe {
223            ffi::gtk_image_set_from_pixbuf(self.as_ref().to_glib_none().0, pixbuf.to_glib_none().0);
224        }
225    }
226
227    #[doc(alias = "gtk_image_set_from_resource")]
228    fn set_from_resource(&self, resource_path: Option<&str>) {
229        unsafe {
230            ffi::gtk_image_set_from_resource(
231                self.as_ref().to_glib_none().0,
232                resource_path.to_glib_none().0,
233            );
234        }
235    }
236
237    #[doc(alias = "gtk_image_set_from_surface")]
238    fn set_from_surface(&self, surface: Option<&cairo::Surface>) {
239        unsafe {
240            ffi::gtk_image_set_from_surface(
241                self.as_ref().to_glib_none().0,
242                mut_override(surface.to_glib_none().0),
243            );
244        }
245    }
246
247    #[doc(alias = "gtk_image_set_pixel_size")]
248    fn set_pixel_size(&self, pixel_size: i32) {
249        unsafe {
250            ffi::gtk_image_set_pixel_size(self.as_ref().to_glib_none().0, pixel_size);
251        }
252    }
253
254    fn file(&self) -> Option<glib::GString> {
255        ObjectExt::property(self.as_ref(), "file")
256    }
257
258    fn set_file(&self, file: Option<&str>) {
259        ObjectExt::set_property(self.as_ref(), "file", file)
260    }
261
262    fn set_gicon<P: IsA<gio::Icon>>(&self, gicon: Option<&P>) {
263        ObjectExt::set_property(self.as_ref(), "gicon", gicon)
264    }
265
266    #[doc(alias = "icon-name")]
267    fn icon_name(&self) -> Option<glib::GString> {
268        ObjectExt::property(self.as_ref(), "icon-name")
269    }
270
271    #[doc(alias = "icon-name")]
272    fn set_icon_name(&self, icon_name: Option<&str>) {
273        ObjectExt::set_property(self.as_ref(), "icon-name", icon_name)
274    }
275
276    fn set_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
277        ObjectExt::set_property(self.as_ref(), "pixbuf", pixbuf)
278    }
279
280    #[doc(alias = "pixbuf-animation")]
281    fn pixbuf_animation(&self) -> Option<gdk_pixbuf::PixbufAnimation> {
282        ObjectExt::property(self.as_ref(), "pixbuf-animation")
283    }
284
285    #[doc(alias = "pixbuf-animation")]
286    fn set_pixbuf_animation<P: IsA<gdk_pixbuf::PixbufAnimation>>(
287        &self,
288        pixbuf_animation: Option<&P>,
289    ) {
290        ObjectExt::set_property(self.as_ref(), "pixbuf-animation", pixbuf_animation)
291    }
292
293    fn resource(&self) -> Option<glib::GString> {
294        ObjectExt::property(self.as_ref(), "resource")
295    }
296
297    fn set_resource(&self, resource: Option<&str>) {
298        ObjectExt::set_property(self.as_ref(), "resource", resource)
299    }
300
301    fn surface(&self) -> Option<cairo::Surface> {
302        ObjectExt::property(self.as_ref(), "surface")
303    }
304
305    fn set_surface(&self, surface: Option<&cairo::Surface>) {
306        ObjectExt::set_property(self.as_ref(), "surface", surface)
307    }
308
309    #[doc(alias = "use-fallback")]
310    fn uses_fallback(&self) -> bool {
311        ObjectExt::property(self.as_ref(), "use-fallback")
312    }
313
314    #[doc(alias = "use-fallback")]
315    fn set_use_fallback(&self, use_fallback: bool) {
316        ObjectExt::set_property(self.as_ref(), "use-fallback", use_fallback)
317    }
318
319    #[doc(alias = "file")]
320    fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
321        unsafe extern "C" fn notify_file_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
322            this: *mut ffi::GtkImage,
323            _param_spec: glib::ffi::gpointer,
324            f: glib::ffi::gpointer,
325        ) {
326            let f: &F = &*(f as *const F);
327            f(Image::from_glib_borrow(this).unsafe_cast_ref())
328        }
329        unsafe {
330            let f: Box_<F> = Box_::new(f);
331            connect_raw(
332                self.as_ptr() as *mut _,
333                b"notify::file\0".as_ptr() as *const _,
334                Some(transmute::<_, unsafe extern "C" fn()>(
335                    notify_file_trampoline::<Self, F> as *const (),
336                )),
337                Box_::into_raw(f),
338            )
339        }
340    }
341
342    #[doc(alias = "gicon")]
343    fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
344        unsafe extern "C" fn notify_gicon_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
345            this: *mut ffi::GtkImage,
346            _param_spec: glib::ffi::gpointer,
347            f: glib::ffi::gpointer,
348        ) {
349            let f: &F = &*(f as *const F);
350            f(Image::from_glib_borrow(this).unsafe_cast_ref())
351        }
352        unsafe {
353            let f: Box_<F> = Box_::new(f);
354            connect_raw(
355                self.as_ptr() as *mut _,
356                b"notify::gicon\0".as_ptr() as *const _,
357                Some(transmute::<_, unsafe extern "C" fn()>(
358                    notify_gicon_trampoline::<Self, F> as *const (),
359                )),
360                Box_::into_raw(f),
361            )
362        }
363    }
364
365    #[doc(alias = "icon-name")]
366    fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
367        unsafe extern "C" fn notify_icon_name_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
368            this: *mut ffi::GtkImage,
369            _param_spec: glib::ffi::gpointer,
370            f: glib::ffi::gpointer,
371        ) {
372            let f: &F = &*(f as *const F);
373            f(Image::from_glib_borrow(this).unsafe_cast_ref())
374        }
375        unsafe {
376            let f: Box_<F> = Box_::new(f);
377            connect_raw(
378                self.as_ptr() as *mut _,
379                b"notify::icon-name\0".as_ptr() as *const _,
380                Some(transmute::<_, unsafe extern "C" fn()>(
381                    notify_icon_name_trampoline::<Self, F> as *const (),
382                )),
383                Box_::into_raw(f),
384            )
385        }
386    }
387
388    #[doc(alias = "pixbuf")]
389    fn connect_pixbuf_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
390        unsafe extern "C" fn notify_pixbuf_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
391            this: *mut ffi::GtkImage,
392            _param_spec: glib::ffi::gpointer,
393            f: glib::ffi::gpointer,
394        ) {
395            let f: &F = &*(f as *const F);
396            f(Image::from_glib_borrow(this).unsafe_cast_ref())
397        }
398        unsafe {
399            let f: Box_<F> = Box_::new(f);
400            connect_raw(
401                self.as_ptr() as *mut _,
402                b"notify::pixbuf\0".as_ptr() as *const _,
403                Some(transmute::<_, unsafe extern "C" fn()>(
404                    notify_pixbuf_trampoline::<Self, F> as *const (),
405                )),
406                Box_::into_raw(f),
407            )
408        }
409    }
410
411    #[doc(alias = "pixbuf-animation")]
412    fn connect_pixbuf_animation_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
413        unsafe extern "C" fn notify_pixbuf_animation_trampoline<
414            P: IsA<Image>,
415            F: Fn(&P) + 'static,
416        >(
417            this: *mut ffi::GtkImage,
418            _param_spec: glib::ffi::gpointer,
419            f: glib::ffi::gpointer,
420        ) {
421            let f: &F = &*(f as *const F);
422            f(Image::from_glib_borrow(this).unsafe_cast_ref())
423        }
424        unsafe {
425            let f: Box_<F> = Box_::new(f);
426            connect_raw(
427                self.as_ptr() as *mut _,
428                b"notify::pixbuf-animation\0".as_ptr() as *const _,
429                Some(transmute::<_, unsafe extern "C" fn()>(
430                    notify_pixbuf_animation_trampoline::<Self, F> as *const (),
431                )),
432                Box_::into_raw(f),
433            )
434        }
435    }
436
437    #[doc(alias = "pixel-size")]
438    fn connect_pixel_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
439        unsafe extern "C" fn notify_pixel_size_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
440            this: *mut ffi::GtkImage,
441            _param_spec: glib::ffi::gpointer,
442            f: glib::ffi::gpointer,
443        ) {
444            let f: &F = &*(f as *const F);
445            f(Image::from_glib_borrow(this).unsafe_cast_ref())
446        }
447        unsafe {
448            let f: Box_<F> = Box_::new(f);
449            connect_raw(
450                self.as_ptr() as *mut _,
451                b"notify::pixel-size\0".as_ptr() as *const _,
452                Some(transmute::<_, unsafe extern "C" fn()>(
453                    notify_pixel_size_trampoline::<Self, F> as *const (),
454                )),
455                Box_::into_raw(f),
456            )
457        }
458    }
459
460    #[doc(alias = "resource")]
461    fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
462        unsafe extern "C" fn notify_resource_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
463            this: *mut ffi::GtkImage,
464            _param_spec: glib::ffi::gpointer,
465            f: glib::ffi::gpointer,
466        ) {
467            let f: &F = &*(f as *const F);
468            f(Image::from_glib_borrow(this).unsafe_cast_ref())
469        }
470        unsafe {
471            let f: Box_<F> = Box_::new(f);
472            connect_raw(
473                self.as_ptr() as *mut _,
474                b"notify::resource\0".as_ptr() as *const _,
475                Some(transmute::<_, unsafe extern "C" fn()>(
476                    notify_resource_trampoline::<Self, F> as *const (),
477                )),
478                Box_::into_raw(f),
479            )
480        }
481    }
482
483    #[doc(alias = "storage-type")]
484    fn connect_storage_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
485        unsafe extern "C" fn notify_storage_type_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
486            this: *mut ffi::GtkImage,
487            _param_spec: glib::ffi::gpointer,
488            f: glib::ffi::gpointer,
489        ) {
490            let f: &F = &*(f as *const F);
491            f(Image::from_glib_borrow(this).unsafe_cast_ref())
492        }
493        unsafe {
494            let f: Box_<F> = Box_::new(f);
495            connect_raw(
496                self.as_ptr() as *mut _,
497                b"notify::storage-type\0".as_ptr() as *const _,
498                Some(transmute::<_, unsafe extern "C" fn()>(
499                    notify_storage_type_trampoline::<Self, F> as *const (),
500                )),
501                Box_::into_raw(f),
502            )
503        }
504    }
505
506    #[doc(alias = "surface")]
507    fn connect_surface_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
508        unsafe extern "C" fn notify_surface_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
509            this: *mut ffi::GtkImage,
510            _param_spec: glib::ffi::gpointer,
511            f: glib::ffi::gpointer,
512        ) {
513            let f: &F = &*(f as *const F);
514            f(Image::from_glib_borrow(this).unsafe_cast_ref())
515        }
516        unsafe {
517            let f: Box_<F> = Box_::new(f);
518            connect_raw(
519                self.as_ptr() as *mut _,
520                b"notify::surface\0".as_ptr() as *const _,
521                Some(transmute::<_, unsafe extern "C" fn()>(
522                    notify_surface_trampoline::<Self, F> as *const (),
523                )),
524                Box_::into_raw(f),
525            )
526        }
527    }
528
529    #[doc(alias = "use-fallback")]
530    fn connect_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
531        unsafe extern "C" fn notify_use_fallback_trampoline<P: IsA<Image>, F: Fn(&P) + 'static>(
532            this: *mut ffi::GtkImage,
533            _param_spec: glib::ffi::gpointer,
534            f: glib::ffi::gpointer,
535        ) {
536            let f: &F = &*(f as *const F);
537            f(Image::from_glib_borrow(this).unsafe_cast_ref())
538        }
539        unsafe {
540            let f: Box_<F> = Box_::new(f);
541            connect_raw(
542                self.as_ptr() as *mut _,
543                b"notify::use-fallback\0".as_ptr() as *const _,
544                Some(transmute::<_, unsafe extern "C" fn()>(
545                    notify_use_fallback_trampoline::<Self, F> as *const (),
546                )),
547                Box_::into_raw(f),
548            )
549        }
550    }
551}
552
553impl<O: IsA<Image>> ImageExt for O {}
554
555impl fmt::Display for Image {
556    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
557        f.write_str("Image")
558    }
559}