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    #[doc(alias = "AdwAvatar")]
16    pub struct Avatar(Object<ffi::AdwAvatar, ffi::AdwAvatarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18    match fn {
19        type_ => || ffi::adw_avatar_get_type(),
20    }
21}
22
23impl Avatar {
24    #[doc(alias = "adw_avatar_new")]
25    pub fn new(size: i32, text: Option<&str>, show_initials: bool) -> Avatar {
26        assert_initialized_main_thread!();
27        unsafe {
28            gtk::Widget::from_glib_none(ffi::adw_avatar_new(
29                size,
30                text.to_glib_none().0,
31                show_initials.into_glib(),
32            ))
33            .unsafe_cast()
34        }
35    }
36
37    // rustdoc-stripper-ignore-next
38    /// Creates a new builder-pattern struct instance to construct [`Avatar`] objects.
39    ///
40    /// This method returns an instance of [`AvatarBuilder`](crate::builders::AvatarBuilder) which can be used to create [`Avatar`] objects.
41    pub fn builder() -> AvatarBuilder {
42        AvatarBuilder::new()
43    }
44
45    #[doc(alias = "adw_avatar_draw_to_texture")]
46    pub fn draw_to_texture(&self, scale_factor: i32) -> gdk::Texture {
47        unsafe {
48            from_glib_full(ffi::adw_avatar_draw_to_texture(
49                self.to_glib_none().0,
50                scale_factor,
51            ))
52        }
53    }
54
55    #[doc(alias = "adw_avatar_get_custom_image")]
56    #[doc(alias = "get_custom_image")]
57    #[doc(alias = "custom-image")]
58    pub fn custom_image(&self) -> Option<gdk::Paintable> {
59        unsafe { from_glib_none(ffi::adw_avatar_get_custom_image(self.to_glib_none().0)) }
60    }
61
62    #[doc(alias = "adw_avatar_get_icon_name")]
63    #[doc(alias = "get_icon_name")]
64    #[doc(alias = "icon-name")]
65    pub fn icon_name(&self) -> Option<glib::GString> {
66        unsafe { from_glib_none(ffi::adw_avatar_get_icon_name(self.to_glib_none().0)) }
67    }
68
69    #[doc(alias = "adw_avatar_get_show_initials")]
70    #[doc(alias = "get_show_initials")]
71    #[doc(alias = "show-initials")]
72    pub fn shows_initials(&self) -> bool {
73        unsafe { from_glib(ffi::adw_avatar_get_show_initials(self.to_glib_none().0)) }
74    }
75
76    #[doc(alias = "adw_avatar_get_size")]
77    #[doc(alias = "get_size")]
78    pub fn size(&self) -> i32 {
79        unsafe { ffi::adw_avatar_get_size(self.to_glib_none().0) }
80    }
81
82    #[doc(alias = "adw_avatar_get_text")]
83    #[doc(alias = "get_text")]
84    pub fn text(&self) -> Option<glib::GString> {
85        unsafe { from_glib_none(ffi::adw_avatar_get_text(self.to_glib_none().0)) }
86    }
87
88    #[doc(alias = "adw_avatar_set_custom_image")]
89    #[doc(alias = "custom-image")]
90    pub fn set_custom_image(&self, custom_image: Option<&impl IsA<gdk::Paintable>>) {
91        unsafe {
92            ffi::adw_avatar_set_custom_image(
93                self.to_glib_none().0,
94                custom_image.map(|p| p.as_ref()).to_glib_none().0,
95            );
96        }
97    }
98
99    #[doc(alias = "adw_avatar_set_icon_name")]
100    #[doc(alias = "icon-name")]
101    pub fn set_icon_name(&self, icon_name: Option<&str>) {
102        unsafe {
103            ffi::adw_avatar_set_icon_name(self.to_glib_none().0, icon_name.to_glib_none().0);
104        }
105    }
106
107    #[doc(alias = "adw_avatar_set_show_initials")]
108    #[doc(alias = "show-initials")]
109    pub fn set_show_initials(&self, show_initials: bool) {
110        unsafe {
111            ffi::adw_avatar_set_show_initials(self.to_glib_none().0, show_initials.into_glib());
112        }
113    }
114
115    #[doc(alias = "adw_avatar_set_size")]
116    #[doc(alias = "size")]
117    pub fn set_size(&self, size: i32) {
118        unsafe {
119            ffi::adw_avatar_set_size(self.to_glib_none().0, size);
120        }
121    }
122
123    #[doc(alias = "adw_avatar_set_text")]
124    #[doc(alias = "text")]
125    pub fn set_text(&self, text: Option<&str>) {
126        unsafe {
127            ffi::adw_avatar_set_text(self.to_glib_none().0, text.to_glib_none().0);
128        }
129    }
130
131    #[doc(alias = "custom-image")]
132    pub fn connect_custom_image_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
133        unsafe extern "C" fn notify_custom_image_trampoline<F: Fn(&Avatar) + 'static>(
134            this: *mut ffi::AdwAvatar,
135            _param_spec: glib::ffi::gpointer,
136            f: glib::ffi::gpointer,
137        ) {
138            unsafe {
139                let f: &F = &*(f as *const F);
140                f(&from_glib_borrow(this))
141            }
142        }
143        unsafe {
144            let f: Box_<F> = Box_::new(f);
145            connect_raw(
146                self.as_ptr() as *mut _,
147                c"notify::custom-image".as_ptr(),
148                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
149                    notify_custom_image_trampoline::<F> as *const (),
150                )),
151                Box_::into_raw(f),
152            )
153        }
154    }
155
156    #[doc(alias = "icon-name")]
157    pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
158        unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Avatar) + 'static>(
159            this: *mut ffi::AdwAvatar,
160            _param_spec: glib::ffi::gpointer,
161            f: glib::ffi::gpointer,
162        ) {
163            unsafe {
164                let f: &F = &*(f as *const F);
165                f(&from_glib_borrow(this))
166            }
167        }
168        unsafe {
169            let f: Box_<F> = Box_::new(f);
170            connect_raw(
171                self.as_ptr() as *mut _,
172                c"notify::icon-name".as_ptr(),
173                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
174                    notify_icon_name_trampoline::<F> as *const (),
175                )),
176                Box_::into_raw(f),
177            )
178        }
179    }
180
181    #[doc(alias = "show-initials")]
182    pub fn connect_show_initials_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
183        unsafe extern "C" fn notify_show_initials_trampoline<F: Fn(&Avatar) + 'static>(
184            this: *mut ffi::AdwAvatar,
185            _param_spec: glib::ffi::gpointer,
186            f: glib::ffi::gpointer,
187        ) {
188            unsafe {
189                let f: &F = &*(f as *const F);
190                f(&from_glib_borrow(this))
191            }
192        }
193        unsafe {
194            let f: Box_<F> = Box_::new(f);
195            connect_raw(
196                self.as_ptr() as *mut _,
197                c"notify::show-initials".as_ptr(),
198                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
199                    notify_show_initials_trampoline::<F> as *const (),
200                )),
201                Box_::into_raw(f),
202            )
203        }
204    }
205
206    #[doc(alias = "size")]
207    pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
208        unsafe extern "C" fn notify_size_trampoline<F: Fn(&Avatar) + 'static>(
209            this: *mut ffi::AdwAvatar,
210            _param_spec: glib::ffi::gpointer,
211            f: glib::ffi::gpointer,
212        ) {
213            unsafe {
214                let f: &F = &*(f as *const F);
215                f(&from_glib_borrow(this))
216            }
217        }
218        unsafe {
219            let f: Box_<F> = Box_::new(f);
220            connect_raw(
221                self.as_ptr() as *mut _,
222                c"notify::size".as_ptr(),
223                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
224                    notify_size_trampoline::<F> as *const (),
225                )),
226                Box_::into_raw(f),
227            )
228        }
229    }
230
231    #[doc(alias = "text")]
232    pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
233        unsafe extern "C" fn notify_text_trampoline<F: Fn(&Avatar) + 'static>(
234            this: *mut ffi::AdwAvatar,
235            _param_spec: glib::ffi::gpointer,
236            f: glib::ffi::gpointer,
237        ) {
238            unsafe {
239                let f: &F = &*(f as *const F);
240                f(&from_glib_borrow(this))
241            }
242        }
243        unsafe {
244            let f: Box_<F> = Box_::new(f);
245            connect_raw(
246                self.as_ptr() as *mut _,
247                c"notify::text".as_ptr(),
248                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
249                    notify_text_trampoline::<F> as *const (),
250                )),
251                Box_::into_raw(f),
252            )
253        }
254    }
255}
256
257impl Default for Avatar {
258    fn default() -> Self {
259        glib::object::Object::new::<Self>()
260    }
261}
262
263// rustdoc-stripper-ignore-next
264/// A [builder-pattern] type to construct [`Avatar`] objects.
265///
266/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
267#[must_use = "The builder must be built to be used"]
268pub struct AvatarBuilder {
269    builder: glib::object::ObjectBuilder<'static, Avatar>,
270}
271
272impl AvatarBuilder {
273    fn new() -> Self {
274        Self {
275            builder: glib::object::Object::builder(),
276        }
277    }
278
279    pub fn custom_image(self, custom_image: &impl IsA<gdk::Paintable>) -> Self {
280        Self {
281            builder: self
282                .builder
283                .property("custom-image", custom_image.clone().upcast()),
284        }
285    }
286
287    pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
288        Self {
289            builder: self.builder.property("icon-name", icon_name.into()),
290        }
291    }
292
293    pub fn show_initials(self, show_initials: bool) -> Self {
294        Self {
295            builder: self.builder.property("show-initials", show_initials),
296        }
297    }
298
299    pub fn size(self, size: i32) -> Self {
300        Self {
301            builder: self.builder.property("size", size),
302        }
303    }
304
305    pub fn text(self, text: impl Into<glib::GString>) -> Self {
306        Self {
307            builder: self.builder.property("text", text.into()),
308        }
309    }
310
311    pub fn can_focus(self, can_focus: bool) -> Self {
312        Self {
313            builder: self.builder.property("can-focus", can_focus),
314        }
315    }
316
317    pub fn can_target(self, can_target: bool) -> Self {
318        Self {
319            builder: self.builder.property("can-target", can_target),
320        }
321    }
322
323    pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
324        Self {
325            builder: self.builder.property("css-classes", css_classes.into()),
326        }
327    }
328
329    pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
330        Self {
331            builder: self.builder.property("css-name", css_name.into()),
332        }
333    }
334
335    pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
336        Self {
337            builder: self.builder.property("cursor", cursor.clone()),
338        }
339    }
340
341    pub fn focus_on_click(self, focus_on_click: bool) -> Self {
342        Self {
343            builder: self.builder.property("focus-on-click", focus_on_click),
344        }
345    }
346
347    pub fn focusable(self, focusable: bool) -> Self {
348        Self {
349            builder: self.builder.property("focusable", focusable),
350        }
351    }
352
353    pub fn halign(self, halign: gtk::Align) -> Self {
354        Self {
355            builder: self.builder.property("halign", halign),
356        }
357    }
358
359    pub fn has_tooltip(self, has_tooltip: bool) -> Self {
360        Self {
361            builder: self.builder.property("has-tooltip", has_tooltip),
362        }
363    }
364
365    pub fn height_request(self, height_request: i32) -> Self {
366        Self {
367            builder: self.builder.property("height-request", height_request),
368        }
369    }
370
371    pub fn hexpand(self, hexpand: bool) -> Self {
372        Self {
373            builder: self.builder.property("hexpand", hexpand),
374        }
375    }
376
377    pub fn hexpand_set(self, hexpand_set: bool) -> Self {
378        Self {
379            builder: self.builder.property("hexpand-set", hexpand_set),
380        }
381    }
382
383    pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
384        Self {
385            builder: self
386                .builder
387                .property("layout-manager", layout_manager.clone().upcast()),
388        }
389    }
390
391    #[cfg(feature = "gtk_v4_18")]
392    #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
393    pub fn limit_events(self, limit_events: bool) -> Self {
394        Self {
395            builder: self.builder.property("limit-events", limit_events),
396        }
397    }
398
399    pub fn margin_bottom(self, margin_bottom: i32) -> Self {
400        Self {
401            builder: self.builder.property("margin-bottom", margin_bottom),
402        }
403    }
404
405    pub fn margin_end(self, margin_end: i32) -> Self {
406        Self {
407            builder: self.builder.property("margin-end", margin_end),
408        }
409    }
410
411    pub fn margin_start(self, margin_start: i32) -> Self {
412        Self {
413            builder: self.builder.property("margin-start", margin_start),
414        }
415    }
416
417    pub fn margin_top(self, margin_top: i32) -> Self {
418        Self {
419            builder: self.builder.property("margin-top", margin_top),
420        }
421    }
422
423    pub fn name(self, name: impl Into<glib::GString>) -> Self {
424        Self {
425            builder: self.builder.property("name", name.into()),
426        }
427    }
428
429    pub fn opacity(self, opacity: f64) -> Self {
430        Self {
431            builder: self.builder.property("opacity", opacity),
432        }
433    }
434
435    pub fn overflow(self, overflow: gtk::Overflow) -> Self {
436        Self {
437            builder: self.builder.property("overflow", overflow),
438        }
439    }
440
441    pub fn receives_default(self, receives_default: bool) -> Self {
442        Self {
443            builder: self.builder.property("receives-default", receives_default),
444        }
445    }
446
447    pub fn sensitive(self, sensitive: bool) -> Self {
448        Self {
449            builder: self.builder.property("sensitive", sensitive),
450        }
451    }
452
453    pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
454        Self {
455            builder: self
456                .builder
457                .property("tooltip-markup", tooltip_markup.into()),
458        }
459    }
460
461    pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
462        Self {
463            builder: self.builder.property("tooltip-text", tooltip_text.into()),
464        }
465    }
466
467    pub fn valign(self, valign: gtk::Align) -> Self {
468        Self {
469            builder: self.builder.property("valign", valign),
470        }
471    }
472
473    pub fn vexpand(self, vexpand: bool) -> Self {
474        Self {
475            builder: self.builder.property("vexpand", vexpand),
476        }
477    }
478
479    pub fn vexpand_set(self, vexpand_set: bool) -> Self {
480        Self {
481            builder: self.builder.property("vexpand-set", vexpand_set),
482        }
483    }
484
485    pub fn visible(self, visible: bool) -> Self {
486        Self {
487            builder: self.builder.property("visible", visible),
488        }
489    }
490
491    pub fn width_request(self, width_request: i32) -> Self {
492        Self {
493            builder: self.builder.property("width-request", width_request),
494        }
495    }
496
497    pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
498        Self {
499            builder: self.builder.property("accessible-role", accessible_role),
500        }
501    }
502
503    // rustdoc-stripper-ignore-next
504    /// Build the [`Avatar`].
505    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
506    pub fn build(self) -> Avatar {
507        assert_initialized_main_thread!();
508        self.builder.build()
509    }
510}