use cocoanut::prelude::*;
fn main() -> cocoanut::Result<()> {
let count = state(0);
let count_inc = count.clone();
let count_dec = count.clone();
let count_reset = count.clone();
let display_count = count.clone();
#[cfg(not(test))]
display_count.on_change(move |v| {
cocoanut::state::update_label_by_tag(100, &format!("Count: {}", v));
});
app("Counter")
.size(400.0, 300.0)
.build()
.root(
View::vstack()
.child(View::text("Counter App").bold().font_size(20.0))
.child(View::spacer())
.child(
View::label(format!("Count: {}", count.get()))
.font_size(36.0)
.tag(100),
)
.child(View::spacer())
.child(
View::hstack()
.child(View::button("+").on_click_fn(move || count_inc.increment()))
.child(View::button("-").on_click_fn(move || count_dec.decrement()))
.child(View::button("Reset").on_click_fn(move || count_reset.reset())),
)
.child(View::spacer())
.child(
View::hstack()
.child(
View::button("Dark").on_click_fn(|| set_appearance(Appearance::Dark)),
)
.child(
View::button("Light").on_click_fn(|| set_appearance(Appearance::Light)),
),
),
)
.run()
}