#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)] use nuit::{Text, VStack, View, Bind, Button, State}; #[derive(Bind)] struct IncrementView { action: F, } impl IncrementView { pub fn new(action: F) -> Self { Self { action } } } impl View for IncrementView where F: Fn() + Clone + 'static { type Body = impl View; fn body(&self) -> Self::Body { let action = self.action.clone(); Button::with_text("Increment", move || { action() }) } } #[derive(Bind, Default)] struct CounterView { count: State, } impl View for CounterView { type Body = impl View; fn body(&self) -> Self::Body { let count = self.count.clone(); VStack::new(( Text::new(format!("Count: {}", count.get())), IncrementView::new(move || { count.set(count.get() + 1); }) )) } } fn main() { nuit::run_app(CounterView::default()); }