Merge #1019: [GUI] tab on TextInputs

158bdc8a70bcd1a5dae34a842e7ac0bb39c20127 tab on TextInputs (pythcoiner)

Pull request description:

  this PR  introduce handling of new events in all views:
  - `Tab` will move cursor to the next TextInput
  - `Tab` + `Shift` will move the cursor to previous TextInput

ACKs for top commit:
  edouardparis:
    ACK 158bdc8a70bcd1a5dae34a842e7ac0bb39c20127

Tree-SHA512: 018fa55bfc4cae597ff82e7663ce43b906086b524eb3f95193a69e296c60a93d1a20d453221a7747037a84313fdcbf1d84cd970794b512841b9387385147bda1
This commit is contained in:
edouardparis 2024-03-20 20:26:35 +01:00
commit bfc55fb084
No known key found for this signature in database
GPG Key ID: E65F7A089C20DC8F

View File

@ -2,7 +2,14 @@
use std::{error::Error, io::Write, path::PathBuf, process, str::FromStr};
use iced::{executor, Application, Command, Settings, Subscription};
use iced::{
event::{self, Event},
executor,
keyboard::{self, KeyCode},
subscription,
widget::{focus_next, focus_previous},
Application, Command, Settings, Subscription,
};
use tracing::{error, info};
use tracing_subscriber::filter::LevelFilter;
extern crate serde;
@ -75,6 +82,11 @@ enum State {
App(App),
}
#[derive(Debug)]
pub enum Key {
Tab(bool),
}
#[derive(Debug)]
pub enum Message {
CtrlC,
@ -83,6 +95,7 @@ pub enum Message {
Load(Box<loader::Message>),
Run(Box<app::Message>),
Event(iced_native::Event),
KeyPressed(Key),
}
async fn ctrl_c() -> Result<(), ()> {
@ -189,6 +202,14 @@ impl Application for GUI {
};
iced::window::close()
}
(_, Message::KeyPressed(Key::Tab(shift))) => {
log::debug!("Tab pressed!");
if shift {
focus_previous()
} else {
focus_next()
}
}
(State::Launcher(l), Message::Launch(msg)) => match *msg {
launcher::Message::Install(datadir_path) => {
self.logger.set_installer_mode(
@ -278,12 +299,27 @@ impl Application for GUI {
State::App(v) => v.subscription().map(|msg| Message::Run(Box::new(msg))),
State::Launcher(v) => v.subscription().map(|msg| Message::Launch(Box::new(msg))),
},
iced_native::subscription::events().map(Self::Message::Event),
subscription::events_with(|event, status| match (&event, status) {
(
Event::Keyboard(keyboard::Event::KeyPressed {
key_code: KeyCode::Tab,
modifiers,
..
}),
event::Status::Ignored,
) => Some(Message::KeyPressed(Key::Tab(modifiers.shift()))),
(
iced::Event::Window(iced_native::window::Event::CloseRequested),
event::Status::Ignored,
) => Some(Message::Event(event)),
_ => None,
}),
])
.with_filter(|(event, _status)| {
matches!(
event,
iced::Event::Window(iced_native::window::Event::CloseRequested)
| iced::Event::Keyboard(_)
)
})
}