Struct relm4::abstractions::Toaster
source · pub struct Toaster { /* private fields */ }
Available on crate feature
libadwaita
only.Expand description
An abstraction over adw::ToastOverlay
that
makes it easy to store it in the model of components.
The only allowed action is to add toasts, effectively keeping the separation between UI and application state.
Implementations§
source§impl Toaster
impl Toaster
sourcepub fn new(overlay: &ToastOverlay) -> Self
pub fn new(overlay: &ToastOverlay) -> Self
Create a new Toaster
with a given overlay.
sourcepub fn overlay_widget(&self) -> &ToastOverlay
pub fn overlay_widget(&self) -> &ToastOverlay
The adw::ToastOverlay
used internally.
Examples found in repository?
examples/toast.rs (line 79)
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
fn init(
_: Self::Init,
root: Self::Root,
sender: ComponentSender<Self>,
) -> ComponentParts<Self> {
let model = App {
activated: "Idle",
toaster: Toaster::default(),
};
let toast_overlay = model.toaster.overlay_widget();
// Insert the code generation of the view! macro here
let widgets = view_output!();
ComponentParts { model, widgets }
}
sourcepub fn toast(&self, title: &str)
pub fn toast(&self, title: &str)
Create a simple adw::Toast
that only contains
a text message.
sourcepub fn add_toast(&self, toast: Toast)
pub fn add_toast(&self, toast: Toast)
Add a adw::Toast
to the overlay.
Examples found in repository?
examples/toast.rs (line 100)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
fn update(&mut self, msg: Self::Input, sender: ComponentSender<Self>) {
match msg {
Msg::Activate => {
self.activated = "Active";
let toast = adw::Toast::builder()
.title("Activated")
.button_label("Cancel")
.timeout(0)
.build();
toast.connect_button_clicked(move |this| {
this.dismiss();
sender.input(Msg::Cancel);
});
self.toaster.add_toast(toast);
}
Msg::Cancel => self.activated = "Idle",
}
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Toaster
impl RefUnwindSafe for Toaster
impl !Send for Toaster
impl !Sync for Toaster
impl Unpin for Toaster
impl UnwindSafe for Toaster
Blanket Implementations§
source§impl<C> AsyncPosition<()> for C
impl<C> AsyncPosition<()> for C
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more