Rename iced_lazy::Cached to Lazy 🎉

This commit is contained in:
Héctor Ramón Jiménez 2022-11-03 02:46:31 +01:00
parent adf541d432
commit 1cdc1fcd06
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
3 changed files with 50 additions and 40 deletions

View file

@ -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![
scrollable(options).height(Length::Fill),
row![