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