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