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