1use crate::ffi;
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
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 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 let f: &F = &*(f as *const F);
139 f(&from_glib_borrow(this))
140 }
141 unsafe {
142 let f: Box_<F> = Box_::new(f);
143 connect_raw(
144 self.as_ptr() as *mut _,
145 c"notify::custom-image".as_ptr() as *const _,
146 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
147 notify_custom_image_trampoline::<F> as *const (),
148 )),
149 Box_::into_raw(f),
150 )
151 }
152 }
153
154 #[doc(alias = "icon-name")]
155 pub fn connect_icon_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
156 unsafe extern "C" fn notify_icon_name_trampoline<F: Fn(&Avatar) + 'static>(
157 this: *mut ffi::AdwAvatar,
158 _param_spec: glib::ffi::gpointer,
159 f: glib::ffi::gpointer,
160 ) {
161 let f: &F = &*(f as *const F);
162 f(&from_glib_borrow(this))
163 }
164 unsafe {
165 let f: Box_<F> = Box_::new(f);
166 connect_raw(
167 self.as_ptr() as *mut _,
168 c"notify::icon-name".as_ptr() as *const _,
169 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
170 notify_icon_name_trampoline::<F> as *const (),
171 )),
172 Box_::into_raw(f),
173 )
174 }
175 }
176
177 #[doc(alias = "show-initials")]
178 pub fn connect_show_initials_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
179 unsafe extern "C" fn notify_show_initials_trampoline<F: Fn(&Avatar) + 'static>(
180 this: *mut ffi::AdwAvatar,
181 _param_spec: glib::ffi::gpointer,
182 f: glib::ffi::gpointer,
183 ) {
184 let f: &F = &*(f as *const F);
185 f(&from_glib_borrow(this))
186 }
187 unsafe {
188 let f: Box_<F> = Box_::new(f);
189 connect_raw(
190 self.as_ptr() as *mut _,
191 c"notify::show-initials".as_ptr() as *const _,
192 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
193 notify_show_initials_trampoline::<F> as *const (),
194 )),
195 Box_::into_raw(f),
196 )
197 }
198 }
199
200 #[doc(alias = "size")]
201 pub fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
202 unsafe extern "C" fn notify_size_trampoline<F: Fn(&Avatar) + 'static>(
203 this: *mut ffi::AdwAvatar,
204 _param_spec: glib::ffi::gpointer,
205 f: glib::ffi::gpointer,
206 ) {
207 let f: &F = &*(f as *const F);
208 f(&from_glib_borrow(this))
209 }
210 unsafe {
211 let f: Box_<F> = Box_::new(f);
212 connect_raw(
213 self.as_ptr() as *mut _,
214 c"notify::size".as_ptr() as *const _,
215 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
216 notify_size_trampoline::<F> as *const (),
217 )),
218 Box_::into_raw(f),
219 )
220 }
221 }
222
223 #[doc(alias = "text")]
224 pub fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
225 unsafe extern "C" fn notify_text_trampoline<F: Fn(&Avatar) + 'static>(
226 this: *mut ffi::AdwAvatar,
227 _param_spec: glib::ffi::gpointer,
228 f: glib::ffi::gpointer,
229 ) {
230 let f: &F = &*(f as *const F);
231 f(&from_glib_borrow(this))
232 }
233 unsafe {
234 let f: Box_<F> = Box_::new(f);
235 connect_raw(
236 self.as_ptr() as *mut _,
237 c"notify::text".as_ptr() as *const _,
238 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
239 notify_text_trampoline::<F> as *const (),
240 )),
241 Box_::into_raw(f),
242 )
243 }
244 }
245}
246
247impl Default for Avatar {
248 fn default() -> Self {
249 glib::object::Object::new::<Self>()
250 }
251}
252
253#[must_use = "The builder must be built to be used"]
258pub struct AvatarBuilder {
259 builder: glib::object::ObjectBuilder<'static, Avatar>,
260}
261
262impl AvatarBuilder {
263 fn new() -> Self {
264 Self {
265 builder: glib::object::Object::builder(),
266 }
267 }
268
269 pub fn custom_image(self, custom_image: &impl IsA<gdk::Paintable>) -> Self {
270 Self {
271 builder: self
272 .builder
273 .property("custom-image", custom_image.clone().upcast()),
274 }
275 }
276
277 pub fn icon_name(self, icon_name: impl Into<glib::GString>) -> Self {
278 Self {
279 builder: self.builder.property("icon-name", icon_name.into()),
280 }
281 }
282
283 pub fn show_initials(self, show_initials: bool) -> Self {
284 Self {
285 builder: self.builder.property("show-initials", show_initials),
286 }
287 }
288
289 pub fn size(self, size: i32) -> Self {
290 Self {
291 builder: self.builder.property("size", size),
292 }
293 }
294
295 pub fn text(self, text: impl Into<glib::GString>) -> Self {
296 Self {
297 builder: self.builder.property("text", text.into()),
298 }
299 }
300
301 pub fn can_focus(self, can_focus: bool) -> Self {
302 Self {
303 builder: self.builder.property("can-focus", can_focus),
304 }
305 }
306
307 pub fn can_target(self, can_target: bool) -> Self {
308 Self {
309 builder: self.builder.property("can-target", can_target),
310 }
311 }
312
313 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
314 Self {
315 builder: self.builder.property("css-classes", css_classes.into()),
316 }
317 }
318
319 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
320 Self {
321 builder: self.builder.property("css-name", css_name.into()),
322 }
323 }
324
325 pub fn cursor(self, cursor: &gdk::Cursor) -> Self {
326 Self {
327 builder: self.builder.property("cursor", cursor.clone()),
328 }
329 }
330
331 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
332 Self {
333 builder: self.builder.property("focus-on-click", focus_on_click),
334 }
335 }
336
337 pub fn focusable(self, focusable: bool) -> Self {
338 Self {
339 builder: self.builder.property("focusable", focusable),
340 }
341 }
342
343 pub fn halign(self, halign: gtk::Align) -> Self {
344 Self {
345 builder: self.builder.property("halign", halign),
346 }
347 }
348
349 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
350 Self {
351 builder: self.builder.property("has-tooltip", has_tooltip),
352 }
353 }
354
355 pub fn height_request(self, height_request: i32) -> Self {
356 Self {
357 builder: self.builder.property("height-request", height_request),
358 }
359 }
360
361 pub fn hexpand(self, hexpand: bool) -> Self {
362 Self {
363 builder: self.builder.property("hexpand", hexpand),
364 }
365 }
366
367 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
368 Self {
369 builder: self.builder.property("hexpand-set", hexpand_set),
370 }
371 }
372
373 pub fn layout_manager(self, layout_manager: &impl IsA<gtk::LayoutManager>) -> Self {
374 Self {
375 builder: self
376 .builder
377 .property("layout-manager", layout_manager.clone().upcast()),
378 }
379 }
380
381 #[cfg(feature = "gtk_v4_18")]
382 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
383 pub fn limit_events(self, limit_events: bool) -> Self {
384 Self {
385 builder: self.builder.property("limit-events", limit_events),
386 }
387 }
388
389 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
390 Self {
391 builder: self.builder.property("margin-bottom", margin_bottom),
392 }
393 }
394
395 pub fn margin_end(self, margin_end: i32) -> Self {
396 Self {
397 builder: self.builder.property("margin-end", margin_end),
398 }
399 }
400
401 pub fn margin_start(self, margin_start: i32) -> Self {
402 Self {
403 builder: self.builder.property("margin-start", margin_start),
404 }
405 }
406
407 pub fn margin_top(self, margin_top: i32) -> Self {
408 Self {
409 builder: self.builder.property("margin-top", margin_top),
410 }
411 }
412
413 pub fn name(self, name: impl Into<glib::GString>) -> Self {
414 Self {
415 builder: self.builder.property("name", name.into()),
416 }
417 }
418
419 pub fn opacity(self, opacity: f64) -> Self {
420 Self {
421 builder: self.builder.property("opacity", opacity),
422 }
423 }
424
425 pub fn overflow(self, overflow: gtk::Overflow) -> Self {
426 Self {
427 builder: self.builder.property("overflow", overflow),
428 }
429 }
430
431 pub fn receives_default(self, receives_default: bool) -> Self {
432 Self {
433 builder: self.builder.property("receives-default", receives_default),
434 }
435 }
436
437 pub fn sensitive(self, sensitive: bool) -> Self {
438 Self {
439 builder: self.builder.property("sensitive", sensitive),
440 }
441 }
442
443 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
444 Self {
445 builder: self
446 .builder
447 .property("tooltip-markup", tooltip_markup.into()),
448 }
449 }
450
451 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
452 Self {
453 builder: self.builder.property("tooltip-text", tooltip_text.into()),
454 }
455 }
456
457 pub fn valign(self, valign: gtk::Align) -> Self {
458 Self {
459 builder: self.builder.property("valign", valign),
460 }
461 }
462
463 pub fn vexpand(self, vexpand: bool) -> Self {
464 Self {
465 builder: self.builder.property("vexpand", vexpand),
466 }
467 }
468
469 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
470 Self {
471 builder: self.builder.property("vexpand-set", vexpand_set),
472 }
473 }
474
475 pub fn visible(self, visible: bool) -> Self {
476 Self {
477 builder: self.builder.property("visible", visible),
478 }
479 }
480
481 pub fn width_request(self, width_request: i32) -> Self {
482 Self {
483 builder: self.builder.property("width-request", width_request),
484 }
485 }
486
487 pub fn accessible_role(self, accessible_role: gtk::AccessibleRole) -> Self {
488 Self {
489 builder: self.builder.property("accessible-role", accessible_role),
490 }
491 }
492
493 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
496 pub fn build(self) -> Avatar {
497 assert_initialized_main_thread!();
498 self.builder.build()
499 }
500}