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