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
impl LoadingWidgets
sourcepub fn new<C, W>(container: &C, child: W) -> Selfwhere
C: RelmRemoveExt + Clone + 'static,
W: AsRef<C::Child>,
C::Child: Clone + AsRef<C::Child>,
pub fn new<C, W>(container: &C, child: W) -> Selfwhere C: RelmRemoveExt + Clone + 'static, W: AsRef<C::Child>, C::Child: Clone + AsRef<C::Child>,
Create new LoadingWidgets
with one child.
Examples found in repository?
relm4/examples/simple_async.rs (line 70)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
fn init_loading_widgets(root: &mut Self::Root) -> Option<LoadingWidgets> {
view! {
#[local_ref]
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
relm4/examples/factory_async.rs (line 109)
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
fn init_loading_widgets(root: &mut Self::Root) -> Option<LoadingWidgets> {
view! {
#[local_ref]
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))
}
sourcepub fn with_children<C, W>(container: &C, children: &[W]) -> Selfwhere
C: RelmRemoveExt + Clone + 'static,
W: AsRef<C::Child>,
C::Child: Clone + AsRef<C::Child>,
pub fn with_children<C, W>(container: &C, children: &[W]) -> Selfwhere C: RelmRemoveExt + Clone + 'static, W: AsRef<C::Child>, C::Child: Clone + AsRef<C::Child>,
Create new LoadingWidgets
with multiple children.