1#![feature(type_alias_impl_trait, impl_trait_in_assoc_type)]
2
3use nuit::{VStack, View, Bind, State, Picker, Id, Text, Button, clone};
4
5#[derive(Bind, Default)]
6struct PickerView {
7 selection: State<Id>,
8}
9
10impl View for PickerView {
11 type Body = impl View;
12
13 fn body(&self) -> Self::Body {
14 let selection = self.selection.clone();
15 VStack::new((
16 Picker::new("Favorite Color", selection.binding(), (
17 Text::new("Red"),
18 Text::new("Green"),
19 Text::new("Yellow"),
20 Text::new("Blue"),
21 )),
22 Button::with_text("Choose next", clone!(selection => move || {
23 if let Id::Index(i) = selection.get() {
24 selection.set((i + 1) % 4);
25 }
26 }))
27 ))
28 }
29}
30
31fn main() {
32 nuit::run_app(PickerView::default());
33}