diff options
Diffstat (limited to 'examples/cached')
| -rw-r--r-- | examples/cached/src/main.rs | 59 | 
1 files changed, 28 insertions, 31 deletions
| diff --git a/examples/cached/src/main.rs b/examples/cached/src/main.rs index 39364dc9..7c8b06f0 100644 --- a/examples/cached/src/main.rs +++ b/examples/cached/src/main.rs @@ -3,7 +3,7 @@ use iced::widget::{      button, column, horizontal_space, row, scrollable, text, text_input,  };  use iced::{Element, Length, Sandbox, Settings}; -use iced_lazy::Cached; +use iced_lazy::lazy;  use std::collections::HashSet; @@ -71,39 +71,36 @@ impl Sandbox for App {      }      fn view(&self) -> Element<Message> { -        let options = -            Cached::new((&self.sort_order, self.options.len()), || { -                let mut options: Vec<_> = self.options.iter().collect(); +        let options = lazy((&self.sort_order, self.options.len()), || { +            let mut options: Vec<_> = self.options.iter().collect(); -                options.sort_by(|a, b| match self.sort_order { -                    SortOrder::Ascending => { -                        a.to_lowercase().cmp(&b.to_lowercase()) -                    } -                    SortOrder::Descending => { -                        b.to_lowercase().cmp(&a.to_lowercase()) -                    } -                }); - -                column( -                    options -                        .into_iter() -                        .map(|option| { -                            row![ -                                text(option), -                                horizontal_space(Length::Fill), -                                button("Delete") -                                    .on_press(Message::DeleteOption( -                                        option.to_string(), -                                    ),) -                                    .style(theme::Button::Destructive) -                            ] -                            .into() -                        }) -                        .collect(), -                ) -                .spacing(10) +            options.sort_by(|a, b| match self.sort_order { +                SortOrder::Ascending => a.to_lowercase().cmp(&b.to_lowercase()), +                SortOrder::Descending => { +                    b.to_lowercase().cmp(&a.to_lowercase()) +                }              }); +            column( +                options +                    .into_iter() +                    .map(|option| { +                        row![ +                            text(option), +                            horizontal_space(Length::Fill), +                            button("Delete") +                                .on_press(Message::DeleteOption( +                                    option.to_string(), +                                ),) +                                .style(theme::Button::Destructive) +                        ] +                        .into() +                    }) +                    .collect(), +            ) +            .spacing(10) +        }); +          column