Skip to main content

libadwaita/auto/
avatar.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from
3// from gir-files (https://github.com/gtk-rs/gir-files.git)
4// DO NOT EDIT
5
6use crate::ffi;
7use glib::{
8    prelude::*,
9    signal::{SignalHandlerId, connect_raw},
10    translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15    /// A widget displaying an image, with a generated fallback.
16    ///
17    /// <picture>
18    ///   <source srcset="avatar-dark.png" media="(prefers-color-scheme: dark)">
19    ///   <img src="avatar.png" alt="avatar">
20    /// </picture>
21    ///
22    /// [`Avatar`][crate::Avatar] is a widget that shows a round avatar.
23    ///
24    /// [`Avatar`][crate::Avatar] generates an avatar with the initials of  the
25    /// [`text`][struct@crate::Avatar#text] on top of a colored background.
26    ///
27    /// The color is picked based on the hash of the [`text`][struct@crate::Avatar#text].
28    ///
29    /// If [`show-initials`][struct@crate::Avatar#show-initials] is set to `FALSE`,
30    /// [`icon-name`][struct@crate::Avatar#icon-name] or `adw-avatar-default-symbolic` is shown instead
31    /// of the initials.
32    ///
33    /// Use [`custom-image`][struct@crate::Avatar#custom-image] to set a custom image.
34    ///
35    /// ## CSS nodes
36    ///
37    /// [`Avatar`][crate::Avatar] has a single CSS node with name `avatar`.
38    ///
39    /// ## Accessibility
40    ///
41    /// [`Avatar`][crate::Avatar] uses the [enum@Gtk.AccessibleRole.img] role.
42    ///
43    /// ## Properties
44    ///
45    ///
46    /// #### `custom-image`
47    ///  A custom image paintable.
48    ///
49    /// Custom image is displayed instead of initials or icon.
50    ///
51    /// Readable | Writeable
52    ///
53    ///
54    /// #### `icon-name`
55    ///  The name of an icon to use as a fallback.
56    ///
57    /// If no name is set, `adw-avatar-default-symbolic` will be used.
58    ///
59    /// Readable | Writeable
60    ///
61    ///
62    /// #### `show-initials`
63    ///  Whether initials are used instead of an icon on the fallback avatar.
64    ///
65    /// See [`icon-name`][struct@crate::Avatar#icon-name] for how to change the fallback icon.
66    ///
67    /// Readable | Writeable
68    ///
69    ///
70    /// #### `size`
71    ///  The size of the avatar.
72    ///
73    /// Readable | Writeable
74    ///
75    ///
76    /// #### `text`
77    ///  Sets the text used to generate the fallback initials and color.
78    ///
79    /// It's only used to generate the color if [`show-initials`][struct@crate::Avatar#show-initials] is
80    /// `FALSE`.
81    ///
82    /// Readable | Writeable
83    /// <details><summary><h4>Widget</h4></summary>
84    ///
85    ///
86    /// #### `can-focus`
87    ///  Whether the widget or any of its descendents can accept
88    /// the input focus.
89    ///
90    /// This property is meant to be set by widget implementations,
91    /// typically in their instance init function.
92    ///
93    /// Readable | Writeable
94    ///
95    ///
96    /// #### `can-target`
97    ///  Whether the widget can receive pointer events.
98    ///
99    /// Readable | Writeable
100    ///
101    ///
102    /// #### `css-classes`
103    ///  A list of css classes applied to this widget.
104    ///
105    /// Readable | Writeable
106    ///
107    ///
108    /// #### `css-name`
109    ///  The name of this widget in the CSS tree.
110    ///
111    /// This property is meant to be set by widget implementations,
112    /// typically in their instance init function.
113    ///
114    /// Readable | Writeable | Construct Only
115    ///
116    ///
117    /// #### `cursor`
118    ///  The cursor used by @widget.
119    ///
120    /// Readable | Writeable
121    ///
122    ///
123    /// #### `focus-on-click`
124    ///  Whether the widget should grab focus when it is clicked with the mouse.
125    ///
126    /// This property is only relevant for widgets that can take focus.
127    ///
128    /// Readable | Writeable
129    ///
130    ///
131    /// #### `focusable`
132    ///  Whether this widget itself will accept the input focus.
133    ///
134    /// Readable | Writeable
135    ///
136    ///
137    /// #### `halign`
138    ///  How to distribute horizontal space if widget gets extra space.
139    ///
140    /// Readable | Writeable
141    ///
142    ///
143    /// #### `has-default`
144    ///  Whether the widget is the default widget.
145    ///
146    /// Readable
147    ///
148    ///
149    /// #### `has-focus`
150    ///  Whether the widget has the input focus.
151    ///
152    /// Readable
153    ///
154    ///
155    /// #### `has-tooltip`
156    ///  Enables or disables the emission of the [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip]
157    /// signal on @widget.
158    ///
159    /// A true value indicates that @widget can have a tooltip, in this case
160    /// the widget will be queried using [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] to
161    /// determine whether it will provide a tooltip or not.
162    ///
163    /// Readable | Writeable
164    ///
165    ///
166    /// #### `height-request`
167    ///  Overrides for height request of the widget.
168    ///
169    /// If this is -1, the natural request will be used.
170    ///
171    /// Readable | Writeable
172    ///
173    ///
174    /// #### `hexpand`
175    ///  Whether to expand horizontally.
176    ///
177    /// Readable | Writeable
178    ///
179    ///
180    /// #### `hexpand-set`
181    ///  Whether to use the `hexpand` property.
182    ///
183    /// Readable | Writeable
184    ///
185    ///
186    /// #### `layout-manager`
187    ///  The [`gtk::LayoutManager`][crate::gtk::LayoutManager] instance to use to compute
188    /// the preferred size of the widget, and allocate its children.
189    ///
190    /// This property is meant to be set by widget implementations,
191    /// typically in their instance init function.
192    ///
193    /// Readable | Writeable
194    ///
195    ///
196    /// #### `limit-events`
197    ///  Makes this widget act like a modal dialog, with respect to
198    /// event delivery.
199    ///
200    /// Global event controllers will not handle events with targets
201    /// inside the widget, unless they are set up to ignore propagation
202    /// limits. See `Gtk::EventController::set_propagation_limit()`.
203    ///
204    /// Readable | Writeable
205    ///
206    ///
207    /// #### `margin-bottom`
208    ///  Margin on bottom side of widget.
209    ///
210    /// This property adds margin outside of the widget's normal size
211    /// request, the margin will be added in addition to the size from
212    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
213    ///
214    /// Readable | Writeable
215    ///
216    ///
217    /// #### `margin-end`
218    ///  Margin on end of widget, horizontally.
219    ///
220    /// This property supports left-to-right and right-to-left text
221    /// directions.
222    ///
223    /// This property adds margin outside of the widget's normal size
224    /// request, the margin will be added in addition to the size from
225    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
226    ///
227    /// Readable | Writeable
228    ///
229    ///
230    /// #### `margin-start`
231    ///  Margin on start of widget, horizontally.
232    ///
233    /// This property supports left-to-right and right-to-left text
234    /// directions.
235    ///
236    /// This property adds margin outside of the widget's normal size
237    /// request, the margin will be added in addition to the size from
238    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
239    ///
240    /// Readable | Writeable
241    ///
242    ///
243    /// #### `margin-top`
244    ///  Margin on top side of widget.
245    ///
246    /// This property adds margin outside of the widget's normal size
247    /// request, the margin will be added in addition to the size from
248    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
249    ///
250    /// Readable | Writeable
251    ///
252    ///
253    /// #### `name`
254    ///  The name of the widget.
255    ///
256    /// Readable | Writeable
257    ///
258    ///
259    /// #### `opacity`
260    ///  The requested opacity of the widget.
261    ///
262    /// Readable | Writeable
263    ///
264    ///
265    /// #### `overflow`
266    ///  How content outside the widget's content area is treated.
267    ///
268    /// This property is meant to be set by widget implementations,
269    /// typically in their instance init function.
270    ///
271    /// Readable | Writeable
272    ///
273    ///
274    /// #### `parent`
275    ///  The parent widget of this widget.
276    ///
277    /// Readable
278    ///
279    ///
280    /// #### `receives-default`
281    ///  Whether the widget will receive the default action when it is focused.
282    ///
283    /// Readable | Writeable
284    ///
285    ///
286    /// #### `root`
287    ///  The [`gtk::Root`][crate::gtk::Root] widget of the widget tree containing this widget.
288    ///
289    /// This will be `NULL` if the widget is not contained in a root widget.
290    ///
291    /// Readable
292    ///
293    ///
294    /// #### `scale-factor`
295    ///  The scale factor of the widget.
296    ///
297    /// Readable
298    ///
299    ///
300    /// #### `sensitive`
301    ///  Whether the widget responds to input.
302    ///
303    /// Readable | Writeable
304    ///
305    ///
306    /// #### `tooltip-markup`
307    ///  Sets the text of tooltip to be the given string, which is marked up
308    /// with Pango markup.
309    ///
310    /// Also see `Gtk::Tooltip::set_markup()`.
311    ///
312    /// This is a convenience property which will take care of getting the
313    /// tooltip shown if the given string is not `NULL`:
314    /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
315    /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
316    /// the default signal handler.
317    ///
318    /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
319    /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
320    ///
321    /// Readable | Writeable
322    ///
323    ///
324    /// #### `tooltip-text`
325    ///  Sets the text of tooltip to be the given string.
326    ///
327    /// Also see `Gtk::Tooltip::set_text()`.
328    ///
329    /// This is a convenience property which will take care of getting the
330    /// tooltip shown if the given string is not `NULL`:
331    /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
332    /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
333    /// the default signal handler.
334    ///
335    /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
336    /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
337    ///
338    /// Readable | Writeable
339    ///
340    ///
341    /// #### `valign`
342    ///  How to distribute vertical space if widget gets extra space.
343    ///
344    /// Readable | Writeable
345    ///
346    ///
347    /// #### `vexpand`
348    ///  Whether to expand vertically.
349    ///
350    /// Readable | Writeable
351    ///
352    ///
353    /// #### `vexpand-set`
354    ///  Whether to use the `vexpand` property.
355    ///
356    /// Readable | Writeable
357    ///
358    ///
359    /// #### `visible`
360    ///  Whether the widget is visible.
361    ///
362    /// Readable | Writeable
363    ///
364    ///
365    /// #### `width-request`
366    ///  Overrides for width request of the widget.
367    ///
368    /// If this is -1, the natural request will be used.
369    ///
370    /// Readable | Writeable
371    /// </details>
372    /// <details><summary><h4>Accessible</h4></summary>
373    ///
374    ///
375    /// #### `accessible-role`
376    ///  The accessible role of the given [`gtk::Accessible`][crate::gtk::Accessible] implementation.
377    ///
378    /// The accessible role cannot be changed once set.
379    ///
380    /// Readable | Writeable
381    /// </details>
382    ///
383    /// # Implements
384    ///
385    /// [`trait@gtk::prelude::WidgetExt`], [`trait@glib::ObjectExt`], [`trait@gtk::prelude::AccessibleExt`], [`trait@gtk::prelude::BuildableExt`], [`trait@gtk::prelude::ConstraintTargetExt`]
386    #[doc(alias = "AdwAvatar")]
387    pub struct Avatar(Object<ffi::AdwAvatar, ffi::AdwAvatarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
388
389    match fn {
390        type_ => || ffi::adw_avatar_get_type(),
391    }
392}
393
394impl Avatar {
395    /// Creates a new [`Avatar`][crate::Avatar].
396    /// ## `size`
397    /// The size of the avatar
398    /// ## `text`
399    /// the text used to get the initials and color
400    /// ## `show_initials`
401    /// whether to use initials instead of an icon as fallback
402    ///
403    /// # Returns
404    ///
405    /// the newly created [`Avatar`][crate::Avatar]
406    #[doc(alias = "adw_avatar_new")]
407    pub fn new(size: i32, text: Option<&str>, show_initials: bool) -> Avatar {
408        assert_initialized_main_thread!();
409        unsafe {
410            gtk::Widget::from_glib_none(ffi::adw_avatar_new(
411                size,
412                text.to_glib_none().0,
413                show_initials.into_glib(),
414            ))
415            .unsafe_cast()
416        }
417    }
418
419    // rustdoc-stripper-ignore-next
420    /// Creates a new builder-pattern struct instance to construct [`Avatar`] objects.
421    ///
422    /// This method returns an instance of [`AvatarBuilder`](crate::builders::AvatarBuilder) which can be used to create [`Avatar`] objects.
423    pub fn builder() -> AvatarBuilder {
424        AvatarBuilder::new()
425    }
426
427    /// Renders @self into a [`gdk::Texture`][crate::gdk::Texture] at @scale_factor.
428    ///
429    /// This can be used to export the fallback avatar.
430    /// ## `scale_factor`
431    /// The scale factor
432    ///
433    /// # Returns
434    ///
435    /// the texture
436    #[doc(alias = "adw_avatar_draw_to_texture")]
437    pub fn draw_to_texture(&self, scale_factor: i32) -> gdk::Texture {
438        unsafe {
439            from_glib_full(ffi::adw_avatar_draw_to_texture(
440                self.to_glib_none().0,
441                scale_factor,
442            ))
443        }
444    }
445
446    /// Gets the custom image paintable.
447    ///
448    /// # Returns
449    ///
450    /// the custom image
451    #[doc(alias = "adw_avatar_get_custom_image")]
452    #[doc(alias = "get_custom_image")]
453    #[doc(alias = "custom-image")]
454    pub fn custom_image(&self) -> Option<gdk::Paintable> {
455        unsafe { from_glib_none(ffi::adw_avatar_get_custom_image(self.to_glib_none().0)) }
456    }
457
458    /// Gets the name of an icon to use as a fallback.
459    ///
460    /// # Returns
461    ///
462    /// the icon name
463    #[doc(alias = "adw_avatar_get_icon_name")]
464    #[doc(alias = "get_icon_name")]
465    #[doc(alias = "icon-name")]
466    pub fn icon_name(&self) -> Option<glib::GString> {
467        unsafe { from_glib_none(ffi::adw_avatar_get_icon_name(self.to_glib_none().0)) }
468    }
469
470    /// Gets whether initials are used instead of an icon on the fallback avatar.
471    ///
472    /// # Returns
473    ///
474    /// whether initials are used instead of an icon as fallback
475    #[doc(alias = "adw_avatar_get_show_initials")]
476    #[doc(alias = "get_show_initials")]
477    #[doc(alias = "show-initials")]
478    pub fn shows_initials(&self) -> bool {
479        unsafe { from_glib(ffi::adw_avatar_get_show_initials(self.to_glib_none().0)) }
480    }
481
482    /// Gets the size of the avatar.
483    ///
484    /// # Returns
485    ///
486    /// the size of the avatar
487    #[doc(alias = "adw_avatar_get_size")]
488    #[doc(alias = "get_size")]
489    pub fn size(&self) -> i32 {
490        unsafe { ffi::adw_avatar_get_size(self.to_glib_none().0) }
491    }
492
493    /// Gets the text used to generate the fallback initials and color.
494    ///
495    /// # Returns
496    ///
497    /// the text used to generate the fallback initials and
498    ///   color
499    #[doc(alias = "adw_avatar_get_text")]
500    #[doc(alias = "get_text")]
501    pub fn text(&self) -> Option<glib::GString> {
502        unsafe { from_glib_none(ffi::adw_avatar_get_text(self.to_glib_none().0)) }
503    }
504
505    /// Sets the custom image paintable.
506    ///
507    /// Custom image is displayed instead of initials or icon.
508    /// ## `custom_image`
509    /// a custom image
510    #[doc(alias = "adw_avatar_set_custom_image")]
511    #[doc(alias = "custom-image")]
512    pub fn set_custom_image(&self, custom_image: Option<&impl IsA<gdk::Paintable>>) {
513        unsafe {
514            ffi::adw_avatar_set_custom_image(
515                self.to_glib_none().0,
516                custom_image.map(|p| p.as_ref()).to_glib_none().0,
517            );
518        }
519    }
520
521    /// Sets the name of an icon to use as a fallback.
522    ///
523    /// If no name is set, `adw-avatar-default-symbolic` will be used.
524    /// ## `icon_name`
525    /// the icon name
526    #[doc(alias = "adw_avatar_set_icon_name")]
527    #[doc(alias = "icon-name")]
528    pub fn set_icon_name(&self, icon_name: Option<&str>) {
529        unsafe {
530            ffi::adw_avatar_set_icon_name(self.to_glib_none().0, icon_name.to_glib_none().0);
531        }
532    }
533
534    /// Sets whether to use initials instead of an icon on the fallback avatar.
535    ///
536    /// See [`icon-name`][struct@crate::Avatar#icon-name] for how to change the fallback icon.
537    /// ## `show_initials`
538    /// whether to use initials instead of an icon as fallback
539    #[doc(alias = "adw_avatar_set_show_initials")]
540    #[doc(alias = "show-initials")]
541    pub fn set_show_initials(&self, show_initials: bool) {
542        unsafe {
543            ffi::adw_avatar_set_show_initials(self.to_glib_none().0, show_initials.into_glib());
544        }
545    }
546
547    /// Sets the size of the avatar.
548    /// ## `size`
549    /// The size of the avatar
550    #[doc(alias = "adw_avatar_set_size")]
551    #[doc(alias = "size")]
552    pub fn set_size(&self, size: i32) {
553        unsafe {
554            ffi::adw_avatar_set_size(self.to_glib_none().0, size);
555        }
556    }
557
558    /// Sets the text used to generate the fallback initials and color.
559    ///
560    /// It's only used to generate the color if [`show-initials`][struct@crate::Avatar#show-initials] is
561    /// `FALSE`.
562    /// ## `text`
563    /// the text used to get the initials and color
564    #[doc(alias = "adw_avatar_set_text")]
565    #[doc(alias = "text")]
566    pub fn set_text(&self, text: Option<&str>) {
567        unsafe {
568            ffi::adw_avatar_set_text(self.to_glib_none().0, text.to_glib_none().0);
569        }
570    }
571
572    #[doc(alias = "custom-image")]
573    pub fn connect_custom_image_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
574        unsafe extern "C" fn notify_custom_image_trampoline<F: Fn(&Avatar) + 'static>(
575            this: *mut ffi::AdwAvatar,
576            _param_spec: glib::ffi::gpointer,
577            f: glib::ffi::gpointer,
578        ) {
579            unsafe {
580                let f: &F = &*(f as *const F);
581                f(&from_glib_borrow(this))
582            }
583        }
584        unsafe {
585            let f: Box_<F> = Box_::new(f);
586            connect_raw(
587                self.as_ptr() as *mut _,
588                c"notify::custom-image".as_ptr(),
589                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
590                    notify_custom_image_trampoline::<F> as *const (),
591                )),
592                Box_::into_raw(f),
593            )
594        }
595    }
596
597    #[doc(alias = "icon-name")]
598    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
599        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Avatar) + 'static>(
600            this: *mut ffi::AdwAvatar,
601            _param_spec: glib::ffi::gpointer,
602            f: glib::ffi::gpointer,
603        ) {
604            unsafe {
605                let f: &F = &*(f as *const F);
606                f(&from_glib_borrow(this))
607            }
608        }
609        unsafe {
610            let f: Box_<F> = Box_::new(f);
611            connect_raw(
612                self.as_ptr() as *mut _,
613                c"notify::icon-name".as_ptr(),
614                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
615                    notify_icon_name_trampoline::<F> as *const (),
616                )),
617                Box_::into_raw(f),
618            )
619        }
620    }
621
622    #[doc(alias = "show-initials")]
623    pub fn connect_show_initials_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
624        unsafe extern "C" fn notify_show_initials_trampoline<F: Fn(&Avatar) + 'static>(
625            this: *mut ffi::AdwAvatar,
626            _param_spec: glib::ffi::gpointer,
627            f: glib::ffi::gpointer,
628        ) {
629            unsafe {
630                let f: &F = &*(f as *const F);
631                f(&from_glib_borrow(this))
632            }
633        }
634        unsafe {
635            let f: Box_<F> = Box_::new(f);
636            connect_raw(
637                self.as_ptr() as *mut _,
638                c"notify::show-initials".as_ptr(),
639                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
640                    notify_show_initials_trampoline::<F> as *const (),
641                )),
642                Box_::into_raw(f),
643            )
644        }
645    }
646
647    #[doc(alias = "size")]
648    pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
649        unsafe extern "C" fn notify_size_trampoline<F: Fn(&Avatar) + 'static>(
650            this: *mut ffi::AdwAvatar,
651            _param_spec: glib::ffi::gpointer,
652            f: glib::ffi::gpointer,
653        ) {
654            unsafe {
655                let f: &F = &*(f as *const F);
656                f(&from_glib_borrow(this))
657            }
658        }
659        unsafe {
660            let f: Box_<F> = Box_::new(f);
661            connect_raw(
662                self.as_ptr() as *mut _,
663                c"notify::size".as_ptr(),
664                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
665                    notify_size_trampoline::<F> as *const (),
666                )),
667                Box_::into_raw(f),
668            )
669        }
670    }
671
672    #[doc(alias = "text")]
673    pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
674        unsafe extern "C" fn notify_text_trampoline<F: Fn(&Avatar) + 'static>(
675            this: *mut ffi::AdwAvatar,
676            _param_spec: glib::ffi::gpointer,
677            f: glib::ffi::gpointer,
678        ) {
679            unsafe {
680                let f: &F = &*(f as *const F);
681                f(&from_glib_borrow(this))
682            }
683        }
684        unsafe {
685            let f: Box_<F> = Box_::new(f);
686            connect_raw(
687                self.as_ptr() as *mut _,
688                c"notify::text".as_ptr(),
689                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
690                    notify_text_trampoline::<F> as *const (),
691                )),
692                Box_::into_raw(f),
693            )
694        }
695    }
696}
697
698impl Default for Avatar {
699    fn default() -> Self {
700        glib::object::Object::new::<Self>()
701    }
702}
703
704// rustdoc-stripper-ignore-next
705/// A [builder-pattern] type to construct [`Avatar`] objects.
706///
707/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
708#[must_use = "The builder must be built to be used"]
709pub struct AvatarBuilder {
710    builder: glib::object::ObjectBuilder<'static, Avatar>,
711}
712
713impl AvatarBuilder {
714    fn new() -> Self {
715        Self {
716            builder: glib::object::Object::builder(),
717        }
718    }
719
720    /// A custom image paintable.
721    ///
722    /// Custom image is displayed instead of initials or icon.
723    pub fn custom_image(self, custom_image: &impl IsA<gdk::Paintable>) -> Self {
724        Self {
725            builder: self
726                .builder
727                .property("custom-image", custom_image.clone().upcast()),
728        }
729    }
730
731    /// The name of an icon to use as a fallback.
732    ///
733    /// If no name is set, `adw-avatar-default-symbolic` will be used.
734    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
735        Self {
736            builder: self.builder.property("icon-name", icon_name.into()),
737        }
738    }
739
740    /// Whether initials are used instead of an icon on the fallback avatar.
741    ///
742    /// See [`icon-name`][struct@crate::Avatar#icon-name] for how to change the fallback icon.
743    pub fn show_initials(self, show_initials: bool) -> Self {
744        Self {
745            builder: self.builder.property("show-initials", show_initials),
746        }
747    }
748
749    /// The size of the avatar.
750    pub fn size(self, size: i32) -> Self {
751        Self {
752            builder: self.builder.property("size", size),
753        }
754    }
755
756    /// Sets the text used to generate the fallback initials and color.
757    ///
758    /// It's only used to generate the color if [`show-initials`][struct@crate::Avatar#show-initials] is
759    /// `FALSE`.
760    pub fn text(self, text: impl Into<glib::GString>) -> Self {
761        Self {
762            builder: self.builder.property("text", text.into()),
763        }
764    }
765
766    /// Whether the widget or any of its descendents can accept
767    /// the input focus.
768    ///
769    /// This property is meant to be set by widget implementations,
770    /// typically in their instance init function.
771    pub fn can_focus(self, can_focus: bool) -> Self {
772        Self {
773            builder: self.builder.property("can-focus", can_focus),
774        }
775    }
776
777    /// Whether the widget can receive pointer events.
778    pub fn can_target(self, can_target: bool) -> Self {
779        Self {
780            builder: self.builder.property("can-target", can_target),
781        }
782    }
783
784    /// A list of css classes applied to this widget.
785    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
786        Self {
787            builder: self.builder.property("css-classes", css_classes.into()),
788        }
789    }
790
791    /// The name of this widget in the CSS tree.
792    ///
793    /// This property is meant to be set by widget implementations,
794    /// typically in their instance init function.
795    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
796        Self {
797            builder: self.builder.property("css-name", css_name.into()),
798        }
799    }
800
801    /// The cursor used by @widget.
802    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
803        Self {
804            builder: self.builder.property("cursor", cursor.clone()),
805        }
806    }
807
808    /// Whether the widget should grab focus when it is clicked with the mouse.
809    ///
810    /// This property is only relevant for widgets that can take focus.
811    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
812        Self {
813            builder: self.builder.property("focus-on-click", focus_on_click),
814        }
815    }
816
817    /// Whether this widget itself will accept the input focus.
818    pub fn focusable(self, focusable: bool) -> Self {
819        Self {
820            builder: self.builder.property("focusable", focusable),
821        }
822    }
823
824    /// How to distribute horizontal space if widget gets extra space.
825    pub fn halign(self, halign: gtk::Align) -> Self {
826        Self {
827            builder: self.builder.property("halign", halign),
828        }
829    }
830
831    /// Enables or disables the emission of the [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip]
832    /// signal on @widget.
833    ///
834    /// A true value indicates that @widget can have a tooltip, in this case
835    /// the widget will be queried using [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] to
836    /// determine whether it will provide a tooltip or not.
837    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
838        Self {
839            builder: self.builder.property("has-tooltip", has_tooltip),
840        }
841    }
842
843    /// Overrides for height request of the widget.
844    ///
845    /// If this is -1, the natural request will be used.
846    pub fn height_request(self, height_request: i32) -> Self {
847        Self {
848            builder: self.builder.property("height-request", height_request),
849        }
850    }
851
852    /// Whether to expand horizontally.
853    pub fn hexpand(self, hexpand: bool) -> Self {
854        Self {
855            builder: self.builder.property("hexpand", hexpand),
856        }
857    }
858
859    /// Whether to use the `hexpand` property.
860    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
861        Self {
862            builder: self.builder.property("hexpand-set", hexpand_set),
863        }
864    }
865
866    /// The [`gtk::LayoutManager`][crate::gtk::LayoutManager] instance to use to compute
867    /// the preferred size of the widget, and allocate its children.
868    ///
869    /// This property is meant to be set by widget implementations,
870    /// typically in their instance init function.
871    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
872        Self {
873            builder: self
874                .builder
875                .property("layout-manager", layout_manager.clone().upcast()),
876        }
877    }
878
879    /// Makes this widget act like a modal dialog, with respect to
880    /// event delivery.
881    ///
882    /// Global event controllers will not handle events with targets
883    /// inside the widget, unless they are set up to ignore propagation
884    /// limits. See `Gtk::EventController::set_propagation_limit()`.
885    #[cfg(feature = "gtk_v4_18")]
886    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
887    pub fn limit_events(self, limit_events: bool) -> Self {
888        Self {
889            builder: self.builder.property("limit-events", limit_events),
890        }
891    }
892
893    /// Margin on bottom side of widget.
894    ///
895    /// This property adds margin outside of the widget's normal size
896    /// request, the margin will be added in addition to the size from
897    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
898    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
899        Self {
900            builder: self.builder.property("margin-bottom", margin_bottom),
901        }
902    }
903
904    /// Margin on end of widget, horizontally.
905    ///
906    /// This property supports left-to-right and right-to-left text
907    /// directions.
908    ///
909    /// This property adds margin outside of the widget's normal size
910    /// request, the margin will be added in addition to the size from
911    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
912    pub fn margin_end(self, margin_end: i32) -> Self {
913        Self {
914            builder: self.builder.property("margin-end", margin_end),
915        }
916    }
917
918    /// Margin on start of widget, horizontally.
919    ///
920    /// This property supports left-to-right and right-to-left text
921    /// directions.
922    ///
923    /// This property adds margin outside of the widget's normal size
924    /// request, the margin will be added in addition to the size from
925    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
926    pub fn margin_start(self, margin_start: i32) -> Self {
927        Self {
928            builder: self.builder.property("margin-start", margin_start),
929        }
930    }
931
932    /// Margin on top side of widget.
933    ///
934    /// This property adds margin outside of the widget's normal size
935    /// request, the margin will be added in addition to the size from
936    /// [`WidgetExtManual::set_size_request()`][crate::gtk::prelude::WidgetExtManual::set_size_request()] for example.
937    pub fn margin_top(self, margin_top: i32) -> Self {
938        Self {
939            builder: self.builder.property("margin-top", margin_top),
940        }
941    }
942
943    /// The name of the widget.
944    pub fn name(self, name: impl Into<glib::GString>) -> Self {
945        Self {
946            builder: self.builder.property("name", name.into()),
947        }
948    }
949
950    /// The requested opacity of the widget.
951    pub fn opacity(self, opacity: f64) -> Self {
952        Self {
953            builder: self.builder.property("opacity", opacity),
954        }
955    }
956
957    /// How content outside the widget's content area is treated.
958    ///
959    /// This property is meant to be set by widget implementations,
960    /// typically in their instance init function.
961    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
962        Self {
963            builder: self.builder.property("overflow", overflow),
964        }
965    }
966
967    /// Whether the widget will receive the default action when it is focused.
968    pub fn receives_default(self, receives_default: bool) -> Self {
969        Self {
970            builder: self.builder.property("receives-default", receives_default),
971        }
972    }
973
974    /// Whether the widget responds to input.
975    pub fn sensitive(self, sensitive: bool) -> Self {
976        Self {
977            builder: self.builder.property("sensitive", sensitive),
978        }
979    }
980
981    /// Sets the text of tooltip to be the given string, which is marked up
982    /// with Pango markup.
983    ///
984    /// Also see `Gtk::Tooltip::set_markup()`.
985    ///
986    /// This is a convenience property which will take care of getting the
987    /// tooltip shown if the given string is not `NULL`:
988    /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
989    /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
990    /// the default signal handler.
991    ///
992    /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
993    /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
994    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
995        Self {
996            builder: self
997                .builder
998                .property("tooltip-markup", tooltip_markup.into()),
999        }
1000    }
1001
1002    /// Sets the text of tooltip to be the given string.
1003    ///
1004    /// Also see `Gtk::Tooltip::set_text()`.
1005    ///
1006    /// This is a convenience property which will take care of getting the
1007    /// tooltip shown if the given string is not `NULL`:
1008    /// [`has-tooltip`][struct@crate::gtk::Widget#has-tooltip] will automatically be set to true
1009    /// and there will be taken care of [`query-tooltip`][struct@crate::gtk::Widget#query-tooltip] in
1010    /// the default signal handler.
1011    ///
1012    /// Note that if both [`tooltip-text`][struct@crate::gtk::Widget#tooltip-text] and
1013    /// [`tooltip-markup`][struct@crate::gtk::Widget#tooltip-markup] are set, the last one wins.
1014    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
1015        Self {
1016            builder: self.builder.property("tooltip-text", tooltip_text.into()),
1017        }
1018    }
1019
1020    /// How to distribute vertical space if widget gets extra space.
1021    pub fn valign(self, valign: gtk::Align) -> Self {
1022        Self {
1023            builder: self.builder.property("valign", valign),
1024        }
1025    }
1026
1027    /// Whether to expand vertically.
1028    pub fn vexpand(self, vexpand: bool) -> Self {
1029        Self {
1030            builder: self.builder.property("vexpand", vexpand),
1031        }
1032    }
1033
1034    /// Whether to use the `vexpand` property.
1035    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
1036        Self {
1037            builder: self.builder.property("vexpand-set", vexpand_set),
1038        }
1039    }
1040
1041    /// Whether the widget is visible.
1042    pub fn visible(self, visible: bool) -> Self {
1043        Self {
1044            builder: self.builder.property("visible", visible),
1045        }
1046    }
1047
1048    /// Overrides for width request of the widget.
1049    ///
1050    /// If this is -1, the natural request will be used.
1051    pub fn width_request(self, width_request: i32) -> Self {
1052        Self {
1053            builder: self.builder.property("width-request", width_request),
1054        }
1055    }
1056
1057    /// The accessible role of the given [`gtk::Accessible`][crate::gtk::Accessible] implementation.
1058    ///
1059    /// The accessible role cannot be changed once set.
1060    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
1061        Self {
1062            builder: self.builder.property("accessible-role", accessible_role),
1063        }
1064    }
1065
1066    // rustdoc-stripper-ignore-next
1067    /// Build the [`Avatar`].
1068    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
1069    pub fn build(self) -> Avatar {
1070        assert_initialized_main_thread!();
1071        self.builder.build()
1072    }
1073}