Macro fractal::toast

source ยท
macro_rules! toast {
    ($widget:expr, $message:expr) => { ... };
    ($widget:expr, $message:expr, $($tail:tt)+) => { ... };
}
Expand description

Show a toast with the given message on the ancestor window of widget.

The simplest way to use this macros is for displaying a simple message. It can be anything that implements AsRef<str>.

use gettextts::gettext;

use crate::toast;

toast!(widget, gettext("Something happened"));

This macro also supports replacing named variables with their value. It supports both the var and the var = expr syntax. In this case the message and the variables must be Strings.

use gettextts::gettext;

use crate::toast;

toast!(
    widget,
    gettext("Error number {n}: {msg}"),
    n = error_nb.to_string(),
    msg,
);

To add Pills to the toast, you can precede a Room or User with @.

use gettextts::gettext;
use crate::toast;
use crate::session::model::{Room, User};

let room = Room::new(session, room_id);
let member = Member::new(room, user_id);

toast!(
    widget,
    gettext("Could not contact {user} in {room}"),
    @user = member,
    @room,
);

For this macro to work, the ancestor window be a Window or an adw::PreferencesWindow.