Package ch.bailu.gtk.adw
Class Toast
java.lang.Object
ch.bailu.gtk.type.Type
ch.bailu.gtk.type.Pointer
ch.bailu.gtk.gobject.Object
ch.bailu.gtk.adw.Toast
- All Implemented Interfaces:
PointerInterface
A helper object for [class@ToastOverlay].
Toasts are meant to be passed into [method@ToastOverlay.add_toast] as
follows:
```c
adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
```
<picture>
<source srcset="toast-simple-dark.png" media="(prefers-color-scheme: dark)">
<img src="toast-simple.png" alt="toast-simple">
</picture>
Toasts always have a close button. They emit the [signal@Toast::dismissed]
signal when disappearing.
[property@Toast:timeout] determines how long the toast stays on screen, while
[property@Toast:priority] determines how it behaves if another toast is
already being displayed.
[property@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
[iface@Gio.Action].
```c
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);
```
<picture>
<source srcset="toast-action-dark.png" media="(prefers-color-scheme: dark)">
<img src="toast-action.png" alt="toast-action">
</picture>
## 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:
```c
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);
}
```
<picture>
<source srcset="toast-undo-dark.png" media="(prefers-color-scheme: dark)">
<img src="toast-undo.png" alt="toast-undo">
</picture>
Toasts are meant to be passed into [method@ToastOverlay.add_toast] as
follows:
```c
adw_toast_overlay_add_toast (overlay, adw_toast_new (_("Simple Toast")));
```
<picture>
<source srcset="toast-simple-dark.png" media="(prefers-color-scheme: dark)">
<img src="toast-simple.png" alt="toast-simple">
</picture>
Toasts always have a close button. They emit the [signal@Toast::dismissed]
signal when disappearing.
[property@Toast:timeout] determines how long the toast stays on screen, while
[property@Toast:priority] determines how it behaves if another toast is
already being displayed.
[property@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
[iface@Gio.Action].
```c
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);
```
<picture>
<source srcset="toast-action-dark.png" media="(prefers-color-scheme: dark)">
<img src="toast-action.png" alt="toast-action">
</picture>
## 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:
```c
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);
}
```
<picture>
<source srcset="toast-undo-dark.png" media="(prefers-color-scheme: dark)">
<img src="toast-undo.png" alt="toast-undo">
</picture>
https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/class.Toast.html
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
Nested classes/interfaces inherited from class ch.bailu.gtk.gobject.Object
Object.OnBindingTransformFunc, Object.OnDestroyNotify, Object.OnDuplicateFunc, Object.OnNotify, Object.OnToggleNotify, Object.OnWeakNotify
-
Field Summary
Fields inherited from class ch.bailu.gtk.gobject.Object
SIGNAL_ON_NOTIFY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dismiss()
Dismisses @self.Gets the name of the associated action.Gets the parameter for action invocations.Gets the label to show on the button.static ClassHandler
Gets the custom title widget of @self.static int
static long
static TypeSystem.TypeSize
int
Gets priority for @self.int
Gets timeout for @self.getTitle()
Gets the title that will be displayed on the toast.static long
static TypeSystem.TypeSize
static Toast
newFormatToast
(Str format, Object... _elipse) Creates a new `AdwToast`.static Toast
newFormatToast
(String format, Object... _elipse) Creates a new `AdwToast`.onButtonClicked
(Toast.OnButtonClicked signal) Connect to signal "button-clicked".onDismissed
(Toast.OnDismissed signal) Connect to signal "dismissed".void
setActionName
(Str action_name) Sets the name of the associated action.void
setActionName
(String action_name) Sets the name of the associated action.void
setActionTarget
(Str format_string, Object... _elipse) Sets the parameter for action invocations.void
setActionTarget
(String format_string, Object... _elipse) Sets the parameter for action invocations.void
setActionTargetValue
(Variant action_target) Sets the parameter for action invocations.void
setButtonLabel
(Str button_label) Sets the label to show on the button.void
setButtonLabel
(String button_label) Sets the label to show on the button.void
setCustomTitle
(Widget widget) Sets the custom title widget of @self.void
setDetailedActionName
(Str detailed_action_name) Sets the action name and its parameter.void
setDetailedActionName
(String detailed_action_name) Sets the action name and its parameter.void
setPriority
(int priority) Sets priority for @self.void
setTimeout
(int timeout) Sets timeout for @self.void
Sets the title that will be displayed on the toast.void
Sets the title that will be displayed on the toast.Methods inherited from class ch.bailu.gtk.gobject.Object
addToggleRef, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, disconnect, disconnect, dupData, dupData, dupQdata, forceFloating, freezeNotify, get, get, getData, getData, getProperty, getProperty, getQdata, interfaceFindProperty, interfaceInstallProperty, isFloating, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, replaceData, replaceData, replaceQdata, runDispose, set, set, setData, setData, setDataFull, setDataFull, setProperty, setProperty, setQdata, setQdataFull, stealData, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref
Methods inherited from class ch.bailu.gtk.type.Pointer
asCPointer, cast, connectSignal, disconnectSignals, disconnectSignals, equals, hashCode, throwIfNull, throwNullPointerException, toString, unregisterCallbacks, unregisterCallbacks
Methods inherited from class ch.bailu.gtk.type.Type
asCPointer, asCPointer, asCPointerNotNull, asJnaPointer, asJnaPointer, asPointer, asPointer, cast, cast, throwIfNull
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ch.bailu.gtk.type.PointerInterface
asCPointerNotNull, asJnaPointer, asPointer, isNotNull, isNull
-
Field Details
-
SIGNAL_ON_BUTTON_CLICKED
- See Also:
-
SIGNAL_ON_DISMISSED
- See Also:
-
-
Constructor Details
-
Toast
-
Toast
Creates a new `AdwToast`.
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
-
Toast
Creates a new `AdwToast`.
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
-
getClassHandler
-
newFormatToast
Creates a new `AdwToast`.
The toast will use the format string as its title.
See also: [ctor@Toast.new]- Parameters:
format
- the formatted string for the toast title_elipse
- the parameters to insert into the format string- Returns:
- the newly created toast object
-
newFormatToast
Creates a new `AdwToast`.
The toast will use the format string as its title.
See also: [ctor@Toast.new]- Parameters:
format
- the formatted string for the toast title_elipse
- the parameters to insert into the format string- Returns:
- the newly created toast object
-
dismiss
public void dismiss()Dismisses @self.
Does nothing if @self has already been dismissed, or hasn't been added to an
[class@ToastOverlay]. -
getActionName
Gets the name of the associated action.- Returns:
- the action name
-
getActionTargetValue
Gets the parameter for action invocations.- Returns:
- the action target
-
getButtonLabel
Gets the label to show on the button.- Returns:
- the button label
-
getCustomTitle
Gets the custom title widget of @self.- Returns:
- the custom title widget
-
getPriority
public int getPriority()Gets priority for @self.- Returns:
- the priority
-
getTimeout
public int getTimeout()Gets timeout for @self.- Returns:
- the timeout
-
getTitle
Gets the title that will be displayed on the toast.
If a custom title has been set with [method@Adw.Toast.set_custom_title]
the return value will be %NULL.- Returns:
- the title
-
setActionName
Sets the name of the associated action.
It will be activated when clicking the button.
See [property@Toast:action-target].- Parameters:
action_name
- the action name
-
setActionName
Sets the name of the associated action.
It will be activated when clicking the button.
See [property@Toast:action-target].- Parameters:
action_name
- the action name
-
setActionTarget
Sets the parameter for action invocations.
This is a convenience function that calls [ctor@GLib.Variant.new] for
@format_string and uses the result to call
[method@Toast.set_action_target_value].
If you are setting a string-valued target and want to set
the action name at the same time, you can use
[method@Toast.set_detailed_action_name].- Parameters:
format_string
- a variant format string_elipse
- arguments appropriate for @target_format
-
setActionTarget
Sets the parameter for action invocations.
This is a convenience function that calls [ctor@GLib.Variant.new] for
@format_string and uses the result to call
[method@Toast.set_action_target_value].
If you are setting a string-valued target and want to set
the action name at the same time, you can use
[method@Toast.set_detailed_action_name].- Parameters:
format_string
- a variant format string_elipse
- arguments appropriate for @target_format
-
setActionTargetValue
Sets the parameter for action invocations.
If the @action_target variant has a floating reference this function
will sink it.- Parameters:
action_target
- 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 [property@Toast:action-name].- Parameters:
button_label
- a button label
-
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 [property@Toast:action-name].- Parameters:
button_label
- a button label
-
setCustomTitle
Sets the custom title widget of @self.
It will be displayed instead of the title if set. In this case,
[property@Toast:title] is ignored.
Setting a custom title will unset [property@Toast:title].- Parameters:
widget
- the custom title widget
-
setDetailedActionName
Sets the action name and its parameter.
@detailed_action_name is a string in the format accepted by
[func@Gio.Action.parse_detailed_name].- Parameters:
detailed_action_name
- the detailed action name
-
setDetailedActionName
Sets the action name and its parameter.
@detailed_action_name is a string in the format accepted by
[func@Gio.Action.parse_detailed_name].- Parameters:
detailed_action_name
- the detailed action name
-
setPriority
public void setPriority(int priority) Sets priority for @self.
Priority controls how the toast behaves when another toast is already
being displayed.
If @priority is `ADW_TOAST_PRIORITY_NORMAL`, the toast will be queued.
If @priority is `ADW_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 @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.- 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 [property@Toast:custom-title].
If [property@Toast:custom-title] is set, it will be used instead.- Parameters:
title
- a title
-
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 [property@Toast:custom-title].
If [property@Toast:custom-title] is set, it will be used instead.- Parameters:
title
- a title
-
onButtonClicked
Connect to signal "button-clicked".
SeeToast.OnButtonClicked.onButtonClicked()
for signal description.
FieldSIGNAL_ON_BUTTON_CLICKED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
onDismissed
Connect to signal "dismissed".
SeeToast.OnDismissed.onDismissed()
for signal description.
FieldSIGNAL_ON_DISMISSED
contains original signal name and can be used as resource reference.- Parameters:
signal
- callback function (lambda).- Returns:
SignalHandler
. Can be used to disconnect signal and to release callback function.
-
getTypeID
public static long getTypeID() -
getParentTypeID
public static long getParentTypeID() -
getTypeSize
-
getParentTypeSize
-
getInstanceSize
public static int getInstanceSize()
-