Add on_submit & esc for example
This commit is contained in:
parent
3814fda9d2
commit
899bd45700
1 changed files with 30 additions and 9 deletions
|
|
@ -25,6 +25,7 @@ enum Message {
|
|||
HideModal,
|
||||
Email(String),
|
||||
Password(String),
|
||||
Submit,
|
||||
Event(Event),
|
||||
}
|
||||
|
||||
|
|
@ -53,9 +54,7 @@ impl Application for App {
|
|||
widget::focus_next()
|
||||
}
|
||||
Message::HideModal => {
|
||||
self.show_modal = false;
|
||||
self.email.clear();
|
||||
self.password.clear();
|
||||
self.hide_modal();
|
||||
Command::none()
|
||||
}
|
||||
Message::Email(email) => {
|
||||
|
|
@ -66,21 +65,33 @@ impl Application for App {
|
|||
self.password = password;
|
||||
Command::none()
|
||||
}
|
||||
Message::Event(event) => {
|
||||
if let Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
Message::Submit => {
|
||||
if !self.email.is_empty() && !self.password.is_empty() {
|
||||
self.hide_modal();
|
||||
}
|
||||
|
||||
Command::none()
|
||||
}
|
||||
Message::Event(event) => match event {
|
||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key_code: keyboard::KeyCode::Tab,
|
||||
modifiers,
|
||||
}) = event
|
||||
{
|
||||
}) => {
|
||||
if modifiers.shift() {
|
||||
widget::focus_previous()
|
||||
} else {
|
||||
widget::focus_next()
|
||||
}
|
||||
} else {
|
||||
}
|
||||
Event::Keyboard(keyboard::Event::KeyPressed {
|
||||
key_code: keyboard::KeyCode::Escape,
|
||||
..
|
||||
}) => {
|
||||
self.hide_modal();
|
||||
Command::none()
|
||||
}
|
||||
}
|
||||
_ => Command::none(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,12 +138,14 @@ impl Application for App {
|
|||
&self.email,
|
||||
Message::Email
|
||||
)
|
||||
.on_submit(Message::Submit)
|
||||
.padding(5),
|
||||
]
|
||||
.spacing(5),
|
||||
column![
|
||||
text("Password").size(12),
|
||||
text_input("", &self.password, Message::Password)
|
||||
.on_submit(Message::Submit)
|
||||
.password()
|
||||
.padding(5),
|
||||
]
|
||||
|
|
@ -156,6 +169,14 @@ impl Application for App {
|
|||
}
|
||||
}
|
||||
|
||||
impl App {
|
||||
fn hide_modal(&mut self) {
|
||||
self.show_modal = false;
|
||||
self.email.clear();
|
||||
self.password.clear();
|
||||
}
|
||||
}
|
||||
|
||||
mod modal {
|
||||
use iced_native::alignment::Alignment;
|
||||
use iced_native::widget::{self, Tree};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue