summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-30 03:31:07 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2019-10-30 03:31:07 +0100
commit63cd0fd8eb1eebae8de7d5141c846fc4ea55d702 (patch)
treee0a427a35435ad5fe5ce98a0b5050a1026a80207 /examples
parent85916c9e8710ee90cbf37d384acbb6d208ff1da3 (diff)
downloadiced-63cd0fd8eb1eebae8de7d5141c846fc4ea55d702.tar.gz
iced-63cd0fd8eb1eebae8de7d5141c846fc4ea55d702.tar.bz2
iced-63cd0fd8eb1eebae8de7d5141c846fc4ea55d702.zip
Draft `TextInput` widget structure
Also started a `todos` example to showcase it!
Diffstat (limited to 'examples')
-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,
+};