dyn_container

Function dyn_container 

Source
pub fn dyn_container<CF: Fn(T) -> IV + 'static, T: 'static, IV: IntoView>(
    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, SignalGet, SignalUpdate},
    views::{dyn_container, label, toggle_button, v_stack, Decorators},
    IntoView, View,
};

#[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 => label(|| "One").into_any(),
                ViewSwitcher::Two => v_stack((label(|| "Stacked"), label(|| "Two"))).into_any(),
            },
        ),
    ))
    .style(|s| {
        s.width_full()
            .height_full()
            .items_center()
            .justify_center()
            .row_gap(10)
    })
}