It derives from <GObject>.
A helper object for ToastOverlay.
Toasts are meant to be passed into ToastOverlay.add_toast as
follows:
adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
Toasts always have a close button. They emit the "dismissed"
signal when disappearing.
Toast:timeout determines how long the toast stays on screen,
while Toast:priority determines how it behaves if another toast
is already being displayed.
Toast titles use Pango markup by default, set Toast:use-markup to
FALSE if this is unwanted.
Toast:custom-title can be used to replace the title label with a
custom widget.
Toasts can have one button on them, with a label and an attached
<GAction>.
AdwToast *toast = adw_toast_new (_("Toast with Action"));
adw_toast_set_button_label (toast, _("_Example"));
adw_toast_set_action_name (toast, "win.example");
adw_toast_overlay_add_toast (overlay, toast);
Toasts can be modified after they have been shown. For this, an
<AdwToast> reference must be kept around while the
toast is visible.
A common use case for this is using toasts as undo prompts that stack with each other, allowing to batch undo the last deleted items:
static void
toast_undo_cb (GtkWidget *sender,
const char *action,
GVariant *param)
{
// Undo the deletion
}
static void
dismissed_cb (MyWindow *self)
{
self->undo_toast = NULL;
// Permanently delete the items
}
static void
delete_item (MyWindow *self,
MyItem *item)
{
g_autofree char *title = NULL;
int n_items;
// Mark the item as waiting for deletion
n_items = ... // The number of waiting items
if (!self->undo_toast) {
self->undo_toast = adw_toast_new_format (_("‘%s’ deleted"), ...);
adw_toast_set_priority (self->undo_toast, ADW_TOAST_PRIORITY_HIGH);
adw_toast_set_button_label (self->undo_toast, _("_Undo"));
adw_toast_set_action_name (self->undo_toast, "toast.undo");
g_signal_connect_swapped (self->undo_toast, "dismissed",
G_CALLBACK (dismissed_cb), self);
adw_toast_overlay_add_toast (self->toast_overlay, self->undo_toast);
return;
}
title =
g_strdup_printf (ngettext ("<span font_features='tnum=1'>%d</span> item deleted",
"<span font_features='tnum=1'>%d</span> items deleted",
n_items), n_items);
adw_toast_set_title (self->undo_toast, title);
// Bump the toast timeout
adw_toast_overlay_add_toast (self->toast_overlay, g_object_ref (self->undo_toast));
}
static void
my_window_class_init (MyWindowClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_install_action (widget_class, "toast.undo", NULL, toast_undo_cb);
}
The name of the associated action.
It will be activated when clicking the button.
See Toast:action-target.
Its value is a string, or #f.
Set it with (set! (toast:action-name self) value).
The parameter for action invocations.
Its value is a <GVariant>, or #f.
Set it with (set! (toast:action-target self) value).
The label to show on the button.
Underlines in the button text can be used to indicate a mnemonic.
If set to NULL, the button won’t be shown.
See Toast:action-name.
Its value is a string, or #f.
Set it with (set! (toast:button-label self) value).
The custom title widget.
It will be displayed instead of the title if set. In this case,
Toast:title is ignored.
Setting a custom title will unset Toast:title.
Its value is a <GtkWidget>, or #f.
Set it with (set! (toast:custom-title self) value).
The priority of the toast.
Priority controls how the toast behaves when another toast is already being displayed.
If the priority is Adw.ToastPriority.normal, the toast will be
queued.
If the priority is Adw.ToastPriority.high, the toast will be
displayed immediately, pushing the previous toast into the queue
instead.
Its value is a <AdwToastPriority> (or, to
set it, one of its symbols).
Set it with (set! (toast:priority self) value).
The timeout of the toast, in seconds.
If timeout is 0, the toast is displayed indefinitely until manually dismissed.
Toasts cannot disappear while being hovered, pressed (on touchscreen), or have keyboard focus inside them.
Its value is an unsigned 32-bit integer.
Set it with (set! (toast:timeout self) value).
The title of the toast.
The title can be marked up with the Pango text markup language.
Setting a title will unset Toast:custom-title.
If Toast:custom-title is set, it will be used instead.
Its value is a string, or #f.
Set it with (set! (toast:title self) value).
Whether to use Pango markup for the toast title.
See also parse-markup.
Its value is a boolean.
Set it with (set! (toast:use-markup self) value).
Dismisses self.
Does nothing if self has already been dismissed, or hasn’t been
added to an ToastOverlay.
Passed: a <AdwToast>.
a toast
Gets the name of the associated action.
Passed: a <AdwToast>.
a toast
Returned: a string, or #f.
the action name
Gets the parameter for action invocations.
Passed: a <AdwToast>.
a toast
Returned: a <GVariant>, or #f.
the action target
Gets the label to show on the button.
Passed: a <AdwToast>.
a toast
Returned: a string, or #f.
the button label
Gets the custom title widget of self.
Passed: a <AdwToast>.
a toast
Returned: a <GtkWidget>, or #f.
the custom title widget
Gets priority for self.
Passed: a <AdwToast>.
a toast
Returned: a <AdwToastPriority>.
the priority
Gets timeout for self.
Passed: a <AdwToast>.
a toast
Returned: an unsigned 32-bit integer.
the timeout
Gets the title that will be displayed on the toast.
If a custom title has been set with toast:set-custom-title the return value will be
#f.
Passed: a <AdwToast>.
a toast
Returned: a string, or #f.
the title
Gets whether to use Pango markup for the toast title.
Passed: a <AdwToast>.
a toast
Returned: a boolean.
whether the toast uses markup
Creates a new <AdwToast>.
The toast will use title as its title.
title can be marked up with the Pango text markup language.
Passed: a string.
the title to be displayed
Returned: a <AdwToast>.
the new created <AdwToast>
Sets the name of the associated action.
It will be activated when clicking the button.
See Toast:action-target.
Passed: a <AdwToast>.
a toast
Passed, or left out: a string, or #f.
the action name
Sets the parameter for action invocations.
If the action-target variant has a floating reference this function will sink it.
Passed: a <AdwToast>.
a toast
Passed, or left out: a <GVariant>, or
#f.
the action target
Sets the label to show on the button.
Underlines in the button text can be used to indicate a mnemonic.
If set to NULL, the button won’t be shown.
See Toast:action-name.
Passed: a <AdwToast>.
a toast
Passed, or left out: a string, or #f.
a button label
Sets the custom title widget of self.
It will be displayed instead of the title if set. In this case,
Toast:title is ignored.
Setting a custom title will unset Toast:title.
Passed: a <AdwToast>.
a toast
Passed, or left out: a <GtkWidget>, or
#f.
the custom title widget
Sets the action name and its parameter.
detailed-action-name is a string in the format accepted by
action:parse-detailed-name.
Passed: a <AdwToast>.
a toast
Passed, or left out: a string, or #f.
the detailed action name
Sets priority for self.
Priority controls how the toast behaves when another toast is already being displayed.
If priority is Adw.ToastPriority.normal, the toast will be
queued.
If priority is Adw.ToastPriority.high, the toast will be
displayed immediately, pushing the previous toast into the queue
instead.
Passed: a <AdwToast>.
a toast
Passed: a <AdwToastPriority>, or one of its
symbols.
the priority
Sets timeout for self.
If timeout is 0, the toast is displayed indefinitely until manually dismissed.
Toasts cannot disappear while being hovered, pressed (on touchscreen), or have keyboard focus inside them.
Passed: a <AdwToast>.
a toast
Passed: an unsigned 32-bit integer.
the timeout
Sets the title that will be displayed on the toast.
The title can be marked up with the Pango text markup language.
Setting a title will unset Toast:custom-title.
If Toast:custom-title is set, it will be used instead.
Passed: a <AdwToast>.
a toast
Passed: a string.
a title
Whether to use Pango markup for the toast title.
See also parse-markup.
Passed: a <AdwToast>.
a toast
Passed: a boolean.
whether to use markup
Connect a handler with (connect object toast:button-clicked
handler). It is called as (handler self).
Emitted after the button has been clicked.
It can be used as an alternative to setting an action.
Passed: a <AdwToast>.
Connect a handler with (connect object toast:dismissed handler).
It is called as (handler self).
Emitted when the toast has been dismissed.
Passed: a <AdwToast>.