diff --git a/src/app/mod.rs b/src/app/mod.rs index 8736b0a..d986140 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -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 { + 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 {