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