feat: keybindings
unfortunately it looks like the tab operations can't focus buttons
This commit is contained in:
parent
29a9ce5d75
commit
d1056e9fbe
1 changed files with 32 additions and 1 deletions
|
|
@ -1,6 +1,9 @@
|
|||
use std::{borrow::Cow, collections::HashMap, env, path::PathBuf, process};
|
||||
|
||||
use iced::{Color, Element, Length, Renderer, Task, Theme, application, theme, widget};
|
||||
use iced::{
|
||||
Color, Element, Event, Length, Renderer, Subscription, Task, Theme, application, event,
|
||||
keyboard, theme, widget, window,
|
||||
};
|
||||
use ignore::{WalkBuilder, types::TypesBuilder};
|
||||
use rayon::iter::{ParallelBridge, ParallelIterator};
|
||||
|
||||
|
|
@ -12,6 +15,8 @@ enum Message {
|
|||
UnloadImage(PathBuf),
|
||||
|
||||
OpenImage(PathBuf),
|
||||
|
||||
KeyPressed(keyboard::Key, keyboard::Modifiers),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
|
@ -71,6 +76,22 @@ impl State {
|
|||
.map_err(|e| e.to_string())
|
||||
.err()
|
||||
}
|
||||
|
||||
Message::KeyPressed(key, modifiers) => match key.as_ref() {
|
||||
// input field cycling
|
||||
keyboard::Key::Named(keyboard::key::Named::Tab) => {
|
||||
return if modifiers.shift() {
|
||||
widget::operation::focus_previous()
|
||||
} else {
|
||||
widget::operation::focus_next()
|
||||
};
|
||||
}
|
||||
|
||||
keyboard::Key::Character("q") => {
|
||||
return window::latest().and_then(window::close);
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
}
|
||||
|
||||
Task::none()
|
||||
|
|
@ -107,10 +128,20 @@ impl State {
|
|||
])
|
||||
.into()
|
||||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
event::listen_with(|event, _status, _id| match event {
|
||||
Event::Keyboard(keyboard::Event::KeyPressed { key, modifiers, .. }) => {
|
||||
Some(Message::KeyPressed(key, modifiers))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run() -> Result<(), impl std::error::Error> {
|
||||
application(State::new, State::update, State::view)
|
||||
.subscription(State::subscription)
|
||||
.theme(theme::Theme::custom(
|
||||
"high-contrast-dark",
|
||||
theme::Palette {
|
||||
|
|
|
|||
Loading…
Reference in a new issue