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