Struct relm4::loading_widgets::LoadingWidgets

source ·
pub struct LoadingWidgets { /* private fields */ }
Expand description

A type that stores widget containers and their child widgets and removes all children automatically when dropped.

This mechanism is used by async components and factories to show widgets while the async init function isn’t completed. Once the actual widgets are initialized, the temporary loading widgets can be removed again, which is simply done with this type.

Implementations§

source§

impl LoadingWidgets

source

pub fn new<C, W>(container: C, child: W) -> Self
where C: RelmRemoveExt + 'static, W: AsRef<C::Child>, C::Child: Clone + AsRef<C::Child>,

Create new LoadingWidgets with one child.

Examples found in repository?
examples/simple_async.rs (line 69)
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    fn init_loading_widgets(root: Self::Root) -> Option<LoadingWidgets> {
        view! {
            #[local]
            root {
                set_title: Some("Simple app"),
                set_default_size: (300, 100),

                // This will be removed automatically by
                // LoadingWidgets when the full view has loaded
                #[name(spinner)]
                gtk::Spinner {
                    start: (),
                    set_halign: gtk::Align::Center,
                }
            }
        }
        Some(LoadingWidgets::new(root, spinner))
    }
More examples
Hide additional examples
examples/factory_async.rs (line 108)
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
    fn init_loading_widgets(root: Self::Root) -> Option<LoadingWidgets> {
        view! {
            #[local]
            root {
                set_orientation: gtk::Orientation::Horizontal,
                set_spacing: 10,

                #[name(spinner)]
                gtk::Spinner {
                    start: (),
                    set_hexpand: true,
                    set_halign: gtk::Align::Center,
                    // Reserve vertical space
                    set_height_request: 34,
                }
            }
        }
        Some(LoadingWidgets::new(root, spinner))
    }
source

pub fn with_children<C, W>(container: C, children: &[W]) -> Self
where C: RelmRemoveExt + 'static, W: AsRef<C::Child>, C::Child: Clone + AsRef<C::Child>,

Create new LoadingWidgets with multiple children.

source

pub fn push<C, W>(&mut self, container: C, child: W)
where C: RelmRemoveExt + 'static, W: AsRef<C::Child>, C::Child: Clone + AsRef<C::Child>,

Add another child to the temporary loading widgets.

source

pub fn add_many<C, W>(&mut self, container: C, children: &[W])
where C: RelmRemoveExt + 'static, W: AsRef<C::Child>, C::Child: Clone + AsRef<C::Child>,

Add many children to the temporary loading widgets.

Trait Implementations§

source§

impl Debug for LoadingWidgets

source§

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

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

impl Drop for LoadingWidgets

source§

fn drop(&mut self)

Executes the destructor for this 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