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

source

pub fn new(overlay: &ToastOverlay) -> Self

Create a new Toaster with a given overlay.

source

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 }
    }
source

pub fn toast(&self, title: &str)

Create a simple adw::Toast that only contains a text message.

source

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§

source§

impl Debug for Toaster

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for Toaster

source§

fn default() -> Toaster

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<C> AsyncPosition<()> for C

source§

fn position(_index: usize)

Returns the position. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<C, I> Position<(), I> for C

source§

fn position(&self, _index: &I)

Returns the position. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more