Skip to main content

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::{ToastPriority, ffi};
7use glib::{
8    object::ObjectType as _,
9    prelude::*,
10    signal::{SignalHandlerId, connect_raw},
11    translate::*,
12};
13use std::boxed::Box as Box_;
14
15glib::wrapper! {
16    /// A helper object for [`ToastOverlay`][crate::ToastOverlay].
17    ///
18    /// Toasts are meant to be passed into [`ToastOverlay::add_toast()`][crate::ToastOverlay::add_toast()] as
19    /// follows:
20    ///
21    /// **⚠️ The following code is in c ⚠️**
22    ///
23    /// ```c
24    /// adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
25    /// ```
26    ///
27    /// <picture>
28    ///   <source srcset="toast-simple-dark.png" media="(prefers-color-scheme: dark)">
29    ///   <img src="toast-simple.png" alt="toast-simple">
30    /// </picture>
31    ///
32    /// Toasts always have a close button. They emit the [`dismissed`][struct@crate::Toast#dismissed]
33    /// signal when disappearing.
34    ///
35    /// [`timeout`][struct@crate::Toast#timeout] determines how long the toast stays on screen, while
36    /// [`priority`][struct@crate::Toast#priority] determines how it behaves if another toast is
37    /// already being displayed.
38    ///
39    /// Toast titles use Pango markup by default, set [`use-markup`][struct@crate::Toast#use-markup] to
40    /// `FALSE` if this is unwanted.
41    ///
42    /// [`custom-title`][struct@crate::Toast#custom-title] can be used to replace the title label with a
43    /// custom widget.
44    ///
45    /// ## Actions
46    ///
47    /// Toasts can have one button on them, with a label and an attached
48    /// `Gio::Action`.
49    ///
50    /// **⚠️ The following code is in c ⚠️**
51    ///
52    /// ```c
53    /// AdwToast *toast = adw_toast_new (_("Toast with Action"));
54    ///
55    /// adw_toast_set_button_label (toast, _("_Example"));
56    /// adw_toast_set_action_name (toast, "win.example");
57    ///
58    /// adw_toast_overlay_add_toast (overlay, toast);
59    /// ```
60    ///
61    /// <picture>
62    ///   <source srcset="toast-action-dark.png" media="(prefers-color-scheme: dark)">
63    ///   <img src="toast-action.png" alt="toast-action">
64    /// </picture>
65    ///
66    /// ## Modifying toasts
67    ///
68    /// Toasts can be modified after they have been shown. For this, an [`Toast`][crate::Toast]
69    /// reference must be kept around while the toast is visible.
70    ///
71    /// A common use case for this is using toasts as undo prompts that stack with
72    /// each other, allowing to batch undo the last deleted items:
73    ///
74    /// **⚠️ The following code is in c ⚠️**
75    ///
76    /// ```c
77    ///
78    /// static void
79    /// toast_undo_cb (GtkWidget  *sender,
80    ///                const char *action,
81    ///                GVariant   *param)
82    /// {
83    ///   // Undo the deletion
84    /// }
85    ///
86    /// static void
87    /// dismissed_cb (MyWindow *self)
88    /// {
89    ///   self->undo_toast = NULL;
90    ///
91    ///   // Permanently delete the items
92    /// }
93    ///
94    /// static void
95    /// delete_item (MyWindow *self,
96    ///              MyItem   *item)
97    /// {
98    ///   g_autofree char *title = NULL;
99    ///   int n_items;
100    ///
101    ///   // Mark the item as waiting for deletion
102    ///   n_items = ... // The number of waiting items
103    ///
104    ///   if (!self->undo_toast) {
105    ///     self->undo_toast = adw_toast_new_format (_("‘%s’ deleted"), ...);
106    ///
107    ///     adw_toast_set_priority (self->undo_toast, ADW_TOAST_PRIORITY_HIGH);
108    ///     adw_toast_set_button_label (self->undo_toast, _("_Undo"));
109    ///     adw_toast_set_action_name (self->undo_toast, "toast.undo");
110    ///
111    ///     g_signal_connect_swapped (self->undo_toast, "dismissed",
112    ///                               G_CALLBACK (dismissed_cb), self);
113    ///
114    ///     adw_toast_overlay_add_toast (self->toast_overlay, self->undo_toast);
115    ///
116    ///     return;
117    ///   }
118    ///
119    ///   title =
120    ///     g_strdup_printf (ngettext ("<span font_features='tnum=1'>%d</span> item deleted",
121    ///                                "<span font_features='tnum=1'>%d</span> items deleted",
122    ///                                n_items), n_items);
123    ///
124    ///   adw_toast_set_title (self->undo_toast, title);
125    ///
126    ///   // Bump the toast timeout
127    ///   adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (self->undo_toast));
128    /// }
129    ///
130    /// static void
131    /// my_window_class_init (MyWindowClass *klass)
132    /// {
133    ///   GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
134    ///
135    ///   gtk_widget_class_install_action (widget_class, "toast.undo", NULL, toast_undo_cb);
136    /// }
137    /// ```
138    ///
139    /// <picture>
140    ///   <source srcset="toast-undo-dark.png" media="(prefers-color-scheme: dark)">
141    ///   <img src="toast-undo.png" alt="toast-undo">
142    /// </picture>
143    ///
144    /// ## Properties
145    ///
146    ///
147    /// #### `action-name`
148    ///  The name of the associated action.
149    ///
150    /// It will be activated when clicking the button.
151    ///
152    /// See [`action-target`][struct@crate::Toast#action-target].
153    ///
154    /// Readable | Writeable
155    ///
156    ///
157    /// #### `action-target`
158    ///  The parameter for action invocations.
159    ///
160    /// Readable | Writeable
161    ///
162    ///
163    /// #### `button-label`
164    ///  The label to show on the button.
165    ///
166    /// Underlines in the button text can be used to indicate a mnemonic.
167    ///
168    /// If set to `NULL`, the button won't be shown.
169    ///
170    /// See [`action-name`][struct@crate::Toast#action-name].
171    ///
172    /// Readable | Writeable
173    ///
174    ///
175    /// #### `custom-title`
176    ///  The custom title widget.
177    ///
178    /// It will be displayed instead of the title if set. In this case,
179    /// [`title`][struct@crate::Toast#title] is ignored.
180    ///
181    /// Setting a custom title will unset [`title`][struct@crate::Toast#title].
182    ///
183    /// Readable | Writeable
184    ///
185    ///
186    /// #### `priority`
187    ///  The priority of the toast.
188    ///
189    /// Priority controls how the toast behaves when another toast is already
190    /// being displayed.
191    ///
192    /// If the priority is [enum@Adw.ToastPriority.normal], the toast will be
193    /// queued.
194    ///
195    /// If the priority is [enum@Adw.ToastPriority.high], the toast will be
196    /// displayed immediately, pushing the previous toast into the queue instead.
197    ///
198    /// Readable | Writeable
199    ///
200    ///
201    /// #### `timeout`
202    ///  The timeout of the toast, in seconds.
203    ///
204    /// If timeout is 0, the toast is displayed indefinitely until manually
205    /// dismissed.
206    ///
207    /// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
208    /// have keyboard focus inside them.
209    ///
210    /// Readable | Writeable
211    ///
212    ///
213    /// #### `title`
214    ///  The title of the toast.
215    ///
216    /// The title can be marked up with the Pango text markup language.
217    ///
218    /// Setting a title will unset [`custom-title`][struct@crate::Toast#custom-title].
219    ///
220    /// If [`custom-title`][struct@crate::Toast#custom-title] is set, it will be used instead.
221    ///
222    /// Readable | Writeable
223    ///
224    ///
225    /// #### `use-markup`
226    ///  Whether to use Pango markup for the toast title.
227    ///
228    /// See also `parse_markup()`.
229    ///
230    /// Readable | Writeable
231    ///
232    /// ## Signals
233    ///
234    ///
235    /// #### `button-clicked`
236    ///  Emitted after the button has been clicked.
237    ///
238    /// It can be used as an alternative to setting an action.
239    ///
240    ///
241    ///
242    ///
243    /// #### `dismissed`
244    ///  Emitted when the toast has been dismissed.
245    ///
246    ///
247    ///
248    /// # Implements
249    ///
250    /// [`trait@glib::ObjectExt`]
251    #[doc(alias = "AdwToast")]
252    pub struct Toast(Object<ffi::AdwToast, ffi::AdwToastClass>);
253
254    match fn {
255        type_ => || ffi::adw_toast_get_type(),
256    }
257}
258
259impl Toast {
260    /// Creates a new [`Toast`][crate::Toast].
261    ///
262    /// The toast will use @title as its title.
263    ///
264    /// @title can be marked up with the Pango text markup language.
265    /// ## `title`
266    /// the title to be displayed
267    ///
268    /// # Returns
269    ///
270    /// the new created [`Toast`][crate::Toast]
271    #[doc(alias = "adw_toast_new")]
272    pub fn new(title: &str) -> Toast {
273        assert_initialized_main_thread!();
274        unsafe { from_glib_full(ffi::adw_toast_new(title.to_glib_none().0)) }
275    }
276
277    // rustdoc-stripper-ignore-next
278    /// Creates a new builder-pattern struct instance to construct [`Toast`] objects.
279    ///
280    /// This method returns an instance of [`ToastBuilder`](crate::builders::ToastBuilder) which can be used to create [`Toast`] objects.
281    pub fn builder() -> ToastBuilder {
282        ToastBuilder::new()
283    }
284
285    /// Dismisses @self.
286    ///
287    /// Does nothing if @self has already been dismissed, or hasn't been added to an
288    /// [`ToastOverlay`][crate::ToastOverlay].
289    #[doc(alias = "adw_toast_dismiss")]
290    pub fn dismiss(&self) {
291        unsafe {
292            ffi::adw_toast_dismiss(self.to_glib_none().0);
293        }
294    }
295
296    /// Gets the name of the associated action.
297    ///
298    /// # Returns
299    ///
300    /// the action name
301    #[doc(alias = "adw_toast_get_action_name")]
302    #[doc(alias = "get_action_name")]
303    #[doc(alias = "action-name")]
304    pub fn action_name(&self) -> Option<glib::GString> {
305        unsafe { from_glib_none(ffi::adw_toast_get_action_name(self.to_glib_none().0)) }
306    }
307
308    /// Gets the parameter for action invocations.
309    ///
310    /// # Returns
311    ///
312    /// the action target
313    #[doc(alias = "adw_toast_get_action_target_value")]
314    #[doc(alias = "get_action_target_value")]
315    #[doc(alias = "action-target")]
316    pub fn action_target_value(&self) -> Option<glib::Variant> {
317        unsafe {
318            from_glib_none(ffi::adw_toast_get_action_target_value(
319                self.to_glib_none().0,
320            ))
321        }
322    }
323
324    /// Gets the label to show on the button.
325    ///
326    /// # Returns
327    ///
328    /// the button label
329    #[doc(alias = "adw_toast_get_button_label")]
330    #[doc(alias = "get_button_label")]
331    #[doc(alias = "button-label")]
332    pub fn button_label(&self) -> Option<glib::GString> {
333        unsafe { from_glib_none(ffi::adw_toast_get_button_label(self.to_glib_none().0)) }
334    }
335
336    /// Gets the custom title widget of @self.
337    ///
338    /// # Returns
339    ///
340    /// the custom title widget
341    #[cfg(feature = "v1_2")]
342    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
343    #[doc(alias = "adw_toast_get_custom_title")]
344    #[doc(alias = "get_custom_title")]
345    #[doc(alias = "custom-title")]
346    pub fn custom_title(&self) -> Option<gtk::Widget> {
347        unsafe { from_glib_none(ffi::adw_toast_get_custom_title(self.to_glib_none().0)) }
348    }
349
350    /// Gets priority for @self.
351    ///
352    /// # Returns
353    ///
354    /// the priority
355    #[doc(alias = "adw_toast_get_priority")]
356    #[doc(alias = "get_priority")]
357    pub fn priority(&self) -> ToastPriority {
358        unsafe { from_glib(ffi::adw_toast_get_priority(self.to_glib_none().0)) }
359    }
360
361    /// Gets timeout for @self.
362    ///
363    /// # Returns
364    ///
365    /// the timeout
366    #[doc(alias = "adw_toast_get_timeout")]
367    #[doc(alias = "get_timeout")]
368    pub fn timeout(&self) -> u32 {
369        unsafe { ffi::adw_toast_get_timeout(self.to_glib_none().0) }
370    }
371
372    /// Gets the title that will be displayed on the toast.
373    ///
374    /// If a custom title has been set with [`set_custom_title()`][Self::set_custom_title()]
375    /// the return value will be [`None`].
376    ///
377    /// # Returns
378    ///
379    /// the title
380    #[doc(alias = "adw_toast_get_title")]
381    #[doc(alias = "get_title")]
382    pub fn title(&self) -> Option<glib::GString> {
383        unsafe { from_glib_none(ffi::adw_toast_get_title(self.to_glib_none().0)) }
384    }
385
386    /// Gets whether to use Pango markup for the toast title.
387    ///
388    /// # Returns
389    ///
390    /// whether the toast uses markup
391    #[cfg(feature = "v1_4")]
392    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
393    #[doc(alias = "adw_toast_get_use_markup")]
394    #[doc(alias = "get_use_markup")]
395    #[doc(alias = "use-markup")]
396    pub fn uses_markup(&self) -> bool {
397        unsafe { from_glib(ffi::adw_toast_get_use_markup(self.to_glib_none().0)) }
398    }
399
400    /// Sets the name of the associated action.
401    ///
402    /// It will be activated when clicking the button.
403    ///
404    /// See [`action-target`][struct@crate::Toast#action-target].
405    /// ## `action_name`
406    /// the action name
407    #[doc(alias = "adw_toast_set_action_name")]
408    #[doc(alias = "action-name")]
409    pub fn set_action_name(&self, action_name: Option<&str>) {
410        unsafe {
411            ffi::adw_toast_set_action_name(self.to_glib_none().0, action_name.to_glib_none().0);
412        }
413    }
414
415    /// Sets the parameter for action invocations.
416    ///
417    /// If the @action_target variant has a floating reference this function
418    /// will sink it.
419    /// ## `action_target`
420    /// the action target
421    #[doc(alias = "adw_toast_set_action_target_value")]
422    #[doc(alias = "action-target")]
423    pub fn set_action_target_value(&self, action_target: Option<&glib::Variant>) {
424        unsafe {
425            ffi::adw_toast_set_action_target_value(
426                self.to_glib_none().0,
427                action_target.to_glib_none().0,
428            );
429        }
430    }
431
432    /// Sets the label to show on the button.
433    ///
434    /// Underlines in the button text can be used to indicate a mnemonic.
435    ///
436    /// If set to `NULL`, the button won't be shown.
437    ///
438    /// See [`action-name`][struct@crate::Toast#action-name].
439    /// ## `button_label`
440    /// a button label
441    #[doc(alias = "adw_toast_set_button_label")]
442    #[doc(alias = "button-label")]
443    pub fn set_button_label(&self, button_label: Option<&str>) {
444        unsafe {
445            ffi::adw_toast_set_button_label(self.to_glib_none().0, button_label.to_glib_none().0);
446        }
447    }
448
449    /// Sets the custom title widget of @self.
450    ///
451    /// It will be displayed instead of the title if set. In this case,
452    /// [`title`][struct@crate::Toast#title] is ignored.
453    ///
454    /// Setting a custom title will unset [`title`][struct@crate::Toast#title].
455    /// ## `widget`
456    /// the custom title widget
457    #[cfg(feature = "v1_2")]
458    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
459    #[doc(alias = "adw_toast_set_custom_title")]
460    #[doc(alias = "custom-title")]
461    pub fn set_custom_title(&self, widget: Option<&impl IsA<gtk::Widget>>) {
462        unsafe {
463            ffi::adw_toast_set_custom_title(
464                self.to_glib_none().0,
465                widget.map(|p| p.as_ref()).to_glib_none().0,
466            );
467        }
468    }
469
470    /// Sets the action name and its parameter.
471    ///
472    /// @detailed_action_name is a string in the format accepted by
473    /// `Gio::Action::parse_detailed_name()`.
474    /// ## `detailed_action_name`
475    /// the detailed action name
476    #[doc(alias = "adw_toast_set_detailed_action_name")]
477    pub fn set_detailed_action_name(&self, detailed_action_name: Option<&str>) {
478        unsafe {
479            ffi::adw_toast_set_detailed_action_name(
480                self.to_glib_none().0,
481                detailed_action_name.to_glib_none().0,
482            );
483        }
484    }
485
486    /// Sets priority for @self.
487    ///
488    /// Priority controls how the toast behaves when another toast is already
489    /// being displayed.
490    ///
491    /// If @priority is [enum@Adw.ToastPriority.normal], the toast will be queued.
492    ///
493    /// If @priority is [enum@Adw.ToastPriority.high], the toast will be displayed
494    /// immediately, pushing the previous toast into the queue instead.
495    /// ## `priority`
496    /// the priority
497    #[doc(alias = "adw_toast_set_priority")]
498    #[doc(alias = "priority")]
499    pub fn set_priority(&self, priority: ToastPriority) {
500        unsafe {
501            ffi::adw_toast_set_priority(self.to_glib_none().0, priority.into_glib());
502        }
503    }
504
505    /// Sets timeout for @self.
506    ///
507    /// If @timeout is 0, the toast is displayed indefinitely until manually
508    /// dismissed.
509    ///
510    /// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
511    /// have keyboard focus inside them.
512    /// ## `timeout`
513    /// the timeout
514    #[doc(alias = "adw_toast_set_timeout")]
515    #[doc(alias = "timeout")]
516    pub fn set_timeout(&self, timeout: u32) {
517        unsafe {
518            ffi::adw_toast_set_timeout(self.to_glib_none().0, timeout);
519        }
520    }
521
522    /// Sets the title that will be displayed on the toast.
523    ///
524    /// The title can be marked up with the Pango text markup language.
525    ///
526    /// Setting a title will unset [`custom-title`][struct@crate::Toast#custom-title].
527    ///
528    /// If [`custom-title`][struct@crate::Toast#custom-title] is set, it will be used instead.
529    /// ## `title`
530    /// a title
531    #[doc(alias = "adw_toast_set_title")]
532    #[doc(alias = "title")]
533    pub fn set_title(&self, title: &str) {
534        unsafe {
535            ffi::adw_toast_set_title(self.to_glib_none().0, title.to_glib_none().0);
536        }
537    }
538
539    /// Whether to use Pango markup for the toast title.
540    ///
541    /// See also `parse_markup()`.
542    /// ## `use_markup`
543    /// whether to use markup
544    #[cfg(feature = "v1_4")]
545    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
546    #[doc(alias = "adw_toast_set_use_markup")]
547    #[doc(alias = "use-markup")]
548    pub fn set_use_markup(&self, use_markup: bool) {
549        unsafe {
550            ffi::adw_toast_set_use_markup(self.to_glib_none().0, use_markup.into_glib());
551        }
552    }
553
554    /// Emitted after the button has been clicked.
555    ///
556    /// It can be used as an alternative to setting an action.
557    #[cfg(feature = "v1_2")]
558    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
559    #[doc(alias = "button-clicked")]
560    pub fn connect_button_clicked<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
561        unsafe extern "C" fn button_clicked_trampoline<F: Fn(&Toast) + 'static>(
562            this: *mut ffi::AdwToast,
563            f: glib::ffi::gpointer,
564        ) {
565            unsafe {
566                let f: &F = &*(f as *const F);
567                f(&from_glib_borrow(this))
568            }
569        }
570        unsafe {
571            let f: Box_<F> = Box_::new(f);
572            connect_raw(
573                self.as_ptr() as *mut _,
574                c"button-clicked".as_ptr(),
575                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
576                    button_clicked_trampoline::<F> as *const (),
577                )),
578                Box_::into_raw(f),
579            )
580        }
581    }
582
583    /// Emitted when the toast has been dismissed.
584    #[doc(alias = "dismissed")]
585    pub fn connect_dismissed<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
586        unsafe extern "C" fn dismissed_trampoline<F: Fn(&Toast) + 'static>(
587            this: *mut ffi::AdwToast,
588            f: glib::ffi::gpointer,
589        ) {
590            unsafe {
591                let f: &F = &*(f as *const F);
592                f(&from_glib_borrow(this))
593            }
594        }
595        unsafe {
596            let f: Box_<F> = Box_::new(f);
597            connect_raw(
598                self.as_ptr() as *mut _,
599                c"dismissed".as_ptr(),
600                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
601                    dismissed_trampoline::<F> as *const (),
602                )),
603                Box_::into_raw(f),
604            )
605        }
606    }
607
608    #[doc(alias = "action-name")]
609    pub fn connect_action_name_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
610        unsafe extern "C" fn notify_action_name_trampoline<F: Fn(&Toast) + 'static>(
611            this: *mut ffi::AdwToast,
612            _param_spec: glib::ffi::gpointer,
613            f: glib::ffi::gpointer,
614        ) {
615            unsafe {
616                let f: &F = &*(f as *const F);
617                f(&from_glib_borrow(this))
618            }
619        }
620        unsafe {
621            let f: Box_<F> = Box_::new(f);
622            connect_raw(
623                self.as_ptr() as *mut _,
624                c"notify::action-name".as_ptr(),
625                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
626                    notify_action_name_trampoline::<F> as *const (),
627                )),
628                Box_::into_raw(f),
629            )
630        }
631    }
632
633    #[doc(alias = "action-target")]
634    pub fn connect_action_target_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
635        unsafe extern "C" fn notify_action_target_trampoline<F: Fn(&Toast) + 'static>(
636            this: *mut ffi::AdwToast,
637            _param_spec: glib::ffi::gpointer,
638            f: glib::ffi::gpointer,
639        ) {
640            unsafe {
641                let f: &F = &*(f as *const F);
642                f(&from_glib_borrow(this))
643            }
644        }
645        unsafe {
646            let f: Box_<F> = Box_::new(f);
647            connect_raw(
648                self.as_ptr() as *mut _,
649                c"notify::action-target".as_ptr(),
650                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
651                    notify_action_target_trampoline::<F> as *const (),
652                )),
653                Box_::into_raw(f),
654            )
655        }
656    }
657
658    #[doc(alias = "button-label")]
659    pub fn connect_button_label_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
660        unsafe extern "C" fn notify_button_label_trampoline<F: Fn(&Toast) + 'static>(
661            this: *mut ffi::AdwToast,
662            _param_spec: glib::ffi::gpointer,
663            f: glib::ffi::gpointer,
664        ) {
665            unsafe {
666                let f: &F = &*(f as *const F);
667                f(&from_glib_borrow(this))
668            }
669        }
670        unsafe {
671            let f: Box_<F> = Box_::new(f);
672            connect_raw(
673                self.as_ptr() as *mut _,
674                c"notify::button-label".as_ptr(),
675                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
676                    notify_button_label_trampoline::<F> as *const (),
677                )),
678                Box_::into_raw(f),
679            )
680        }
681    }
682
683    #[cfg(feature = "v1_2")]
684    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
685    #[doc(alias = "custom-title")]
686    pub fn connect_custom_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
687        unsafe extern "C" fn notify_custom_title_trampoline<F: Fn(&Toast) + 'static>(
688            this: *mut ffi::AdwToast,
689            _param_spec: glib::ffi::gpointer,
690            f: glib::ffi::gpointer,
691        ) {
692            unsafe {
693                let f: &F = &*(f as *const F);
694                f(&from_glib_borrow(this))
695            }
696        }
697        unsafe {
698            let f: Box_<F> = Box_::new(f);
699            connect_raw(
700                self.as_ptr() as *mut _,
701                c"notify::custom-title".as_ptr(),
702                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
703                    notify_custom_title_trampoline::<F> as *const (),
704                )),
705                Box_::into_raw(f),
706            )
707        }
708    }
709
710    #[doc(alias = "priority")]
711    pub fn connect_priority_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
712        unsafe extern "C" fn notify_priority_trampoline<F: Fn(&Toast) + 'static>(
713            this: *mut ffi::AdwToast,
714            _param_spec: glib::ffi::gpointer,
715            f: glib::ffi::gpointer,
716        ) {
717            unsafe {
718                let f: &F = &*(f as *const F);
719                f(&from_glib_borrow(this))
720            }
721        }
722        unsafe {
723            let f: Box_<F> = Box_::new(f);
724            connect_raw(
725                self.as_ptr() as *mut _,
726                c"notify::priority".as_ptr(),
727                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
728                    notify_priority_trampoline::<F> as *const (),
729                )),
730                Box_::into_raw(f),
731            )
732        }
733    }
734
735    #[doc(alias = "timeout")]
736    pub fn connect_timeout_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
737        unsafe extern "C" fn notify_timeout_trampoline<F: Fn(&Toast) + 'static>(
738            this: *mut ffi::AdwToast,
739            _param_spec: glib::ffi::gpointer,
740            f: glib::ffi::gpointer,
741        ) {
742            unsafe {
743                let f: &F = &*(f as *const F);
744                f(&from_glib_borrow(this))
745            }
746        }
747        unsafe {
748            let f: Box_<F> = Box_::new(f);
749            connect_raw(
750                self.as_ptr() as *mut _,
751                c"notify::timeout".as_ptr(),
752                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
753                    notify_timeout_trampoline::<F> as *const (),
754                )),
755                Box_::into_raw(f),
756            )
757        }
758    }
759
760    #[doc(alias = "title")]
761    pub fn connect_title_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
762        unsafe extern "C" fn notify_title_trampoline<F: Fn(&Toast) + 'static>(
763            this: *mut ffi::AdwToast,
764            _param_spec: glib::ffi::gpointer,
765            f: glib::ffi::gpointer,
766        ) {
767            unsafe {
768                let f: &F = &*(f as *const F);
769                f(&from_glib_borrow(this))
770            }
771        }
772        unsafe {
773            let f: Box_<F> = Box_::new(f);
774            connect_raw(
775                self.as_ptr() as *mut _,
776                c"notify::title".as_ptr(),
777                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
778                    notify_title_trampoline::<F> as *const (),
779                )),
780                Box_::into_raw(f),
781            )
782        }
783    }
784
785    #[cfg(feature = "v1_4")]
786    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
787    #[doc(alias = "use-markup")]
788    pub fn connect_use_markup_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
789        unsafe extern "C" fn notify_use_markup_trampoline<F: Fn(&Toast) + 'static>(
790            this: *mut ffi::AdwToast,
791            _param_spec: glib::ffi::gpointer,
792            f: glib::ffi::gpointer,
793        ) {
794            unsafe {
795                let f: &F = &*(f as *const F);
796                f(&from_glib_borrow(this))
797            }
798        }
799        unsafe {
800            let f: Box_<F> = Box_::new(f);
801            connect_raw(
802                self.as_ptr() as *mut _,
803                c"notify::use-markup".as_ptr(),
804                Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
805                    notify_use_markup_trampoline::<F> as *const (),
806                )),
807                Box_::into_raw(f),
808            )
809        }
810    }
811}
812
813impl Default for Toast {
814    fn default() -> Self {
815        glib::object::Object::new::<Self>()
816    }
817}
818
819// rustdoc-stripper-ignore-next
820/// A [builder-pattern] type to construct [`Toast`] objects.
821///
822/// [builder-pattern]: https://doc.rust-lang.org/1.0.0/style/ownership/builders.html
823#[must_use = "The builder must be built to be used"]
824pub struct ToastBuilder {
825    builder: glib::object::ObjectBuilder<'static, Toast>,
826}
827
828impl ToastBuilder {
829    fn new() -> Self {
830        Self {
831            builder: glib::object::Object::builder(),
832        }
833    }
834
835    /// The name of the associated action.
836    ///
837    /// It will be activated when clicking the button.
838    ///
839    /// See [`action-target`][struct@crate::Toast#action-target].
840    pub fn action_name(self, action_name: impl Into<glib::GString>) -> Self {
841        Self {
842            builder: self.builder.property("action-name", action_name.into()),
843        }
844    }
845
846    /// The parameter for action invocations.
847    pub fn action_target(self, action_target: &glib::Variant) -> Self {
848        Self {
849            builder: self
850                .builder
851                .property("action-target", action_target.clone()),
852        }
853    }
854
855    /// The label to show on the button.
856    ///
857    /// Underlines in the button text can be used to indicate a mnemonic.
858    ///
859    /// If set to `NULL`, the button won't be shown.
860    ///
861    /// See [`action-name`][struct@crate::Toast#action-name].
862    pub fn button_label(self, button_label: impl Into<glib::GString>) -> Self {
863        Self {
864            builder: self.builder.property("button-label", button_label.into()),
865        }
866    }
867
868    /// The custom title widget.
869    ///
870    /// It will be displayed instead of the title if set. In this case,
871    /// [`title`][struct@crate::Toast#title] is ignored.
872    ///
873    /// Setting a custom title will unset [`title`][struct@crate::Toast#title].
874    #[cfg(feature = "v1_2")]
875    #[cfg_attr(docsrs, doc(cfg(feature = "v1_2")))]
876    pub fn custom_title(self, custom_title: &impl IsA<gtk::Widget>) -> Self {
877        Self {
878            builder: self
879                .builder
880                .property("custom-title", custom_title.clone().upcast()),
881        }
882    }
883
884    /// The priority of the toast.
885    ///
886    /// Priority controls how the toast behaves when another toast is already
887    /// being displayed.
888    ///
889    /// If the priority is [enum@Adw.ToastPriority.normal], the toast will be
890    /// queued.
891    ///
892    /// If the priority is [enum@Adw.ToastPriority.high], the toast will be
893    /// displayed immediately, pushing the previous toast into the queue instead.
894    pub fn priority(self, priority: ToastPriority) -> Self {
895        Self {
896            builder: self.builder.property("priority", priority),
897        }
898    }
899
900    /// The timeout of the toast, in seconds.
901    ///
902    /// If timeout is 0, the toast is displayed indefinitely until manually
903    /// dismissed.
904    ///
905    /// Toasts cannot disappear while being hovered, pressed (on touchscreen), or
906    /// have keyboard focus inside them.
907    pub fn timeout(self, timeout: u32) -> Self {
908        Self {
909            builder: self.builder.property("timeout", timeout),
910        }
911    }
912
913    /// The title of the toast.
914    ///
915    /// The title can be marked up with the Pango text markup language.
916    ///
917    /// Setting a title will unset [`custom-title`][struct@crate::Toast#custom-title].
918    ///
919    /// If [`custom-title`][struct@crate::Toast#custom-title] is set, it will be used instead.
920    pub fn title(self, title: impl Into<glib::GString>) -> Self {
921        Self {
922            builder: self.builder.property("title", title.into()),
923        }
924    }
925
926    /// Whether to use Pango markup for the toast title.
927    ///
928    /// See also `parse_markup()`.
929    #[cfg(feature = "v1_4")]
930    #[cfg_attr(docsrs, doc(cfg(feature = "v1_4")))]
931    pub fn use_markup(self, use_markup: bool) -> Self {
932        Self {
933            builder: self.builder.property("use-markup", use_markup),
934        }
935    }
936
937    // rustdoc-stripper-ignore-next
938    /// Build the [`Toast`].
939    #[must_use = "Building the object from the builder is usually expensive and is not expected to have side effects"]
940    pub fn build(self) -> Toast {
941        assert_initialized_main_thread!();
942        self.builder.build()
943    }
944}