libadwaita/auto/
toast.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, ToastPriority};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{connect_raw, SignalHandlerId},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    #[doc(alias = "AdwToast")]
17    pub struct Toast(Object<ffi::AdwToast, ffi::AdwToastClass>);
18
19    match fn {
20        type_ => || ffi::adw_toast_get_type(),
21    }
22}
23
24impl Toast {
25    #[doc(alias = "adw_toast_new")]
26    pub fn new(title: &str) -> Toast {
27        assert_initialized_main_thread!();
28        unsafe { from_glib_full(ffi::adw_toast_new(title.to_glib_none().0)) }
29    }
30
31    // rustdoc-stripper-ignore-next
32    /// Creates a new builder-pattern struct instance to construct [`Toast`] objects.
33    ///
34    /// This method returns an instance of [`ToastBuilder`](crate::builders::ToastBuilder) which can be used to create [`Toast`] objects.
35    pub fn builder() -> ToastBuilder {
36        ToastBuilder::new()
37    }
38
39    #[doc(alias = "adw_toast_dismiss")]
40    pub fn dismiss(&self) {
41        unsafe {
42            ffi::adw_toast_dismiss(self.to_glib_none().0);
43        }
44    }
45
46    #[doc(alias = "adw_toast_get_action_name")]
47    #[doc(alias = "get_action_name")]
48    #[doc(alias = "action-name")]
49    pub fn action_name(&self) -> Option<glib::GString> {
50        unsafe { from_glib_none(ffi::adw_toast_get_action_name(self.to_glib_none().0)) }
51    }
52
53    #[doc(alias = "adw_toast_get_action_target_value")]
54    #[doc(alias = "get_action_target_value")]
55    #[doc(alias = "action-target")]
56    pub fn action_target_value(&self) -> Option<glib::Variant> {
57        unsafe {
58            from_glib_none(ffi::adw_toast_get_action_target_value(
59                self.to_glib_none().0,
60            ))
61        }
62    }
63
64    #[doc(alias = "adw_toast_get_button_label")]
65    #[doc(alias = "get_button_label")]
66    #[doc(alias = "button-label")]
67    pub fn button_label(&self) -> Option<glib::GString> {
68        unsafe { from_glib_none(ffi::adw_toast_get_button_label(self.to_glib_none().0)) }
69    }
70
71    #[cfg(feature = "v1_2")]
72    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
73    #[doc(alias = "adw_toast_get_custom_title")]
74    #[doc(alias = "get_custom_title")]
75    #[doc(alias = "custom-title")]
76    pub fn custom_title(&self) -> Option<gtk::Widget> {
77        unsafe { from_glib_none(ffi::adw_toast_get_custom_title(self.to_glib_none().0)) }
78    }
79
80    #[doc(alias = "adw_toast_get_priority")]
81    #[doc(alias = "get_priority")]
82    pub fn priority(&self) -> ToastPriority {
83        unsafe { from_glib(ffi::adw_toast_get_priority(self.to_glib_none().0)) }
84    }
85
86    #[doc(alias = "adw_toast_get_timeout")]
87    #[doc(alias = "get_timeout")]
88    pub fn timeout(&self) -> u32 {
89        unsafe { ffi::adw_toast_get_timeout(self.to_glib_none().0) }
90    }
91
92    #[doc(alias = "adw_toast_get_title")]
93    #[doc(alias = "get_title")]
94    pub fn title(&self) -> Option<glib::GString> {
95        unsafe { from_glib_none(ffi::adw_toast_get_title(self.to_glib_none().0)) }
96    }
97
98    #[cfg(feature = "v1_4")]
99    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
100    #[doc(alias = "adw_toast_get_use_markup")]
101    #[doc(alias = "get_use_markup")]
102    #[doc(alias = "use-markup")]
103    pub fn uses_markup(&self) -> bool {
104        unsafe { from_glib(ffi::adw_toast_get_use_markup(self.to_glib_none().0)) }
105    }
106
107    #[doc(alias = "adw_toast_set_action_name")]
108    #[doc(alias = "action-name")]
109    pub fn set_action_name(&self, action_name: Option<&str>) {
110        unsafe {
111            ffi::adw_toast_set_action_name(self.to_glib_none().0, action_name.to_glib_none().0);
112        }
113    }
114
115    #[doc(alias = "adw_toast_set_action_target_value")]
116    #[doc(alias = "action-target")]
117    pub fn set_action_target_value(&self, action_target: Option<&glib::Variant>) {
118        unsafe {
119            ffi::adw_toast_set_action_target_value(
120                self.to_glib_none().0,
121                action_target.to_glib_none().0,
122            );
123        }
124    }
125
126    #[doc(alias = "adw_toast_set_button_label")]
127    #[doc(alias = "button-label")]
128    pub fn set_button_label(&self, button_label: Option<&str>) {
129        unsafe {
130            ffi::adw_toast_set_button_label(self.to_glib_none().0, button_label.to_glib_none().0);
131        }
132    }
133
134    #[cfg(feature = "v1_2")]
135    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
136    #[doc(alias = "adw_toast_set_custom_title")]
137    #[doc(alias = "custom-title")]
138    pub fn set_custom_title(&self, widget: Option<&impl IsA<gtk::Widget>>) {
139        unsafe {
140            ffi::adw_toast_set_custom_title(
141                self.to_glib_none().0,
142                widget.map(|p| p.as_ref()).to_glib_none().0,
143            );
144        }
145    }
146
147    #[doc(alias = "adw_toast_set_detailed_action_name")]
148    pub fn set_detailed_action_name(&self, detailed_action_name: Option<&str>) {
149        unsafe {
150            ffi::adw_toast_set_detailed_action_name(
151                self.to_glib_none().0,
152                detailed_action_name.to_glib_none().0,
153            );
154        }
155    }
156
157    #[doc(alias = "adw_toast_set_priority")]
158    #[doc(alias = "priority")]
159    pub fn set_priority(&self, priority: ToastPriority) {
160        unsafe {
161            ffi::adw_toast_set_priority(self.to_glib_none().0, priority.into_glib());
162        }
163    }
164
165    #[doc(alias = "adw_toast_set_timeout")]
166    #[doc(alias = "timeout")]
167    pub fn set_timeout(&self, timeout: u32) {
168        unsafe {
169            ffi::adw_toast_set_timeout(self.to_glib_none().0, timeout);
170        }
171    }
172
173    #[doc(alias = "adw_toast_set_title")]
174    #[doc(alias = "title")]
175    pub fn set_title(&self, title: &str) {
176        unsafe {
177            ffi::adw_toast_set_title(self.to_glib_none().0, title.to_glib_none().0);
178        }
179    }
180
181    #[cfg(feature = "v1_4")]
182    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
183    #[doc(alias = "adw_toast_set_use_markup")]
184    #[doc(alias = "use-markup")]
185    pub fn set_use_markup(&self, use_markup: bool) {
186        unsafe {
187            ffi::adw_toast_set_use_markup(self.to_glib_none().0, use_markup.into_glib());
188        }
189    }
190
191    #[cfg(feature = "v1_2")]
192    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
193    #[doc(alias = "button-clicked")]
194    pub fn connect_button_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
195        unsafe extern "C" fn button_clicked_trampoline<F: Fn(&Toast) + 'static>(
196            this: *mut ffi::AdwToast,
197            f: glib::ffi::gpointer,
198        ) {
199            let f: &F = &*(f as *const F);
200            f(&from_glib_borrow(this))
201        }
202        unsafe {
203            let f: Box_<F> = Box_::new(f);
204            connect_raw(
205                self.as_ptr() as *mut _,
206                c"button-clicked".as_ptr() as *const _,
207                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
208                    button_clicked_trampoline::<F> as *const (),
209                )),
210                Box_::into_raw(f),
211            )
212        }
213    }
214
215    #[doc(alias = "dismissed")]
216    pub fn connect_dismissed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
217        unsafe extern "C" fn dismissed_trampoline<F: Fn(&Toast) + 'static>(
218            this: *mut ffi::AdwToast,
219            f: glib::ffi::gpointer,
220        ) {
221            let f: &F = &*(f as *const F);
222            f(&from_glib_borrow(this))
223        }
224        unsafe {
225            let f: Box_<F> = Box_::new(f);
226            connect_raw(
227                self.as_ptr() as *mut _,
228                c"dismissed".as_ptr() as *const _,
229                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
230                    dismissed_trampoline::<F> as *const (),
231                )),
232                Box_::into_raw(f),
233            )
234        }
235    }
236
237    #[doc(alias = "action-name")]
238    pub fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
239        unsafe extern "C" fn notify_action_name_trampoline<F: Fn(&Toast) + 'static>(
240            this: *mut ffi::AdwToast,
241            _param_spec: glib::ffi::gpointer,
242            f: glib::ffi::gpointer,
243        ) {
244            let f: &F = &*(f as *const F);
245            f(&from_glib_borrow(this))
246        }
247        unsafe {
248            let f: Box_<F> = Box_::new(f);
249            connect_raw(
250                self.as_ptr() as *mut _,
251                c"notify::action-name".as_ptr() as *const _,
252                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
253                    notify_action_name_trampoline::<F> as *const (),
254                )),
255                Box_::into_raw(f),
256            )
257        }
258    }
259
260    #[doc(alias = "action-target")]
261    pub fn connect_action_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
262        unsafe extern "C" fn notify_action_target_trampoline<F: Fn(&Toast) + 'static>(
263            this: *mut ffi::AdwToast,
264            _param_spec: glib::ffi::gpointer,
265            f: glib::ffi::gpointer,
266        ) {
267            let f: &F = &*(f as *const F);
268            f(&from_glib_borrow(this))
269        }
270        unsafe {
271            let f: Box_<F> = Box_::new(f);
272            connect_raw(
273                self.as_ptr() as *mut _,
274                c"notify::action-target".as_ptr() as *const _,
275                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
276                    notify_action_target_trampoline::<F> as *const (),
277                )),
278                Box_::into_raw(f),
279            )
280        }
281    }
282
283    #[doc(alias = "button-label")]
284    pub fn connect_button_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
285        unsafe extern "C" fn notify_button_label_trampoline<F: Fn(&Toast) + 'static>(
286            this: *mut ffi::AdwToast,
287            _param_spec: glib::ffi::gpointer,
288            f: glib::ffi::gpointer,
289        ) {
290            let f: &F = &*(f as *const F);
291            f(&from_glib_borrow(this))
292        }
293        unsafe {
294            let f: Box_<F> = Box_::new(f);
295            connect_raw(
296                self.as_ptr() as *mut _,
297                c"notify::button-label".as_ptr() as *const _,
298                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
299                    notify_button_label_trampoline::<F> as *const (),
300                )),
301                Box_::into_raw(f),
302            )
303        }
304    }
305
306    #[cfg(feature = "v1_2")]
307    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
308    #[doc(alias = "custom-title")]
309    pub fn connect_custom_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
310        unsafe extern "C" fn notify_custom_title_trampoline<F: Fn(&Toast) + 'static>(
311            this: *mut ffi::AdwToast,
312            _param_spec: glib::ffi::gpointer,
313            f: glib::ffi::gpointer,
314        ) {
315            let f: &F = &*(f as *const F);
316            f(&from_glib_borrow(this))
317        }
318        unsafe {
319            let f: Box_<F> = Box_::new(f);
320            connect_raw(
321                self.as_ptr() as *mut _,
322                c"notify::custom-title".as_ptr() as *const _,
323                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
324                    notify_custom_title_trampoline::<F> as *const (),
325                )),
326                Box_::into_raw(f),
327            )
328        }
329    }
330
331    #[doc(alias = "priority")]
332    pub fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
333        unsafe extern "C" fn notify_priority_trampoline<F: Fn(&Toast) + 'static>(
334            this: *mut ffi::AdwToast,
335            _param_spec: glib::ffi::gpointer,
336            f: glib::ffi::gpointer,
337        ) {
338            let f: &F = &*(f as *const F);
339            f(&from_glib_borrow(this))
340        }
341        unsafe {
342            let f: Box_<F> = Box_::new(f);
343            connect_raw(
344                self.as_ptr() as *mut _,
345                c"notify::priority".as_ptr() as *const _,
346                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
347                    notify_priority_trampoline::<F> as *const (),
348                )),
349                Box_::into_raw(f),
350            )
351        }
352    }
353
354    #[doc(alias = "timeout")]
355    pub fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
356        unsafe extern "C" fn notify_timeout_trampoline<F: Fn(&Toast) + 'static>(
357            this: *mut ffi::AdwToast,
358            _param_spec: glib::ffi::gpointer,
359            f: glib::ffi::gpointer,
360        ) {
361            let f: &F = &*(f as *const F);
362            f(&from_glib_borrow(this))
363        }
364        unsafe {
365            let f: Box_<F> = Box_::new(f);
366            connect_raw(
367                self.as_ptr() as *mut _,
368                c"notify::timeout".as_ptr() as *const _,
369                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
370                    notify_timeout_trampoline::<F> as *const (),
371                )),
372                Box_::into_raw(f),
373            )
374        }
375    }
376
377    #[doc(alias = "title")]
378    pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
379        unsafe extern "C" fn notify_title_trampoline<F: Fn(&Toast) + 'static>(
380            this: *mut ffi::AdwToast,
381            _param_spec: glib::ffi::gpointer,
382            f: glib::ffi::gpointer,
383        ) {
384            let f: &F = &*(f as *const F);
385            f(&from_glib_borrow(this))
386        }
387        unsafe {
388            let f: Box_<F> = Box_::new(f);
389            connect_raw(
390                self.as_ptr() as *mut _,
391                c"notify::title".as_ptr() as *const _,
392                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
393                    notify_title_trampoline::<F> as *const (),
394                )),
395                Box_::into_raw(f),
396            )
397        }
398    }
399
400    #[cfg(feature = "v1_4")]
401    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
402    #[doc(alias = "use-markup")]
403    pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
404        unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&Toast) + 'static>(
405            this: *mut ffi::AdwToast,
406            _param_spec: glib::ffi::gpointer,
407            f: glib::ffi::gpointer,
408        ) {
409            let f: &F = &*(f as *const F);
410            f(&from_glib_borrow(this))
411        }
412        unsafe {
413            let f: Box_<F> = Box_::new(f);
414            connect_raw(
415                self.as_ptr() as *mut _,
416                c"notify::use-markup".as_ptr() as *const _,
417                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
418                    notify_use_markup_trampoline::<F> as *const (),
419                )),
420                Box_::into_raw(f),
421            )
422        }
423    }
424}
425
426impl Default for Toast {
427    fn default() -> Self {
428        glib::object::Object::new::<Self>()
429    }
430}
431
432// rustdoc-stripper-ignore-next
433/// A [builder-pattern] type to construct [`Toast`] objects.
434///
435/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
436#[must_use = "The builder must be built to be used"]
437pub struct ToastBuilder {
438    builder: glib::object::ObjectBuilder<'static, Toast>,
439}
440
441impl ToastBuilder {
442    fn new() -> Self {
443        Self {
444            builder: glib::object::Object::builder(),
445        }
446    }
447
448    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
449        Self {
450            builder: self.builder.property("action-name", action_name.into()),
451        }
452    }
453
454    pub fn action_target(self, action_target: &glib::Variant) -> Self {
455        Self {
456            builder: self
457                .builder
458                .property("action-target", action_target.clone()),
459        }
460    }
461
462    pub fn button_label(self, button_label: impl Into<glib::GString>) -> Self {
463        Self {
464            builder: self.builder.property("button-label", button_label.into()),
465        }
466    }
467
468    #[cfg(feature = "v1_2")]
469    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
470    pub fn custom_title(self, custom_title: &impl IsA<gtk::Widget>) -> Self {
471        Self {
472            builder: self
473                .builder
474                .property("custom-title", custom_title.clone().upcast()),
475        }
476    }
477
478    pub fn priority(self, priority: ToastPriority) -> Self {
479        Self {
480            builder: self.builder.property("priority", priority),
481        }
482    }
483
484    pub fn timeout(self, timeout: u32) -> Self {
485        Self {
486            builder: self.builder.property("timeout", timeout),
487        }
488    }
489
490    pub fn title(self, title: impl Into<glib::GString>) -> Self {
491        Self {
492            builder: self.builder.property("title", title.into()),
493        }
494    }
495
496    #[cfg(feature = "v1_4")]
497    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
498    pub fn use_markup(self, use_markup: bool) -> Self {
499        Self {
500            builder: self.builder.property("use-markup", use_markup),
501        }
502    }
503
504    // rustdoc-stripper-ignore-next
505    /// Build the [`Toast`].
506    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
507    pub fn build(self) -> Toast {
508        assert_initialized_main_thread!();
509        self.builder.build()
510    }
511}