Introduce keyed::Column widget
This commit is contained in:
parent
1a1da6a1f0
commit
34495bba1c
8 changed files with 490 additions and 11 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue