1#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)]
2
3use nuit::{Text, VStack, View, ViewExt, State, HStack, TextField, Bind, Insets, Frame, ForEach, clone};
4
5#[derive(Bind, Default)]
6struct EnterNameView {
7 raw_names: State<String>,
8}
9
10impl View for EnterNameView {
11 type Body = impl View;
12
13 fn body(&self) -> Self::Body {
14 let raw_names = self.raw_names.clone();
15 VStack::new((
16 HStack::new((
17 Text::new("Please enter some names:"),
18 TextField::new(raw_names.binding()),
19 )),
20 ForEach::new(raw_names.get().split(",").map(|s| s.trim().to_owned()).filter(|s| !s.is_empty()), |name| {
21 Text::new(format!("Hi {}!", name))
22 .on_appear(clone!(name => move || println!("A wild {} appeared!", name)))
23 .on_disappear(clone!(name => move || println!("{} disappeared!", name)))
24 }),
25 ))
26 .padding(Insets::default())
27 .frame(Frame::with_width(400))
28 }
29}
30
31fn main() {
32 nuit::run_app(EnterNameView::default());
33}