1use crate::{ffi, AvatarStatusColor};
7use glib::{
8 prelude::*,
9 signal::{connect_raw, SignalHandlerId},
10 translate::*,
11};
12use std::boxed::Box as Box_;
13
14glib::wrapper! {
15 #[doc(alias = "HeAvatar")]
16 pub struct Avatar(Object<ffi::HeAvatar, ffi::HeAvatarClass>) @extends gtk::Widget, @implements gtk::Accessible, gtk::Buildable, gtk::ConstraintTarget;
17
18 match fn {
19 type_ => || ffi::he_avatar_get_type(),
20 }
21}
22
23impl Avatar {
24 pub const NONE: Option<&'static Avatar> = None;
25
26 pub fn builder() -> AvatarBuilder {
31 AvatarBuilder::new()
32 }
33}
34
35#[must_use = "The builder must be built to be used"]
40pub struct AvatarBuilder {
41 builder: glib::object::ObjectBuilder<'static, Avatar>,
42}
43
44impl AvatarBuilder {
45 fn new() -> Self {
46 Self {
47 builder: glib::object::Object::builder(),
48 }
49 }
50
51 pub fn size(self, size: i32) -> Self {
52 Self {
53 builder: self.builder.property("size", size),
54 }
55 }
56
57 pub fn text(self, text: impl Into<glib::GString>) -> Self {
58 Self {
59 builder: self.builder.property("text", text.into()),
60 }
61 }
62
63 pub fn status(self, status: bool) -> Self {
64 Self {
65 builder: self.builder.property("status", status),
66 }
67 }
68
69 pub fn status_color(self, status_color: AvatarStatusColor) -> Self {
70 Self {
71 builder: self.builder.property("status-color", status_color),
72 }
73 }
74
75 pub fn image(self, image: impl Into<glib::GString>) -> Self {
76 Self {
77 builder: self.builder.property("image", image.into()),
78 }
79 }
80
81 pub fn can_focus(self, can_focus: bool) -> Self {
82 Self {
83 builder: self.builder.property("can-focus", can_focus),
84 }
85 }
86
87 pub fn can_target(self, can_target: bool) -> Self {
88 Self {
89 builder: self.builder.property("can-target", can_target),
90 }
91 }
92
93 pub fn css_classes(self, css_classes: impl Into<glib::StrV>) -> Self {
94 Self {
95 builder: self.builder.property("css-classes", css_classes.into()),
96 }
97 }
98
99 pub fn css_name(self, css_name: impl Into<glib::GString>) -> Self {
100 Self {
101 builder: self.builder.property("css-name", css_name.into()),
102 }
103 }
104
105 pub fn focus_on_click(self, focus_on_click: bool) -> Self {
110 Self {
111 builder: self.builder.property("focus-on-click", focus_on_click),
112 }
113 }
114
115 pub fn focusable(self, focusable: bool) -> Self {
116 Self {
117 builder: self.builder.property("focusable", focusable),
118 }
119 }
120
121 pub fn halign(self, halign: gtk::Align) -> Self {
122 Self {
123 builder: self.builder.property("halign", halign),
124 }
125 }
126
127 pub fn has_tooltip(self, has_tooltip: bool) -> Self {
128 Self {
129 builder: self.builder.property("has-tooltip", has_tooltip),
130 }
131 }
132
133 pub fn height_request(self, height_request: i32) -> Self {
134 Self {
135 builder: self.builder.property("height-request", height_request),
136 }
137 }
138
139 pub fn hexpand(self, hexpand: bool) -> Self {
140 Self {
141 builder: self.builder.property("hexpand", hexpand),
142 }
143 }
144
145 pub fn hexpand_set(self, hexpand_set: bool) -> Self {
146 Self {
147 builder: self.builder.property("hexpand-set", hexpand_set),
148 }
149 }
150
151 #[cfg(feature = "gtk_v4_18")]
156 #[cfg_attr(docsrs, doc(cfg(feature = "gtk_v4_18")))]
157 pub fn limit_events(self, limit_events: bool) -> Self {
158 Self {
159 builder: self.builder.property("limit-events", limit_events),
160 }
161 }
162
163 pub fn margin_bottom(self, margin_bottom: i32) -> Self {
164 Self {
165 builder: self.builder.property("margin-bottom", margin_bottom),
166 }
167 }
168
169 pub fn margin_end(self, margin_end: i32) -> Self {
170 Self {
171 builder: self.builder.property("margin-end", margin_end),
172 }
173 }
174
175 pub fn margin_start(self, margin_start: i32) -> Self {
176 Self {
177 builder: self.builder.property("margin-start", margin_start),
178 }
179 }
180
181 pub fn margin_top(self, margin_top: i32) -> Self {
182 Self {
183 builder: self.builder.property("margin-top", margin_top),
184 }
185 }
186
187 pub fn name(self, name: impl Into<glib::GString>) -> Self {
188 Self {
189 builder: self.builder.property("name", name.into()),
190 }
191 }
192
193 pub fn opacity(self, opacity: f64) -> Self {
194 Self {
195 builder: self.builder.property("opacity", opacity),
196 }
197 }
198
199 pub fn receives_default(self, receives_default: bool) -> Self {
204 Self {
205 builder: self.builder.property("receives-default", receives_default),
206 }
207 }
208
209 pub fn sensitive(self, sensitive: bool) -> Self {
210 Self {
211 builder: self.builder.property("sensitive", sensitive),
212 }
213 }
214
215 pub fn tooltip_markup(self, tooltip_markup: impl Into<glib::GString>) -> Self {
216 Self {
217 builder: self
218 .builder
219 .property("tooltip-markup", tooltip_markup.into()),
220 }
221 }
222
223 pub fn tooltip_text(self, tooltip_text: impl Into<glib::GString>) -> Self {
224 Self {
225 builder: self.builder.property("tooltip-text", tooltip_text.into()),
226 }
227 }
228
229 pub fn valign(self, valign: gtk::Align) -> Self {
230 Self {
231 builder: self.builder.property("valign", valign),
232 }
233 }
234
235 pub fn vexpand(self, vexpand: bool) -> Self {
236 Self {
237 builder: self.builder.property("vexpand", vexpand),
238 }
239 }
240
241 pub fn vexpand_set(self, vexpand_set: bool) -> Self {
242 Self {
243 builder: self.builder.property("vexpand-set", vexpand_set),
244 }
245 }
246
247 pub fn visible(self, visible: bool) -> Self {
248 Self {
249 builder: self.builder.property("visible", visible),
250 }
251 }
252
253 pub fn width_request(self, width_request: i32) -> Self {
254 Self {
255 builder: self.builder.property("width-request", width_request),
256 }
257 }
258
259 #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
266 pub fn build(self) -> Avatar {
267 assert_initialized_main_thread!();
268 self.builder.build()
269 }
270}
271
272pub trait AvatarExt: IsA<Avatar> + 'static {
273 #[doc(alias = "he_avatar_get_size")]
274 #[doc(alias = "get_size")]
275 fn size(&self) -> i32 {
276 unsafe { ffi::he_avatar_get_size(self.as_ref().to_glib_none().0) }
277 }
278
279 #[doc(alias = "he_avatar_set_size")]
280 fn set_size(&self, value: i32) {
281 unsafe {
282 ffi::he_avatar_set_size(self.as_ref().to_glib_none().0, value);
283 }
284 }
285
286 #[doc(alias = "he_avatar_get_text")]
287 #[doc(alias = "get_text")]
288 fn text(&self) -> Option<glib::GString> {
289 unsafe { from_glib_none(ffi::he_avatar_get_text(self.as_ref().to_glib_none().0)) }
290 }
291
292 #[doc(alias = "he_avatar_set_text")]
293 fn set_text(&self, value: Option<&str>) {
294 unsafe {
295 ffi::he_avatar_set_text(self.as_ref().to_glib_none().0, value.to_glib_none().0);
296 }
297 }
298
299 #[doc(alias = "he_avatar_get_status")]
300 #[doc(alias = "get_status")]
301 fn is_status(&self) -> bool {
302 unsafe { from_glib(ffi::he_avatar_get_status(self.as_ref().to_glib_none().0)) }
303 }
304
305 #[doc(alias = "he_avatar_set_status")]
306 fn set_status(&self, value: bool) {
307 unsafe {
308 ffi::he_avatar_set_status(self.as_ref().to_glib_none().0, value.into_glib());
309 }
310 }
311
312 #[doc(alias = "he_avatar_get_status_color")]
313 #[doc(alias = "get_status_color")]
314 fn status_color(&self) -> AvatarStatusColor {
315 unsafe {
316 from_glib(ffi::he_avatar_get_status_color(
317 self.as_ref().to_glib_none().0,
318 ))
319 }
320 }
321
322 #[doc(alias = "he_avatar_set_status_color")]
323 fn set_status_color(&self, value: AvatarStatusColor) {
324 unsafe {
325 ffi::he_avatar_set_status_color(self.as_ref().to_glib_none().0, value.into_glib());
326 }
327 }
328
329 #[doc(alias = "he_avatar_get_image")]
330 #[doc(alias = "get_image")]
331 fn image(&self) -> Option<glib::GString> {
332 unsafe { from_glib_none(ffi::he_avatar_get_image(self.as_ref().to_glib_none().0)) }
333 }
334
335 #[doc(alias = "he_avatar_set_image")]
336 fn set_image(&self, value: Option<&str>) {
337 unsafe {
338 ffi::he_avatar_set_image(self.as_ref().to_glib_none().0, value.to_glib_none().0);
339 }
340 }
341
342 #[doc(alias = "size")]
343 fn connect_size_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
344 unsafe extern "C" fn notify_size_trampoline<P: IsA<Avatar>, F: Fn(&P) + 'static>(
345 this: *mut ffi::HeAvatar,
346 _param_spec: glib::ffi::gpointer,
347 f: glib::ffi::gpointer,
348 ) {
349 let f: &F = &*(f as *const F);
350 f(Avatar::from_glib_borrow(this).unsafe_cast_ref())
351 }
352 unsafe {
353 let f: Box_<F> = Box_::new(f);
354 connect_raw(
355 self.as_ptr() as *mut _,
356 c"notify::size".as_ptr() as *const _,
357 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
358 notify_size_trampoline::<Self, F> as *const (),
359 )),
360 Box_::into_raw(f),
361 )
362 }
363 }
364
365 #[doc(alias = "text")]
366 fn connect_text_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
367 unsafe extern "C" fn notify_text_trampoline<P: IsA<Avatar>, F: Fn(&P) + 'static>(
368 this: *mut ffi::HeAvatar,
369 _param_spec: glib::ffi::gpointer,
370 f: glib::ffi::gpointer,
371 ) {
372 let f: &F = &*(f as *const F);
373 f(Avatar::from_glib_borrow(this).unsafe_cast_ref())
374 }
375 unsafe {
376 let f: Box_<F> = Box_::new(f);
377 connect_raw(
378 self.as_ptr() as *mut _,
379 c"notify::text".as_ptr() as *const _,
380 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
381 notify_text_trampoline::<Self, F> as *const (),
382 )),
383 Box_::into_raw(f),
384 )
385 }
386 }
387
388 #[doc(alias = "status")]
389 fn connect_status_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
390 unsafe extern "C" fn notify_status_trampoline<P: IsA<Avatar>, F: Fn(&P) + 'static>(
391 this: *mut ffi::HeAvatar,
392 _param_spec: glib::ffi::gpointer,
393 f: glib::ffi::gpointer,
394 ) {
395 let f: &F = &*(f as *const F);
396 f(Avatar::from_glib_borrow(this).unsafe_cast_ref())
397 }
398 unsafe {
399 let f: Box_<F> = Box_::new(f);
400 connect_raw(
401 self.as_ptr() as *mut _,
402 c"notify::status".as_ptr() as *const _,
403 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
404 notify_status_trampoline::<Self, F> as *const (),
405 )),
406 Box_::into_raw(f),
407 )
408 }
409 }
410
411 #[doc(alias = "status-color")]
412 fn connect_status_color_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
413 unsafe extern "C" fn notify_status_color_trampoline<P: IsA<Avatar>, F: Fn(&P) + 'static>(
414 this: *mut ffi::HeAvatar,
415 _param_spec: glib::ffi::gpointer,
416 f: glib::ffi::gpointer,
417 ) {
418 let f: &F = &*(f as *const F);
419 f(Avatar::from_glib_borrow(this).unsafe_cast_ref())
420 }
421 unsafe {
422 let f: Box_<F> = Box_::new(f);
423 connect_raw(
424 self.as_ptr() as *mut _,
425 c"notify::status-color".as_ptr() as *const _,
426 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
427 notify_status_color_trampoline::<Self, F> as *const (),
428 )),
429 Box_::into_raw(f),
430 )
431 }
432 }
433
434 #[doc(alias = "image")]
435 fn connect_image_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
436 unsafe extern "C" fn notify_image_trampoline<P: IsA<Avatar>, F: Fn(&P) + 'static>(
437 this: *mut ffi::HeAvatar,
438 _param_spec: glib::ffi::gpointer,
439 f: glib::ffi::gpointer,
440 ) {
441 let f: &F = &*(f as *const F);
442 f(Avatar::from_glib_borrow(this).unsafe_cast_ref())
443 }
444 unsafe {
445 let f: Box_<F> = Box_::new(f);
446 connect_raw(
447 self.as_ptr() as *mut _,
448 c"notify::image".as_ptr() as *const _,
449 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
450 notify_image_trampoline::<Self, F> as *const (),
451 )),
452 Box_::into_raw(f),
453 )
454 }
455 }
456}
457
458impl<O: IsA<Avatar>> AvatarExt for O {}