1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
use iced::{
text::HorizontalAlignment, text_input, Align, Application, Color, Column,
Element, Justify, Length, Text, TextInput,
};
pub fn main() {
Todos::default().run()
}
#[derive(Default)]
struct Todos {
input: text_input::State,
input_value: String,
}
#[derive(Debug, Clone)]
pub enum Message {
InputChanged(String),
CreateTask,
}
impl Application for Todos {
type Message = Message;
fn update(&mut self, message: Message) {
match message {
Message::InputChanged(value) => {
self.input_value = value;
}
Message::CreateTask => {}
}
}
fn view(&mut self) -> Element<Message> {
let title = Text::new("todos")
.size(100)
.color(GRAY)
.horizontal_alignment(HorizontalAlignment::Center);
let input = TextInput::new(
&mut self.input,
"What needs to be done?",
&self.input_value,
Message::InputChanged,
)
.padding(15)
.size(30)
.on_submit(Message::CreateTask);
Column::new()
.max_width(Length::Units(800))
.height(Length::Fill)
.align_self(Align::Center)
.justify_content(Justify::Center)
.spacing(20)
.padding(20)
.push(title)
.push(input)
.into()
}
}
// Colors
const GRAY: Color = Color {
r: 0.5,
g: 0.5,
b: 0.5,
a: 1.0,
};
|