Skip to main content

gtk4/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#![allow(deprecated)]
5
6#[cfg(feature = "v4_10")]
7#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
8use crate::Accessible;
9use crate::{
10    AccessibleRole, Align, Buildable, ConstraintTarget, IconSize, ImageType, LayoutManager,
11    Overflow, Widget, ffi,
12};
13use glib::{
14    prelude::*,
15    signal::{SignalHandlerId, connect_raw},
16    translate::*,
17};
18use std::boxed::Box as Box_;
19
20#[cfg(feature = "v4_10")]
21#[cfg_attr(docsrs, doc(cfg(feature = "v4_10")))]
22glib::wrapper! {
23    /// Displays an image.
24    ///
25    /// <picture>
26    ///   <source srcset="image-dark.png" media="(prefers-color-scheme: dark)">
27    ///   <img alt="An example GtkImage" src="image.png">
28    /// </picture>
29    ///
30    /// Various kinds of object can be displayed as an image; most typically,
31    /// you would load a [`gdk::Texture`][crate::gdk::Texture] from a file, using the convenience function
32    /// [`from_file()`][Self::from_file()], for instance:
33    ///
34    /// **⚠️ The following code is in c ⚠️**
35    ///
36    /// ```c
37    /// GtkWidget *image = gtk_image_new_from_file ("myfile.png");
38    /// ```
39    ///
40    /// If the file isn’t loaded successfully, the image will contain a
41    /// “broken image” icon similar to that used in many web browsers.
42    ///
43    /// If you want to handle errors in loading the file yourself, for example
44    /// by displaying an error message, then load the image with an image
45    /// loading framework such as libglycin, then create the [`Image`][crate::Image] with
46    /// [`from_paintable()`][Self::from_paintable()].
47    ///
48    /// Sometimes an application will want to avoid depending on external data
49    /// files, such as image files. See the documentation of `GResource` inside
50    /// GIO, for details. In this case, [`resource`][struct@crate::Image#resource],
51    /// [`from_resource()`][Self::from_resource()], and [`set_resource()`][Self::set_resource()]
52    /// should be used.
53    ///
54    /// [`Image`][crate::Image] displays its image as an icon, with a size that is determined
55    /// by the application. See [`Picture`][crate::Picture] if you want to show an image
56    /// at is actual size.
57    ///
58    /// ## CSS nodes
59    ///
60    /// [`Image`][crate::Image] has a single CSS node with the name `image`. The style classes
61    /// `.normal-icons` or `.large-icons` may appear, depending on the
62    /// [`icon-size`][struct@crate::Image#icon-size] property.
63    ///
64    /// ## Accessibility
65    ///
66    /// [`Image`][crate::Image] uses the [enum@Gtk.AccessibleRole.img] role.
67    ///
68    /// ## Properties
69    ///
70    ///
71    /// #### `file`
72    ///  A path to the file to display.
73    ///
74    /// Readable | Writable
75    ///
76    ///
77    /// #### `gicon`
78    ///  The `GIcon` displayed in the GtkImage.
79    ///
80    /// For themed icons, If the icon theme is changed, the image will be updated
81    /// automatically.
82    ///
83    /// Readable | Writable
84    ///
85    ///
86    /// #### `icon-name`
87    ///  The name of the icon in the icon theme.
88    ///
89    /// If the icon theme is changed, the image will be updated automatically.
90    ///
91    /// Readable | Writable
92    ///
93    ///
94    /// #### `icon-size`
95    ///  The symbolic size to display icons at.
96    ///
97    /// Readable | Writable
98    ///
99    ///
100    /// #### `paintable`
101    ///  The [`gdk::Paintable`][crate::gdk::Paintable] to display.
102    ///
103    /// Readable | Writable
104    ///
105    ///
106    /// #### `pixel-size`
107    ///  The size in pixels to display icons at.
108    ///
109    /// If set to a value != -1, this property overrides the
110    /// [`icon-size`][struct@crate::Image#icon-size] property for images of type
111    /// `GTK_IMAGE_ICON_NAME`.
112    ///
113    /// Readable | Writable
114    ///
115    ///
116    /// #### `resource`
117    ///  A path to a resource file to display.
118    ///
119    /// Readable | Writable
120    ///
121    ///
122    /// #### `storage-type`
123    ///  The representation being used for image data.
124    ///
125    /// Readable
126    ///
127    ///
128    /// #### `use-fallback`
129    ///  Whether the icon displayed in the [`Image`][crate::Image] will use
130    /// standard icon names fallback.
131    ///
132    /// The value of this property is only relevant for images of type
133    /// [`ImageType::IconName`][crate::ImageType::IconName] and [`ImageType::Gicon`][crate::ImageType::Gicon].
134    ///
135    /// Readable | Writable
136    /// <details><summary><h4>Widget</h4></summary>
137    ///
138    ///
139    /// #### `can-focus`
140    ///  Whether the widget or any of its descendents can accept
141    /// the input focus.
142    ///
143    /// This property is meant to be set by widget implementations,
144    /// typically in their instance init function.
145    ///
146    /// Readable | Writable
147    ///
148    ///
149    /// #### `can-target`
150    ///  Whether the widget can receive pointer events.
151    ///
152    /// Readable | Writable
153    ///
154    ///
155    /// #### `css-classes`
156    ///  A list of css classes applied to this widget.
157    ///
158    /// Readable | Writable
159    ///
160    ///
161    /// #### `css-name`
162    ///  The name of this widget in the CSS tree.
163    ///
164    /// This property is meant to be set by widget implementations,
165    /// typically in their instance init function.
166    ///
167    /// Readable | Writable | Construct Only
168    ///
169    ///
170    /// #### `cursor`
171    ///  The cursor used by @widget.
172    ///
173    /// Readable | Writable
174    ///
175    ///
176    /// #### `focus-on-click`
177    ///  Whether the widget should grab focus when it is clicked with the mouse.
178    ///
179    /// This property is only relevant for widgets that can take focus.
180    ///
181    /// Readable | Writable
182    ///
183    ///
184    /// #### `focusable`
185    ///  Whether this widget itself will accept the input focus.
186    ///
187    /// Readable | Writable
188    ///
189    ///
190    /// #### `halign`
191    ///  How to distribute horizontal space if widget gets extra space.
192    ///
193    /// Readable | Writable
194    ///
195    ///
196    /// #### `has-default`
197    ///  Whether the widget is the default widget.
198    ///
199    /// Readable
200    ///
201    ///
202    /// #### `has-focus`
203    ///  Whether the widget has the input focus.
204    ///
205    /// Readable
206    ///
207    ///
208    /// #### `has-tooltip`
209    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
210    /// signal on @widget.
211    ///
212    /// A true value indicates that @widget can have a tooltip, in this case
213    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
214    /// determine whether it will provide a tooltip or not.
215    ///
216    /// Readable | Writable
217    ///
218    ///
219    /// #### `height-request`
220    ///  Overrides for height request of the widget.
221    ///
222    /// If this is -1, the natural request will be used.
223    ///
224    /// Readable | Writable
225    ///
226    ///
227    /// #### `hexpand`
228    ///  Whether to expand horizontally.
229    ///
230    /// Readable | Writable
231    ///
232    ///
233    /// #### `hexpand-set`
234    ///  Whether to use the `hexpand` property.
235    ///
236    /// Readable | Writable
237    ///
238    ///
239    /// #### `layout-manager`
240    ///  The [`LayoutManager`][crate::LayoutManager] instance to use to compute
241    /// the preferred size of the widget, and allocate its children.
242    ///
243    /// This property is meant to be set by widget implementations,
244    /// typically in their instance init function.
245    ///
246    /// Readable | Writable
247    ///
248    ///
249    /// #### `limit-events`
250    ///  Makes this widget act like a modal dialog, with respect to
251    /// event delivery.
252    ///
253    /// Global event controllers will not handle events with targets
254    /// inside the widget, unless they are set up to ignore propagation
255    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
256    ///
257    /// Readable | Writable
258    ///
259    ///
260    /// #### `margin-bottom`
261    ///  Margin on bottom side of widget.
262    ///
263    /// This property adds margin outside of the widget's normal size
264    /// request, the margin will be added in addition to the size from
265    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
266    ///
267    /// Readable | Writable
268    ///
269    ///
270    /// #### `margin-end`
271    ///  Margin on end of widget, horizontally.
272    ///
273    /// This property supports left-to-right and right-to-left text
274    /// directions.
275    ///
276    /// This property adds margin outside of the widget's normal size
277    /// request, the margin will be added in addition to the size from
278    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
279    ///
280    /// Readable | Writable
281    ///
282    ///
283    /// #### `margin-start`
284    ///  Margin on start of widget, horizontally.
285    ///
286    /// This property supports left-to-right and right-to-left text
287    /// directions.
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-top`
297    ///  Margin on top 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    /// #### `name`
307    ///  The name of the widget.
308    ///
309    /// Readable | Writable
310    ///
311    ///
312    /// #### `opacity`
313    ///  The requested opacity of the widget.
314    ///
315    /// Readable | Writable
316    ///
317    ///
318    /// #### `overflow`
319    ///  How content outside the widget's content area is treated.
320    ///
321    /// This property is meant to be set by widget implementations,
322    /// typically in their instance init function.
323    ///
324    /// Readable | Writable
325    ///
326    ///
327    /// #### `parent`
328    ///  The parent widget of this widget.
329    ///
330    /// Readable
331    ///
332    ///
333    /// #### `receives-default`
334    ///  Whether the widget will receive the default action when it is focused.
335    ///
336    /// Readable | Writable
337    ///
338    ///
339    /// #### `root`
340    ///  The [`Root`][crate::Root] widget of the widget tree containing this widget.
341    ///
342    /// This will be `NULL` if the widget is not contained in a root widget.
343    ///
344    /// Readable
345    ///
346    ///
347    /// #### `scale-factor`
348    ///  The scale factor of the widget.
349    ///
350    /// Readable
351    ///
352    ///
353    /// #### `sensitive`
354    ///  Whether the widget responds to input.
355    ///
356    /// Readable | Writable
357    ///
358    ///
359    /// #### `tooltip-markup`
360    ///  Sets the text of tooltip to be the given string, which is marked up
361    /// with Pango markup.
362    ///
363    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
364    ///
365    /// This is a convenience property which will take care of getting the
366    /// tooltip shown if the given string is not `NULL`:
367    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
368    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
369    /// the default signal handler.
370    ///
371    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
372    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
373    ///
374    /// Readable | Writable
375    ///
376    ///
377    /// #### `tooltip-text`
378    ///  Sets the text of tooltip to be the given string.
379    ///
380    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
381    ///
382    /// This is a convenience property which will take care of getting the
383    /// tooltip shown if the given string is not `NULL`:
384    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
385    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
386    /// the default signal handler.
387    ///
388    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
389    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
390    ///
391    /// Readable | Writable
392    ///
393    ///
394    /// #### `valign`
395    ///  How to distribute vertical space if widget gets extra space.
396    ///
397    /// Readable | Writable
398    ///
399    ///
400    /// #### `vexpand`
401    ///  Whether to expand vertically.
402    ///
403    /// Readable | Writable
404    ///
405    ///
406    /// #### `vexpand-set`
407    ///  Whether to use the `vexpand` property.
408    ///
409    /// Readable | Writable
410    ///
411    ///
412    /// #### `visible`
413    ///  Whether the widget is visible.
414    ///
415    /// Readable | Writable
416    ///
417    ///
418    /// #### `width-request`
419    ///  Overrides for width request of the widget.
420    ///
421    /// If this is -1, the natural request will be used.
422    ///
423    /// Readable | Writable
424    /// </details>
425    /// <details><summary><h4>Accessible</h4></summary>
426    ///
427    ///
428    /// #### `accessible-role`
429    ///  The accessible role of the given [`Accessible`][crate::Accessible] implementation.
430    ///
431    /// The accessible role cannot be changed once set.
432    ///
433    /// Readable | Writable
434    /// </details>
435    ///
436    /// # Implements
437    ///
438    /// [`WidgetExt`][trait@crate::prelude::WidgetExt], [`trait@glib::ObjectExt`], [`AccessibleExt`][trait@crate::prelude::AccessibleExt], [`BuildableExt`][trait@crate::prelude::BuildableExt], [`ConstraintTargetExt`][trait@crate::prelude::ConstraintTargetExt], [`WidgetExtManual`][trait@crate::prelude::WidgetExtManual], [`AccessibleExtManual`][trait@crate::prelude::AccessibleExtManual]
439    #[doc(alias = "GtkImage")]
440    pub struct Image(Object<ffi::GtkImage>) @extends Widget, @implements Accessible, Buildable, ConstraintTarget;
441
442    match fn {
443        type_ => || ffi::gtk_image_get_type(),
444    }
445}
446
447#[cfg(not(feature = "v4_10"))]
448glib::wrapper! {
449    #[doc(alias = "GtkImage")]
450    pub struct Image(Object<ffi::GtkImage>) @extends Widget, @implements Buildable, ConstraintTarget;
451
452    match fn {
453        type_ => || ffi::gtk_image_get_type(),
454    }
455}
456
457impl Image {
458    /// Creates a new empty [`Image`][crate::Image] widget.
459    ///
460    /// # Returns
461    ///
462    /// a newly created [`Image`][crate::Image] widget.
463    #[doc(alias = "gtk_image_new")]
464    pub fn new() -> Image {
465        assert_initialized_main_thread!();
466        unsafe { Widget::from_glib_none(ffi::gtk_image_new()).unsafe_cast() }
467    }
468
469    /// Creates a new [`Image`][crate::Image] displaying the file @filename.
470    ///
471    /// If the file isn’t found or can’t be loaded, the resulting [`Image`][crate::Image]
472    /// will display a “broken image” icon. This function never returns [`None`],
473    /// it always returns a valid [`Image`][crate::Image] widget.
474    ///
475    /// If you need to detect failures to load the file, use an
476    /// image loading framework such as libglycin to load the file
477    /// yourself, then create the [`Image`][crate::Image] from the texture.
478    ///
479    /// The storage type (see [`storage_type()`][Self::storage_type()])
480    /// of the returned image is not defined, it will be whatever
481    /// is appropriate for displaying the file.
482    /// ## `filename`
483    /// a filename
484    ///
485    /// # Returns
486    ///
487    /// a new [`Image`][crate::Image]
488    #[doc(alias = "gtk_image_new_from_file")]
489    #[doc(alias = "new_from_file")]
490    pub fn from_file(filename: impl AsRef<std::path::Path>) -> Image {
491        assert_initialized_main_thread!();
492        unsafe {
493            Widget::from_glib_none(ffi::gtk_image_new_from_file(
494                filename.as_ref().to_glib_none().0,
495            ))
496            .unsafe_cast()
497        }
498    }
499
500    /// Creates a [`Image`][crate::Image] displaying an icon from the current icon theme.
501    ///
502    /// If the icon name isn’t known, a “broken image” icon will be
503    /// displayed instead. If the current icon theme is changed, the icon
504    /// will be updated appropriately.
505    /// ## `icon`
506    /// an icon
507    ///
508    /// # Returns
509    ///
510    /// a new [`Image`][crate::Image] displaying the themed icon
511    #[doc(alias = "gtk_image_new_from_gicon")]
512    #[doc(alias = "new_from_gicon")]
513    pub fn from_gicon(icon: &impl IsA<gio::Icon>) -> Image {
514        assert_initialized_main_thread!();
515        unsafe {
516            Widget::from_glib_none(ffi::gtk_image_new_from_gicon(
517                icon.as_ref().to_glib_none().0,
518            ))
519            .unsafe_cast()
520        }
521    }
522
523    /// Creates a [`Image`][crate::Image] displaying an icon from the current icon theme.
524    ///
525    /// If the icon name isn’t known, a “broken image” icon will be
526    /// displayed instead. If the current icon theme is changed, the icon
527    /// will be updated appropriately.
528    /// ## `icon_name`
529    /// an icon name
530    ///
531    /// # Returns
532    ///
533    /// a new [`Image`][crate::Image] displaying the themed icon
534    #[doc(alias = "gtk_image_new_from_icon_name")]
535    #[doc(alias = "new_from_icon_name")]
536    pub fn from_icon_name(icon_name: &str) -> Image {
537        assert_initialized_main_thread!();
538        unsafe {
539            Widget::from_glib_none(ffi::gtk_image_new_from_icon_name(
540                icon_name.to_glib_none().0,
541            ))
542            .unsafe_cast()
543        }
544    }
545
546    /// Creates a new [`Image`][crate::Image] displaying @paintable.
547    ///
548    /// The [`Image`][crate::Image] does not assume a reference to the paintable; you still
549    /// need to unref it if you own references. [`Image`][crate::Image] will add its own
550    /// reference rather than adopting yours.
551    ///
552    /// The [`Image`][crate::Image] will track changes to the @paintable and update
553    /// its size and contents in response to it.
554    ///
555    /// Note that paintables are still subject to the icon size that is
556    /// set on the image. If you want to display a paintable at its intrinsic
557    /// size, use [`Picture`][crate::Picture] instead.
558    ///
559    /// If @paintable is a [`SymbolicPaintable`][crate::SymbolicPaintable], then it will be
560    /// recolored with the symbolic palette from the theme.
561    /// ## `paintable`
562    /// a [`gdk::Paintable`][crate::gdk::Paintable]
563    ///
564    /// # Returns
565    ///
566    /// a new [`Image`][crate::Image]
567    #[doc(alias = "gtk_image_new_from_paintable")]
568    #[doc(alias = "new_from_paintable")]
569    pub fn from_paintable(paintable: Option<&impl IsA<gdk::Paintable>>) -> Image {
570        assert_initialized_main_thread!();
571        unsafe {
572            Widget::from_glib_none(ffi::gtk_image_new_from_paintable(
573                paintable.map(|p| p.as_ref()).to_glib_none().0,
574            ))
575            .unsafe_cast()
576        }
577    }
578
579    /// Creates a new [`Image`][crate::Image] displaying @pixbuf.
580    ///
581    /// The [`Image`][crate::Image] does not assume a reference to the pixbuf; you still
582    /// need to unref it if you own references. [`Image`][crate::Image] will add its own
583    /// reference rather than adopting yours.
584    ///
585    /// This is a helper for [`from_paintable()`][Self::from_paintable()], and you can't
586    /// get back the exact pixbuf once this is called, only a texture.
587    ///
588    /// Note that this function just creates an [`Image`][crate::Image] from the pixbuf.
589    /// The [`Image`][crate::Image] created will not react to state changes. Should you
590    /// want that, you should use [`from_icon_name()`][Self::from_icon_name()].
591    ///
592    /// # Deprecated since 4.12
593    ///
594    /// Use [`from_paintable()`][Self::from_paintable()] and
595    ///   [`gdk::Texture::for_pixbuf()`][crate::gdk::Texture::for_pixbuf()] instead
596    /// ## `pixbuf`
597    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf]
598    ///
599    /// # Returns
600    ///
601    /// a new [`Image`][crate::Image]
602    #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
603    #[allow(deprecated)]
604    #[doc(alias = "gtk_image_new_from_pixbuf")]
605    #[doc(alias = "new_from_pixbuf")]
606    pub fn from_pixbuf(pixbuf: Option<&gdk_pixbuf::Pixbuf>) -> Image {
607        assert_initialized_main_thread!();
608        unsafe {
609            Widget::from_glib_none(ffi::gtk_image_new_from_pixbuf(pixbuf.to_glib_none().0))
610                .unsafe_cast()
611        }
612    }
613
614    /// Creates a new [`Image`][crate::Image] displaying the resource file @resource_path.
615    ///
616    /// If the file isn’t found or can’t be loaded, the resulting [`Image`][crate::Image] will
617    /// display a “broken image” icon. This function never returns [`None`],
618    /// it always returns a valid [`Image`][crate::Image] widget.
619    ///
620    /// If you need to detect failures to load the file, use an
621    /// image loading framework such as libglycin to load the file
622    /// yourself, then create the [`Image`][crate::Image] from the texture.
623    ///
624    /// The storage type (see [`storage_type()`][Self::storage_type()]) of
625    /// the returned image is not defined, it will be whatever is
626    /// appropriate for displaying the file.
627    /// ## `resource_path`
628    /// a resource path
629    ///
630    /// # Returns
631    ///
632    /// a new [`Image`][crate::Image]
633    #[doc(alias = "gtk_image_new_from_resource")]
634    #[doc(alias = "new_from_resource")]
635    pub fn from_resource(resource_path: &str) -> Image {
636        assert_initialized_main_thread!();
637        unsafe {
638            Widget::from_glib_none(ffi::gtk_image_new_from_resource(
639                resource_path.to_glib_none().0,
640            ))
641            .unsafe_cast()
642        }
643    }
644
645    // rustdoc-stripper-ignore-next
646    /// Creates a new builder-pattern struct instance to construct [`Image`] objects.
647    ///
648    /// This method returns an instance of [`ImageBuilder`](crate::builders::ImageBuilder) which can be used to create [`Image`] objects.
649    pub fn builder() -> ImageBuilder {
650        ImageBuilder::new()
651    }
652
653    /// Resets the image to be empty.
654    #[doc(alias = "gtk_image_clear")]
655    pub fn clear(&self) {
656        unsafe {
657            ffi::gtk_image_clear(self.to_glib_none().0);
658        }
659    }
660
661    /// Gets the `GIcon` being displayed by the [`Image`][crate::Image].
662    ///
663    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
664    /// [`ImageType::Gicon`][crate::ImageType::Gicon] (see [`storage_type()`][Self::storage_type()]).
665    /// The caller of this function does not own a reference to the
666    /// returned `GIcon`.
667    ///
668    /// # Returns
669    ///
670    /// a `GIcon`
671    #[doc(alias = "gtk_image_get_gicon")]
672    #[doc(alias = "get_gicon")]
673    pub fn gicon(&self) -> Option<gio::Icon> {
674        unsafe { from_glib_none(ffi::gtk_image_get_gicon(self.to_glib_none().0)) }
675    }
676
677    /// Gets the icon name and size being displayed by the [`Image`][crate::Image].
678    ///
679    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
680    /// [`ImageType::IconName`][crate::ImageType::IconName] (see [`storage_type()`][Self::storage_type()]).
681    /// The returned string is owned by the [`Image`][crate::Image] and should not
682    /// be freed.
683    ///
684    /// # Returns
685    ///
686    /// the icon name
687    #[doc(alias = "gtk_image_get_icon_name")]
688    #[doc(alias = "get_icon_name")]
689    #[doc(alias = "icon-name")]
690    pub fn icon_name(&self) -> Option<glib::GString> {
691        unsafe { from_glib_none(ffi::gtk_image_get_icon_name(self.to_glib_none().0)) }
692    }
693
694    /// Gets the icon size used by the @self when rendering icons.
695    ///
696    /// # Returns
697    ///
698    /// the image size used by icons
699    #[doc(alias = "gtk_image_get_icon_size")]
700    #[doc(alias = "get_icon_size")]
701    #[doc(alias = "icon-size")]
702    pub fn icon_size(&self) -> IconSize {
703        unsafe { from_glib(ffi::gtk_image_get_icon_size(self.to_glib_none().0)) }
704    }
705
706    /// Gets the image [`gdk::Paintable`][crate::gdk::Paintable] being displayed by the [`Image`][crate::Image].
707    ///
708    /// The storage type of the image must be [`ImageType::Empty`][crate::ImageType::Empty] or
709    /// [`ImageType::Paintable`][crate::ImageType::Paintable] (see [`storage_type()`][Self::storage_type()]).
710    /// The caller of this function does not own a reference to the
711    /// returned paintable.
712    ///
713    /// # Returns
714    ///
715    /// the displayed paintable
716    #[doc(alias = "gtk_image_get_paintable")]
717    #[doc(alias = "get_paintable")]
718    pub fn paintable(&self) -> Option<gdk::Paintable> {
719        unsafe { from_glib_none(ffi::gtk_image_get_paintable(self.to_glib_none().0)) }
720    }
721
722    /// Gets the pixel size used for named icons.
723    ///
724    /// # Returns
725    ///
726    /// the pixel size used for named icons.
727    #[doc(alias = "gtk_image_get_pixel_size")]
728    #[doc(alias = "get_pixel_size")]
729    #[doc(alias = "pixel-size")]
730    pub fn pixel_size(&self) -> i32 {
731        unsafe { ffi::gtk_image_get_pixel_size(self.to_glib_none().0) }
732    }
733
734    /// Gets the type of representation being used by the [`Image`][crate::Image]
735    /// to store image data.
736    ///
737    /// If the [`Image`][crate::Image] has no image data, the return value will
738    /// be [`ImageType::Empty`][crate::ImageType::Empty].
739    ///
740    /// # Returns
741    ///
742    /// image representation being used
743    #[doc(alias = "gtk_image_get_storage_type")]
744    #[doc(alias = "get_storage_type")]
745    #[doc(alias = "storage-type")]
746    pub fn storage_type(&self) -> ImageType {
747        unsafe { from_glib(ffi::gtk_image_get_storage_type(self.to_glib_none().0)) }
748    }
749
750    /// Sets a [`Image`][crate::Image] to show a file.
751    ///
752    /// See [`from_file()`][Self::from_file()] for details.
753    ///
754    /// ::: warning
755    ///     Note that this function should not be used with untrusted data.
756    ///     Use a proper image loading framework such as libglycin, which can
757    ///     load many image formats into a [`gdk::Texture`][crate::gdk::Texture], and then use
758    ///     [`set_paintable()`][Self::set_paintable()].
759    /// ## `filename`
760    /// a filename
761    #[doc(alias = "gtk_image_set_from_file")]
762    #[doc(alias = "file")]
763    pub fn set_from_file(&self, filename: Option<impl AsRef<std::path::Path>>) {
764        unsafe {
765            ffi::gtk_image_set_from_file(
766                self.to_glib_none().0,
767                filename.as_ref().map(|p| p.as_ref()).to_glib_none().0,
768            );
769        }
770    }
771
772    /// Sets a [`Image`][crate::Image] to show a `GIcon`.
773    ///
774    /// See [`from_gicon()`][Self::from_gicon()] for details.
775    /// ## `icon`
776    /// an icon
777    #[doc(alias = "gtk_image_set_from_gicon")]
778    #[doc(alias = "gicon")]
779    pub fn set_from_gicon(&self, icon: &impl IsA<gio::Icon>) {
780        unsafe {
781            ffi::gtk_image_set_from_gicon(self.to_glib_none().0, icon.as_ref().to_glib_none().0);
782        }
783    }
784
785    /// Sets a [`Image`][crate::Image] to show a named icon.
786    ///
787    /// See [`from_icon_name()`][Self::from_icon_name()] for details.
788    /// ## `icon_name`
789    /// an icon name
790    #[doc(alias = "gtk_image_set_from_icon_name")]
791    #[doc(alias = "set_from_icon_name")]
792    #[doc(alias = "icon-name")]
793    pub fn set_icon_name(&self, icon_name: Option<&str>) {
794        unsafe {
795            ffi::gtk_image_set_from_icon_name(self.to_glib_none().0, icon_name.to_glib_none().0);
796        }
797    }
798
799    /// Sets a [`Image`][crate::Image] to show a [`gdk::Paintable`][crate::gdk::Paintable].
800    ///
801    /// See [`from_paintable()`][Self::from_paintable()] for details.
802    /// ## `paintable`
803    /// a [`gdk::Paintable`][crate::gdk::Paintable]
804    #[doc(alias = "gtk_image_set_from_paintable")]
805    #[doc(alias = "set_from_paintable")]
806    #[doc(alias = "paintable")]
807    pub fn set_paintable(&self, paintable: Option<&impl IsA<gdk::Paintable>>) {
808        unsafe {
809            ffi::gtk_image_set_from_paintable(
810                self.to_glib_none().0,
811                paintable.map(|p| p.as_ref()).to_glib_none().0,
812            );
813        }
814    }
815
816    /// Sets a [`Image`][crate::Image] to show a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf].
817    ///
818    /// See [`from_pixbuf()`][Self::from_pixbuf()] for details.
819    ///
820    /// Note: This is a helper for [`set_paintable()`][Self::set_paintable()],
821    /// and you can't get back the exact pixbuf once this is called,
822    /// only a paintable.
823    ///
824    /// # Deprecated since 4.12
825    ///
826    /// Use [`set_paintable()`][Self::set_paintable()] instead
827    /// ## `pixbuf`
828    /// a [`gdk_pixbuf::Pixbuf`][crate::gdk_pixbuf::Pixbuf] or `NULL`
829    #[cfg_attr(feature = "v4_12", deprecated = "Since 4.12")]
830    #[allow(deprecated)]
831    #[doc(alias = "gtk_image_set_from_pixbuf")]
832    pub fn set_from_pixbuf(&self, pixbuf: Option<&gdk_pixbuf::Pixbuf>) {
833        unsafe {
834            ffi::gtk_image_set_from_pixbuf(self.to_glib_none().0, pixbuf.to_glib_none().0);
835        }
836    }
837
838    /// Sets a [`Image`][crate::Image] to show a resource.
839    ///
840    /// See [`from_resource()`][Self::from_resource()] for details.
841    /// ## `resource_path`
842    /// a resource path
843    #[doc(alias = "gtk_image_set_from_resource")]
844    #[doc(alias = "set_from_resource")]
845    #[doc(alias = "resource")]
846    pub fn set_resource(&self, resource_path: Option<&str>) {
847        unsafe {
848            ffi::gtk_image_set_from_resource(self.to_glib_none().0, resource_path.to_glib_none().0);
849        }
850    }
851
852    /// Suggests an icon size to the theme for named icons.
853    /// ## `icon_size`
854    /// the new icon size
855    #[doc(alias = "gtk_image_set_icon_size")]
856    #[doc(alias = "icon-size")]
857    pub fn set_icon_size(&self, icon_size: IconSize) {
858        unsafe {
859            ffi::gtk_image_set_icon_size(self.to_glib_none().0, icon_size.into_glib());
860        }
861    }
862
863    /// Sets the pixel size to use for named icons.
864    ///
865    /// If the pixel size is set to a value != -1, it is used instead
866    /// of the icon size set by [`set_icon_size()`][Self::set_icon_size()].
867    /// ## `pixel_size`
868    /// the new pixel size
869    #[doc(alias = "gtk_image_set_pixel_size")]
870    #[doc(alias = "pixel-size")]
871    pub fn set_pixel_size(&self, pixel_size: i32) {
872        unsafe {
873            ffi::gtk_image_set_pixel_size(self.to_glib_none().0, pixel_size);
874        }
875    }
876
877    /// A path to the file to display.
878    pub fn file(&self) -> Option<glib::GString> {
879        ObjectExt::property(self, "file")
880    }
881
882    /// A path to a resource file to display.
883    pub fn resource(&self) -> Option<glib::GString> {
884        ObjectExt::property(self, "resource")
885    }
886
887    /// Whether the icon displayed in the [`Image`][crate::Image] will use
888    /// standard icon names fallback.
889    ///
890    /// The value of this property is only relevant for images of type
891    /// [`ImageType::IconName`][crate::ImageType::IconName] and [`ImageType::Gicon`][crate::ImageType::Gicon].
892    #[doc(alias = "use-fallback")]
893    pub fn uses_fallback(&self) -> bool {
894        ObjectExt::property(self, "use-fallback")
895    }
896
897    /// Whether the icon displayed in the [`Image`][crate::Image] will use
898    /// standard icon names fallback.
899    ///
900    /// The value of this property is only relevant for images of type
901    /// [`ImageType::IconName`][crate::ImageType::IconName] and [`ImageType::Gicon`][crate::ImageType::Gicon].
902    #[doc(alias = "use-fallback")]
903    pub fn set_use_fallback(&self, use_fallback: bool) {
904        ObjectExt::set_property(self, "use-fallback", use_fallback)
905    }
906
907    #[doc(alias = "file")]
908    pub fn connect_file_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
909        unsafe extern "C" fn notify_file_trampoline<F: Fn(&Image) + 'static>(
910            this: *mut ffi::GtkImage,
911            _param_spec: glib::ffi::gpointer,
912            f: glib::ffi::gpointer,
913        ) {
914            unsafe {
915                let f: &F = &*(f as *const F);
916                f(&from_glib_borrow(this))
917            }
918        }
919        unsafe {
920            let f: Box_<F> = Box_::new(f);
921            connect_raw(
922                self.as_ptr() as *mut _,
923                c"notify::file".as_ptr(),
924                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
925                    notify_file_trampoline::<F> as *const (),
926                )),
927                Box_::into_raw(f),
928            )
929        }
930    }
931
932    #[doc(alias = "gicon")]
933    pub fn connect_gicon_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
934        unsafe extern "C" fn notify_gicon_trampoline<F: Fn(&Image) + 'static>(
935            this: *mut ffi::GtkImage,
936            _param_spec: glib::ffi::gpointer,
937            f: glib::ffi::gpointer,
938        ) {
939            unsafe {
940                let f: &F = &*(f as *const F);
941                f(&from_glib_borrow(this))
942            }
943        }
944        unsafe {
945            let f: Box_<F> = Box_::new(f);
946            connect_raw(
947                self.as_ptr() as *mut _,
948                c"notify::gicon".as_ptr(),
949                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
950                    notify_gicon_trampoline::<F> as *const (),
951                )),
952                Box_::into_raw(f),
953            )
954        }
955    }
956
957    #[doc(alias = "icon-name")]
958    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
959        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Image) + 'static>(
960            this: *mut ffi::GtkImage,
961            _param_spec: glib::ffi::gpointer,
962            f: glib::ffi::gpointer,
963        ) {
964            unsafe {
965                let f: &F = &*(f as *const F);
966                f(&from_glib_borrow(this))
967            }
968        }
969        unsafe {
970            let f: Box_<F> = Box_::new(f);
971            connect_raw(
972                self.as_ptr() as *mut _,
973                c"notify::icon-name".as_ptr(),
974                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
975                    notify_icon_name_trampoline::<F> as *const (),
976                )),
977                Box_::into_raw(f),
978            )
979        }
980    }
981
982    #[doc(alias = "icon-size")]
983    pub fn connect_icon_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
984        unsafe extern "C" fn notify_icon_size_trampoline<F: Fn(&Image) + 'static>(
985            this: *mut ffi::GtkImage,
986            _param_spec: glib::ffi::gpointer,
987            f: glib::ffi::gpointer,
988        ) {
989            unsafe {
990                let f: &F = &*(f as *const F);
991                f(&from_glib_borrow(this))
992            }
993        }
994        unsafe {
995            let f: Box_<F> = Box_::new(f);
996            connect_raw(
997                self.as_ptr() as *mut _,
998                c"notify::icon-size".as_ptr(),
999                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1000                    notify_icon_size_trampoline::<F> as *const (),
1001                )),
1002                Box_::into_raw(f),
1003            )
1004        }
1005    }
1006
1007    #[doc(alias = "paintable")]
1008    pub fn connect_paintable_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1009        unsafe extern "C" fn notify_paintable_trampoline<F: Fn(&Image) + 'static>(
1010            this: *mut ffi::GtkImage,
1011            _param_spec: glib::ffi::gpointer,
1012            f: glib::ffi::gpointer,
1013        ) {
1014            unsafe {
1015                let f: &F = &*(f as *const F);
1016                f(&from_glib_borrow(this))
1017            }
1018        }
1019        unsafe {
1020            let f: Box_<F> = Box_::new(f);
1021            connect_raw(
1022                self.as_ptr() as *mut _,
1023                c"notify::paintable".as_ptr(),
1024                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1025                    notify_paintable_trampoline::<F> as *const (),
1026                )),
1027                Box_::into_raw(f),
1028            )
1029        }
1030    }
1031
1032    #[doc(alias = "pixel-size")]
1033    pub fn connect_pixel_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1034        unsafe extern "C" fn notify_pixel_size_trampoline<F: Fn(&Image) + 'static>(
1035            this: *mut ffi::GtkImage,
1036            _param_spec: glib::ffi::gpointer,
1037            f: glib::ffi::gpointer,
1038        ) {
1039            unsafe {
1040                let f: &F = &*(f as *const F);
1041                f(&from_glib_borrow(this))
1042            }
1043        }
1044        unsafe {
1045            let f: Box_<F> = Box_::new(f);
1046            connect_raw(
1047                self.as_ptr() as *mut _,
1048                c"notify::pixel-size".as_ptr(),
1049                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1050                    notify_pixel_size_trampoline::<F> as *const (),
1051                )),
1052                Box_::into_raw(f),
1053            )
1054        }
1055    }
1056
1057    #[doc(alias = "resource")]
1058    pub fn connect_resource_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1059        unsafe extern "C" fn notify_resource_trampoline<F: Fn(&Image) + 'static>(
1060            this: *mut ffi::GtkImage,
1061            _param_spec: glib::ffi::gpointer,
1062            f: glib::ffi::gpointer,
1063        ) {
1064            unsafe {
1065                let f: &F = &*(f as *const F);
1066                f(&from_glib_borrow(this))
1067            }
1068        }
1069        unsafe {
1070            let f: Box_<F> = Box_::new(f);
1071            connect_raw(
1072                self.as_ptr() as *mut _,
1073                c"notify::resource".as_ptr(),
1074                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1075                    notify_resource_trampoline::<F> as *const (),
1076                )),
1077                Box_::into_raw(f),
1078            )
1079        }
1080    }
1081
1082    #[doc(alias = "storage-type")]
1083    pub fn connect_storage_type_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1084        unsafe extern "C" fn notify_storage_type_trampoline<F: Fn(&Image) + 'static>(
1085            this: *mut ffi::GtkImage,
1086            _param_spec: glib::ffi::gpointer,
1087            f: glib::ffi::gpointer,
1088        ) {
1089            unsafe {
1090                let f: &F = &*(f as *const F);
1091                f(&from_glib_borrow(this))
1092            }
1093        }
1094        unsafe {
1095            let f: Box_<F> = Box_::new(f);
1096            connect_raw(
1097                self.as_ptr() as *mut _,
1098                c"notify::storage-type".as_ptr(),
1099                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1100                    notify_storage_type_trampoline::<F> as *const (),
1101                )),
1102                Box_::into_raw(f),
1103            )
1104        }
1105    }
1106
1107    #[doc(alias = "use-fallback")]
1108    pub fn connect_use_fallback_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
1109        unsafe extern "C" fn notify_use_fallback_trampoline<F: Fn(&Image) + 'static>(
1110            this: *mut ffi::GtkImage,
1111            _param_spec: glib::ffi::gpointer,
1112            f: glib::ffi::gpointer,
1113        ) {
1114            unsafe {
1115                let f: &F = &*(f as *const F);
1116                f(&from_glib_borrow(this))
1117            }
1118        }
1119        unsafe {
1120            let f: Box_<F> = Box_::new(f);
1121            connect_raw(
1122                self.as_ptr() as *mut _,
1123                c"notify::use-fallback".as_ptr(),
1124                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
1125                    notify_use_fallback_trampoline::<F> as *const (),
1126                )),
1127                Box_::into_raw(f),
1128            )
1129        }
1130    }
1131}
1132
1133impl Default for Image {
1134    fn default() -> Self {
1135        Self::new()
1136    }
1137}
1138
1139// rustdoc-stripper-ignore-next
1140/// A [builder-pattern] type to construct [`Image`] objects.
1141///
1142/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
1143#[must_use = "The builder must be built to be used"]
1144pub struct ImageBuilder {
1145    builder: glib::object::ObjectBuilder<'static, Image>,
1146}
1147
1148impl ImageBuilder {
1149    fn new() -> Self {
1150        Self {
1151            builder: glib::object::Object::builder(),
1152        }
1153    }
1154
1155    /// A path to the file to display.
1156    pub fn file(self, file: impl Into<glib::GString>) -> Self {
1157        Self {
1158            builder: self.builder.property("file", file.into()),
1159        }
1160    }
1161
1162    /// The `GIcon` displayed in the GtkImage.
1163    ///
1164    /// For themed icons, If the icon theme is changed, the image will be updated
1165    /// automatically.
1166    pub fn gicon(self, gicon: &impl IsA<gio::Icon>) -> Self {
1167        Self {
1168            builder: self.builder.property("gicon", gicon.clone().upcast()),
1169        }
1170    }
1171
1172    /// The name of the icon in the icon theme.
1173    ///
1174    /// If the icon theme is changed, the image will be updated automatically.
1175    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
1176        Self {
1177            builder: self.builder.property("icon-name", icon_name.into()),
1178        }
1179    }
1180
1181    /// The symbolic size to display icons at.
1182    pub fn icon_size(self, icon_size: IconSize) -> Self {
1183        Self {
1184            builder: self.builder.property("icon-size", icon_size),
1185        }
1186    }
1187
1188    /// The [`gdk::Paintable`][crate::gdk::Paintable] to display.
1189    pub fn paintable(self, paintable: &impl IsA<gdk::Paintable>) -> Self {
1190        Self {
1191            builder: self
1192                .builder
1193                .property("paintable", paintable.clone().upcast()),
1194        }
1195    }
1196
1197    /// The size in pixels to display icons at.
1198    ///
1199    /// If set to a value != -1, this property overrides the
1200    /// [`icon-size`][struct@crate::Image#icon-size] property for images of type
1201    /// `GTK_IMAGE_ICON_NAME`.
1202    pub fn pixel_size(self, pixel_size: i32) -> Self {
1203        Self {
1204            builder: self.builder.property("pixel-size", pixel_size),
1205        }
1206    }
1207
1208    /// A path to a resource file to display.
1209    pub fn resource(self, resource: impl Into<glib::GString>) -> Self {
1210        Self {
1211            builder: self.builder.property("resource", resource.into()),
1212        }
1213    }
1214
1215    /// Whether the icon displayed in the [`Image`][crate::Image] will use
1216    /// standard icon names fallback.
1217    ///
1218    /// The value of this property is only relevant for images of type
1219    /// [`ImageType::IconName`][crate::ImageType::IconName] and [`ImageType::Gicon`][crate::ImageType::Gicon].
1220    pub fn use_fallback(self, use_fallback: bool) -> Self {
1221        Self {
1222            builder: self.builder.property("use-fallback", use_fallback),
1223        }
1224    }
1225
1226    /// Whether the widget or any of its descendents can accept
1227    /// the input focus.
1228    ///
1229    /// This property is meant to be set by widget implementations,
1230    /// typically in their instance init function.
1231    pub fn can_focus(self, can_focus: bool) -> Self {
1232        Self {
1233            builder: self.builder.property("can-focus", can_focus),
1234        }
1235    }
1236
1237    /// Whether the widget can receive pointer events.
1238    pub fn can_target(self, can_target: bool) -> Self {
1239        Self {
1240            builder: self.builder.property("can-target", can_target),
1241        }
1242    }
1243
1244    /// A list of css classes applied to this widget.
1245    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
1246        Self {
1247            builder: self.builder.property("css-classes", css_classes.into()),
1248        }
1249    }
1250
1251    /// The name of this widget in the CSS tree.
1252    ///
1253    /// This property is meant to be set by widget implementations,
1254    /// typically in their instance init function.
1255    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
1256        Self {
1257            builder: self.builder.property("css-name", css_name.into()),
1258        }
1259    }
1260
1261    /// The cursor used by @widget.
1262    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
1263        Self {
1264            builder: self.builder.property("cursor", cursor.clone()),
1265        }
1266    }
1267
1268    /// Whether the widget should grab focus when it is clicked with the mouse.
1269    ///
1270    /// This property is only relevant for widgets that can take focus.
1271    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
1272        Self {
1273            builder: self.builder.property("focus-on-click", focus_on_click),
1274        }
1275    }
1276
1277    /// Whether this widget itself will accept the input focus.
1278    pub fn focusable(self, focusable: bool) -> Self {
1279        Self {
1280            builder: self.builder.property("focusable", focusable),
1281        }
1282    }
1283
1284    /// How to distribute horizontal space if widget gets extra space.
1285    pub fn halign(self, halign: Align) -> Self {
1286        Self {
1287            builder: self.builder.property("halign", halign),
1288        }
1289    }
1290
1291    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::Widget#query-tooltip]
1292    /// signal on @widget.
1293    ///
1294    /// A true value indicates that @widget can have a tooltip, in this case
1295    /// the widget will be queried using [`query-tooltip`][struct@crate::Widget#query-tooltip] to
1296    /// determine whether it will provide a tooltip or not.
1297    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
1298        Self {
1299            builder: self.builder.property("has-tooltip", has_tooltip),
1300        }
1301    }
1302
1303    /// Overrides for height request of the widget.
1304    ///
1305    /// If this is -1, the natural request will be used.
1306    pub fn height_request(self, height_request: i32) -> Self {
1307        Self {
1308            builder: self.builder.property("height-request", height_request),
1309        }
1310    }
1311
1312    /// Whether to expand horizontally.
1313    pub fn hexpand(self, hexpand: bool) -> Self {
1314        Self {
1315            builder: self.builder.property("hexpand", hexpand),
1316        }
1317    }
1318
1319    /// Whether to use the `hexpand` property.
1320    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
1321        Self {
1322            builder: self.builder.property("hexpand-set", hexpand_set),
1323        }
1324    }
1325
1326    /// The [`LayoutManager`][crate::LayoutManager] instance to use to compute
1327    /// the preferred size of the widget, and allocate its children.
1328    ///
1329    /// This property is meant to be set by widget implementations,
1330    /// typically in their instance init function.
1331    pub fn layout_manager(self, layout_manager: &impl IsA<LayoutManager>) -> Self {
1332        Self {
1333            builder: self
1334                .builder
1335                .property("layout-manager", layout_manager.clone().upcast()),
1336        }
1337    }
1338
1339    /// Makes this widget act like a modal dialog, with respect to
1340    /// event delivery.
1341    ///
1342    /// Global event controllers will not handle events with targets
1343    /// inside the widget, unless they are set up to ignore propagation
1344    /// limits. See [`EventControllerExt::set_propagation_limit()`][crate::prelude::EventControllerExt::set_propagation_limit()].
1345    #[cfg(feature = "v4_18")]
1346    #[cfg_attr(docsrs, doc(cfg(feature = "v4_18")))]
1347    pub fn limit_events(self, limit_events: bool) -> Self {
1348        Self {
1349            builder: self.builder.property("limit-events", limit_events),
1350        }
1351    }
1352
1353    /// Margin on bottom side of widget.
1354    ///
1355    /// This property adds margin outside of the widget's normal size
1356    /// request, the margin will be added in addition to the size from
1357    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1358    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
1359        Self {
1360            builder: self.builder.property("margin-bottom", margin_bottom),
1361        }
1362    }
1363
1364    /// Margin on end of widget, horizontally.
1365    ///
1366    /// This property supports left-to-right and right-to-left text
1367    /// directions.
1368    ///
1369    /// This property adds margin outside of the widget's normal size
1370    /// request, the margin will be added in addition to the size from
1371    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1372    pub fn margin_end(self, margin_end: i32) -> Self {
1373        Self {
1374            builder: self.builder.property("margin-end", margin_end),
1375        }
1376    }
1377
1378    /// Margin on start of widget, horizontally.
1379    ///
1380    /// This property supports left-to-right and right-to-left text
1381    /// directions.
1382    ///
1383    /// This property adds margin outside of the widget's normal size
1384    /// request, the margin will be added in addition to the size from
1385    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1386    pub fn margin_start(self, margin_start: i32) -> Self {
1387        Self {
1388            builder: self.builder.property("margin-start", margin_start),
1389        }
1390    }
1391
1392    /// Margin on top side of widget.
1393    ///
1394    /// This property adds margin outside of the widget's normal size
1395    /// request, the margin will be added in addition to the size from
1396    /// [`WidgetExt::set_size_request()`][crate::prelude::WidgetExt::set_size_request()] for example.
1397    pub fn margin_top(self, margin_top: i32) -> Self {
1398        Self {
1399            builder: self.builder.property("margin-top", margin_top),
1400        }
1401    }
1402
1403    /// The name of the widget.
1404    pub fn name(self, name: impl Into<glib::GString>) -> Self {
1405        Self {
1406            builder: self.builder.property("name", name.into()),
1407        }
1408    }
1409
1410    /// The requested opacity of the widget.
1411    pub fn opacity(self, opacity: f64) -> Self {
1412        Self {
1413            builder: self.builder.property("opacity", opacity),
1414        }
1415    }
1416
1417    /// How content outside the widget's content area is treated.
1418    ///
1419    /// This property is meant to be set by widget implementations,
1420    /// typically in their instance init function.
1421    pub fn overflow(self, overflow: Overflow) -> Self {
1422        Self {
1423            builder: self.builder.property("overflow", overflow),
1424        }
1425    }
1426
1427    /// Whether the widget will receive the default action when it is focused.
1428    pub fn receives_default(self, receives_default: bool) -> Self {
1429        Self {
1430            builder: self.builder.property("receives-default", receives_default),
1431        }
1432    }
1433
1434    /// Whether the widget responds to input.
1435    pub fn sensitive(self, sensitive: bool) -> Self {
1436        Self {
1437            builder: self.builder.property("sensitive", sensitive),
1438        }
1439    }
1440
1441    /// Sets the text of tooltip to be the given string, which is marked up
1442    /// with Pango markup.
1443    ///
1444    /// Also see [`Tooltip::set_markup()`][crate::Tooltip::set_markup()].
1445    ///
1446    /// This is a convenience property which will take care of getting the
1447    /// tooltip shown if the given string is not `NULL`:
1448    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1449    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1450    /// the default signal handler.
1451    ///
1452    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1453    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1454    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
1455        Self {
1456            builder: self
1457                .builder
1458                .property("tooltip-markup", tooltip_markup.into()),
1459        }
1460    }
1461
1462    /// Sets the text of tooltip to be the given string.
1463    ///
1464    /// Also see [`Tooltip::set_text()`][crate::Tooltip::set_text()].
1465    ///
1466    /// This is a convenience property which will take care of getting the
1467    /// tooltip shown if the given string is not `NULL`:
1468    /// [`has-tooltip`][struct@crate::Widget#has-tooltip] will automatically be set to true
1469    /// and there will be taken care of [`query-tooltip`][struct@crate::Widget#query-tooltip] in
1470    /// the default signal handler.
1471    ///
1472    /// Note that if both [`tooltip-text`][struct@crate::Widget#tooltip-text] and
1473    /// [`tooltip-markup`][struct@crate::Widget#tooltip-markup] are set, the last one wins.
1474    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1475        Self {
1476            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1477        }
1478    }
1479
1480    /// How to distribute vertical space if widget gets extra space.
1481    pub fn valign(self, valign: Align) -> Self {
1482        Self {
1483            builder: self.builder.property("valign", valign),
1484        }
1485    }
1486
1487    /// Whether to expand vertically.
1488    pub fn vexpand(self, vexpand: bool) -> Self {
1489        Self {
1490            builder: self.builder.property("vexpand", vexpand),
1491        }
1492    }
1493
1494    /// Whether to use the `vexpand` property.
1495    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1496        Self {
1497            builder: self.builder.property("vexpand-set", vexpand_set),
1498        }
1499    }
1500
1501    /// Whether the widget is visible.
1502    pub fn visible(self, visible: bool) -> Self {
1503        Self {
1504            builder: self.builder.property("visible", visible),
1505        }
1506    }
1507
1508    /// Overrides for width request of the widget.
1509    ///
1510    /// If this is -1, the natural request will be used.
1511    pub fn width_request(self, width_request: i32) -> Self {
1512        Self {
1513            builder: self.builder.property("width-request", width_request),
1514        }
1515    }
1516
1517    /// The accessible role of the given [`Accessible`][crate::Accessible] implementation.
1518    ///
1519    /// The accessible role cannot be changed once set.
1520    pub fn accessible_role(self, accessible_role: AccessibleRole) -> Self {
1521        Self {
1522            builder: self.builder.property("accessible-role", accessible_role),
1523        }
1524    }
1525
1526    // rustdoc-stripper-ignore-next
1527    /// Build the [`Image`].
1528    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1529    pub fn build(self) -> Image {
1530        assert_initialized_main_thread!();
1531        self.builder.build()
1532    }
1533}