summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-09-04 02:55:09 +0200
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-09-04 02:55:09 +0200
commit34495bba1c1ffaa4ea2bab46103b5d66e333c51e (patch)
tree09c2393621ae1e83c25ca8e7d69dc7b951931fbe /examples
parent1a1da6a1f0ee58d5cdc7365681e0ad5edd0117af (diff)
downloadiced-34495bba1c1ffaa4ea2bab46103b5d66e333c51e.tar.gz
iced-34495bba1c1ffaa4ea2bab46103b5d66e333c51e.tar.bz2
iced-34495bba1c1ffaa4ea2bab46103b5d66e333c51e.zip
Introduce `keyed::Column` widget
Diffstat (limited to 'examples')
-rw-r--r--examples/todos/Cargo.toml4
-rw-r--r--examples/todos/src/main.rs24
2 files changed, 19 insertions, 9 deletions
diff --git a/examples/todos/Cargo.toml b/examples/todos/Cargo.toml
index 7ad4d558..4a35cfe6 100644
--- a/examples/todos/Cargo.toml
+++ b/examples/todos/Cargo.toml
@@ -7,9 +7,11 @@ publish = false
[dependencies]
iced = { path = "../..", features = ["async-std", "debug"] }
+uuid = { version = "1.0", features = ["v4", "fast-rng", "serde"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
-once_cell = "1.15"
+once_cell = "1.0"
+tracing-subscriber = "0.3"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
async-std = "1.0"
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 6ad7b4fb..1dd8a307 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -5,8 +5,8 @@ use iced::keyboard::{self, KeyCode, Modifiers};
use iced::subscription;
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};
@@ -14,10 +14,13 @@ 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 {
+ tracing_subscriber::fmt::init();
+
Todos::run(Settings {
window: window::Settings {
size: (500, 800),
@@ -222,17 +225,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()
@@ -295,6 +300,8 @@ impl Application for Todos {
#[derive(Debug, Clone, Serialize, Deserialize)]
struct Task {
+ #[serde(default = "Uuid::new_v4")]
+ id: Uuid,
description: String,
completed: bool,
@@ -330,6 +337,7 @@ impl Task {
fn new(description: String) -> Self {
Task {
+ id: Uuid::new_v4(),
description,
completed: false,
state: TaskState::Idle,