Function floem::views::dyn_container
source · pub fn dyn_container<CF: Fn(T) -> Box<dyn View> + 'static, T: 'static>(
update_view: impl Fn() -> T + 'static,
child_fn: CF
) -> DynamicContainer<T>
Expand description
A container for a dynamically updating View
Example
ⓘ
use floem::{
reactive::create_rw_signal,
view::View,
views::{dyn_container, label, v_stack, Decorators},
widgets::toggle_button,
};
#[derive(Clone)]
enum ViewSwitcher {
One,
Two,
}
fn app_view() -> impl View {
let view = create_rw_signal(ViewSwitcher::One);
v_stack((
toggle_button(|| true)
.on_toggle(move |is_on| {
if is_on {
view.update(|val| *val = ViewSwitcher::One);
} else {
view.update(|val| *val = ViewSwitcher::Two);
}
})
.style(|s| s.margin_bottom(20)),
dyn_container(
move || view.get(),
move |value| match value {
ViewSwitcher::One => Box::new(label(|| "One")),
ViewSwitcher::Two => Box::new(v_stack((label(|| "Stacked"), label(|| "Two")))),
},
),
))
.style(|s| {
s.width_full()
.height_full()
.items_center()
.justify_center()
.gap(10, 0)
})
}
fn main() {
floem::launch(app_view);
}
See container_box for more documentation on a general container