adw.toast

Module for [Toast] class

Types 3

A helper object for adw.toast_overlay.ToastOverlay.

Toasts are meant to be passed into adw.toast_overlay.ToastOverlay.addToast as follows:

adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));

toast-simple

Toasts always have a close button. They emit the adw.toast.Toast.dismissed signal when disappearing.

adw.toast.Toast.timeout determines how long the toast stays on screen, while adw.toast.Toast.priority determines how it behaves if another toast is already being displayed.

Toast titles use Pango markup by default, set adw.toast.Toast.useMarkup to FALSE if this is unwanted.

adw.toast.Toast.customTitle can be used to replace the title label with a custom widget.

Actions

Toasts can have one button on them, with a label and an attached gio.action.Action.

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);

toast-action

Modifying toasts

Toasts can be modified after they have been shown. For this, an adw.toast.Toast 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);
}

toast-undo

Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
Toast self() nothrowReturns `this`, for use in `with` statements.
ToastGidBuilder builder() static nothrowGet builder for [adw.toast.Toast] Returns: New builder object
string actionName() @property nothrowGet `actionName` property. Returns: The name of the associated action.
void actionName(string propval) @property nothrowSet `actionName` property. Params: propval = The name of the associated action.
glib.variant.Variant actionTarget() @property nothrowGet `actionTarget` property. Returns: The parameter for action invocations.
void actionTarget(glib.variant.Variant propval) @property nothrowSet `actionTarget` property. Params: propval = The parameter for action invocations.
string buttonLabel() @property nothrowGet `buttonLabel` property. Returns: The label to show on the button.
void buttonLabel(string propval) @property nothrowSet `buttonLabel` property. Params: propval = The label to show on the button.
gtk.widget.Widget customTitle() @property nothrowGet `customTitle` property. Returns: The custom title widget.
void customTitle(gtk.widget.Widget propval) @property nothrowSet `customTitle` property. Params: propval = The custom title widget.
adw.types.ToastPriority priority() @property nothrowGet `priority` property. Returns: The priority of the toast.
void priority(adw.types.ToastPriority propval) @property nothrowSet `priority` property. Params: propval = The priority of the toast.
uint timeout() @property nothrowGet `timeout` property. Returns: The timeout of the toast, in seconds.
void timeout(uint propval) @property nothrowSet `timeout` property. Params: propval = The timeout of the toast, in seconds.
string title() @property nothrowGet `title` property. Returns: The title of the toast.
void title(string propval) @property nothrowSet `title` property. Params: propval = The title of the toast.
bool useMarkup() @property nothrowGet `useMarkup` property. Returns: Whether to use Pango markup for the toast title.
void useMarkup(bool propval) @property nothrowSet `useMarkup` property. Params: propval = Whether to use Pango markup for the toast title.
void dismiss() nothrowDismisses self.
string getActionName() nothrowGets the name of the associated action. Returns: the action name
glib.variant.Variant getActionTargetValue() nothrowGets the parameter for action invocations. Returns: the action target
string getButtonLabel() nothrowGets the label to show on the button. Returns: the button label
gtk.widget.Widget getCustomTitle() nothrowGets the custom title widget of self. Returns: the custom title widget
adw.types.ToastPriority getPriority() nothrowGets priority for self. Returns: the priority
uint getTimeout() nothrowGets timeout for self. Returns: the timeout
string getTitle() nothrowGets the title that will be displayed on the toast.
bool getUseMarkup() nothrowGets whether to use Pango markup for the toast title. Returns: whether the toast uses markup
void setActionName(string actionName = null) nothrowSets the name of the associated action.
void setActionTargetValue(glib.variant.Variant actionTarget = null) nothrowSets the parameter for action invocations.
void setButtonLabel(string buttonLabel = null) nothrowSets the label to show on the button.
void setCustomTitle(gtk.widget.Widget widget = null) nothrowSets the custom title widget of self.
void setDetailedActionName(string detailedActionName = null) nothrowSets the action name and its parameter.
void setPriority(adw.types.ToastPriority priority) nothrowSets priority for self.
void setTimeout(uint timeout) nothrowSets timeout for self.
void setTitle(string title) nothrowSets the title that will be displayed on the toast.
void setUseMarkup(bool useMarkup) nothrowWhether to use Pango markup for the toast title.
gulong connectButtonClicked(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : adw.toast.Toast))) && Parameters!T.length < 2) nothrowConnect to `ButtonClicked` signal.
gulong connectDismissed(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] : adw.toast.Toast))) && Parameters!T.length < 2) nothrowConnect to `Dismissed` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this(string title)Creates a new [adw.toast.Toast].

Fluent builder implementation template for adw.toast.Toast

Methods
T actionName(string propval) nothrowSet `actionName` property. Params: propval = The name of the associated action.
T actionTarget(glib.variant.Variant propval) nothrowSet `actionTarget` property. Params: propval = The parameter for action invocations. Returns: Builder instance for fluent chaining
T buttonLabel(string propval) nothrowSet `buttonLabel` property. Params: propval = The label to show on the button.
T customTitle(gtk.widget.Widget propval) nothrowSet `customTitle` property. Params: propval = The custom title widget.
T priority(adw.types.ToastPriority propval) nothrowSet `priority` property. Params: propval = The priority of the toast.
T timeout(uint propval) nothrowSet `timeout` property. Params: propval = The timeout of the toast, in seconds.
T title(string propval) nothrowSet `title` property. Params: propval = The title of the toast.
T useMarkup(bool propval) nothrowSet `useMarkup` property. Params: propval = Whether to use Pango markup for the toast title.

Fluent builder for adw.toast.Toast

Methods
Toast build() nothrowCreate object from builder. Returns: New object