summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 02:46:31 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2022-11-03 02:46:31 +0100
commit1cdc1fcd0669bfea096237c07b32742c1a3f2158 (patch)
treec636951447fa1ccefdc4fb4a6c8f58240710da4c /examples
parentadf541d4325df22d577342f870f0f95fa357797a (diff)
downloadiced-1cdc1fcd0669bfea096237c07b32742c1a3f2158.tar.gz
iced-1cdc1fcd0669bfea096237c07b32742c1a3f2158.tar.bz2
iced-1cdc1fcd0669bfea096237c07b32742c1a3f2158.zip
Rename `iced_lazy::Cached` to `Lazy` :tada:
Diffstat (limited to 'examples')
-rw-r--r--examples/cached/src/main.rs59
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![
scrollable(options).height(Length::Fill),
row![