pub fn list<ID: Hash, V: View, F: Fn(&ID) -> V + 'static>(
ids: Vec<ID>,
f: F,
) -> List<ID, F>Expand description
Displays a list of items all of which are represented by the same View. See examples/list.rs.
ids is a Vec of items that implement Hash.
f is a function called to generate a View for each item.
For example:
rui(list(vec![1, 2, 3], |i| {
hstack((
circle(),
text(&format!("{:?}", i))
))
}));Examples found in repository?
More examples
examples/counter_list.rs (lines 6-22)
3fn main() {
4 rui(state(Counters::default, |counters, cx| {
5 vstack((
6 list(cx[counters].ids(), move |&i| {
7 with_cx(move |cx| {
8 let count = bind(counters, CounterLens(i));
9 hstack((
10 format!("{}", count.get(cx)).padding(Auto),
11 button("increment", move |cx| {
12 *count.get_mut(cx) += 1;
13 })
14 .padding(Auto),
15 button("decrement", move |cx| {
16 *count.get_mut(cx) -= 1;
17 })
18 .padding(Auto),
19 button("remove", move |cx| cx[counters].remove_counter(i)).padding(Auto),
20 ))
21 })
22 }),
23 format!("total: {}", cx[counters].sum_counters()).padding(Auto),
24 button("add counter", move |cx| cx[counters].add_counter()).padding(Auto),
25 ))
26 }));
27}