summaryrefslogtreecommitdiffstats
path: root/examples/todos.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/todos.rs')
-rw-r--r--examples/todos.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/examples/todos.rs b/examples/todos.rs
new file mode 100644
index 00000000..6a5d5e85
--- /dev/null
+++ b/examples/todos.rs
@@ -0,0 +1,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,
+};