Class Toast
- All Implemented Interfaces:
Proxy
ToastOverlay
.
Toasts are meant to be passed into ToastOverlay.addToast(org.gnome.adw.Toast)
as
follows:
adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
Toasts always have a close button. They emit the Toast::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.
Actions
Toasts can have one button on them, with a label and an attached
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);
Modifying toasts
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);
}
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Toast.Builder<B extends Toast.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theButtonClickedCallback
callback.static interface
Functional interface declaration of theDismissedCallback
callback.static class
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
-
Constructor Summary
ConstructorDescriptionToast
(MemorySegment address) Create a Toast proxy instance for the provided memory address.Creates a newAdwToast
. -
Method Summary
Modifier and TypeMethodDescriptionprotected Toast
asParent()
Returns this instance as if it were its parent type.static Toast.Builder
<? extends Toast.Builder> builder()
AToast.Builder
object constructs aToast
with the specified properties.void
dismiss()
Dismisses this Toast.void
Emits the "button-clicked" signal.void
Emits the "dismissed" signal.static Toast
Creates a newAdwToast
.Gets the name of the associated action.Gets the parameter for action invocations.Gets the label to show on the button.Gets the custom title widget of this Toast.Gets priority for this Toast.int
Gets timeout for this Toast.getTitle()
Gets the title that will be displayed on the toast.static Type
getType()
Get the GType of the Toast classboolean
Gets whether to use Pango markup for the toast title.Emitted after the button has been clicked.onDismissed
(Toast.DismissedCallback handler) Emitted when the toast has been dismissed.void
setActionName
(@Nullable String actionName) Sets the name of the associated action.void
setActionTarget
(@Nullable String formatString, Object... varargs) Sets the parameter for action invocations.void
setActionTargetValue
(@Nullable Variant actionTarget) Sets the parameter for action invocations.void
setButtonLabel
(@Nullable String buttonLabel) Sets the label to show on the button.void
setCustomTitle
(@Nullable Widget widget) Sets the custom title widget of this Toast.void
setDetailedActionName
(@Nullable String detailedActionName) Sets the action name and its parameter.void
setPriority
(ToastPriority priority) Sets priority for this Toast.void
setTimeout
(int timeout) Sets timeout for this Toast.void
Sets the title that will be displayed on the toast.void
setUseMarkup
(boolean useMarkup) Whether to use Pango markup for the toast title.Methods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getMemoryLayout, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newInstance, newInstance, newv, notify_, notify_, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Toast
Create a Toast proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
Toast
Creates a newAdwToast
.The toast will use
title
as its title.title
can be marked up with the Pango text markup language.- Parameters:
title
- the title to be displayed
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()
doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName()
. This will call the native function pointer of this virtual method in the typeclass of the parent type. -
format
Creates a newAdwToast
.The toast will use the format string as its title.
See also:
Toast(java.lang.String)
- Parameters:
format
- the formatted string for the toast titlevarargs
- the parameters to insert into the format string- Returns:
- the newly created toast object
-
dismiss
public void dismiss()Dismisses this Toast.Does nothing if this Toast has already been dismissed, or hasn't been added to an
ToastOverlay
. -
getActionName
-
getActionTargetValue
Gets the parameter for action invocations.- Returns:
- the action target
-
getButtonLabel
-
getCustomTitle
Gets the custom title widget of this Toast.- Returns:
- the custom title widget
-
getPriority
-
getTimeout
public int getTimeout()Gets timeout for this Toast.- Returns:
- the timeout
-
getTitle
Gets the title that will be displayed on the toast.If a custom title has been set with
setCustomTitle(org.gnome.gtk.Widget)
the return value will benull
.- Returns:
- the title
-
getUseMarkup
public boolean getUseMarkup()Gets whether to use Pango markup for the toast title.- Returns:
- whether the toast uses markup
-
setActionName
Sets the name of the associated action.It will be activated when clicking the button.
See
Toast:action-target
.- Parameters:
actionName
- the action name
-
setActionTarget
Sets the parameter for action invocations.This is a convenience function that calls
Variant(java.lang.String, java.lang.Object...)
forformatString
and uses the result to callsetActionTargetValue(org.gnome.glib.Variant)
.If you are setting a string-valued target and want to set the action name at the same time, you can use
setDetailedActionName(java.lang.String)
.- Parameters:
formatString
- a variant format stringvarargs
- arguments appropriate fortargetFormat
-
setActionTargetValue
Sets the parameter for action invocations.If the
actionTarget
variant has a floating reference this function will sink it.- Parameters:
actionTarget
- the action target
-
setButtonLabel
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
.- Parameters:
buttonLabel
- a button label
-
setCustomTitle
Sets the custom title widget of this Toast.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
.- Parameters:
widget
- the custom title widget
-
setDetailedActionName
Sets the action name and its parameter.detailedActionName
is a string in the format accepted byAction.parseDetailedName(java.lang.String, io.github.jwharm.javagi.base.Out<java.lang.String>, io.github.jwharm.javagi.base.Out<org.gnome.glib.Variant>)
.- Parameters:
detailedActionName
- the detailed action name
-
setPriority
Sets priority for this Toast.Priority controls how the toast behaves when another toast is already being displayed.
If
priority
isADW_TOAST_PRIORITY_NORMAL
, the toast will be queued.If
priority
isADW_TOAST_PRIORITY_HIGH
, the toast will be displayed immediately, pushing the previous toast into the queue instead.- Parameters:
priority
- the priority
-
setTimeout
public void setTimeout(int timeout) Sets timeout for this Toast.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.
- Parameters:
timeout
- the timeout
-
setTitle
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.- Parameters:
title
- a title
-
setUseMarkup
public void setUseMarkup(boolean useMarkup) Whether to use Pango markup for the toast title.- Parameters:
useMarkup
- whether to use markup
-
onButtonClicked
public SignalConnection<Toast.ButtonClickedCallback> onButtonClicked(Toast.ButtonClickedCallback handler) Emitted after the button has been clicked.It can be used as an alternative to setting an action.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitButtonClicked
public void emitButtonClicked()Emits the "button-clicked" signal. SeeonButtonClicked(org.gnome.adw.Toast.ButtonClickedCallback)
. -
onDismissed
Emitted when the toast has been dismissed.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitDismissed
public void emitDismissed()Emits the "dismissed" signal. SeeonDismissed(org.gnome.adw.Toast.DismissedCallback)
. -
builder
AToast.Builder
object constructs aToast
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withToast.Builder.build()
.
-