Draft TextInput widget structure
Also started a `todos` example to showcase it!
This commit is contained in:
parent
85916c9e87
commit
63cd0fd8eb
11 changed files with 372 additions and 25 deletions
69
examples/todos.rs
Normal file
69
examples/todos.rs
Normal file
|
|
@ -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,
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue