summaryrefslogtreecommitdiffstats
path: root/examples/todos/src
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón <hector@hecrj.dev>2023-09-10 01:14:39 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-10 01:14:39 +0200
commit1af5ff41abdef243588199ef7988666655924a02 (patch)
tree4dfd518dd93b0393e77355867062c60d75e7f358 /examples/todos/src
parenta3489e4af960388e9f73988b88df361022a654a4 (diff)
parent1cc5bf59d7c4f47ae47d9a4e22ebaab3ea4975c1 (diff)
downloadiced-1af5ff41abdef243588199ef7988666655924a02.tar.gz
iced-1af5ff41abdef243588199ef7988666655924a02.tar.bz2
iced-1af5ff41abdef243588199ef7988666655924a02.zip
Merge pull request #2058 from iced-rs/explicit-text-caching
Explicit text caching
Diffstat (limited to '')
-rw-r--r--examples/todos/src/main.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 62c17926..501bf67e 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -3,8 +3,8 @@ use iced::font::{self, Font};
use iced::keyboard;
use iced::theme::{self, Theme};
use iced::widget::{
- self, button, checkbox, column, container, row, scrollable, text,
- text_input, Text,
+ self, button, checkbox, column, container, keyed_column, row, scrollable,
+ text, text_input, Text,
};
use iced::window;
use iced::{Application, Element};
@@ -12,10 +12,14 @@ use iced::{Color, Command, Length, Settings, Subscription};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
+use uuid::Uuid;
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
pub fn main() -> iced::Result {
+ #[cfg(not(target_arch = "wasm32"))]
+ tracing_subscriber::fmt::init();
+
Todos::run(Settings {
window: window::Settings {
size: (500, 800),
@@ -220,17 +224,19 @@ impl Application for Todos {
tasks.iter().filter(|task| filter.matches(task));
let tasks: Element<_> = if filtered_tasks.count() > 0 {
- column(
+ keyed_column(
tasks
.iter()
.enumerate()
.filter(|(_, task)| filter.matches(task))
.map(|(i, task)| {
- task.view(i).map(move |message| {
- Message::TaskMessage(i, message)
- })
- })
- .collect(),
+ (
+ task.id,
+ task.view(i).map(move |message| {
+ Message::TaskMessage(i, message)
+ }),
+ )
+ }),
)
.spacing(10)
.into()
@@ -279,6 +285,8 @@ impl Application for Todos {
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Task {
+ #[serde(default = "Uuid::new_v4")]
+ id: Uuid,
description: String,
completed: bool,
@@ -314,6 +322,7 @@ impl Task {
fn new(description: String) -> Self {
Task {
+ id: Uuid::new_v4(),
description,
completed: false,
state: TaskState::Idle,