|
1 | 1 | use iced::alignment::{self, Alignment}; |
2 | | -use iced::event::{self, Event}; |
3 | 2 | use iced::font::{self, Font}; |
4 | | -use iced::keyboard::{self, KeyCode, Modifiers}; |
5 | | -use iced::subscription; |
| 3 | +use iced::keyboard; |
6 | 4 | use iced::theme::{self, Theme}; |
7 | 5 | use iced::widget::{ |
8 | 6 | self, button, checkbox, column, container, row, scrollable, text, |
@@ -52,7 +50,7 @@ enum Message { |
52 | 50 | FilterChanged(Filter), |
53 | 51 | TaskMessage(usize, TaskMessage), |
54 | 52 | TabPressed { shift: bool }, |
55 | | - ToggleFullscreen(window::Mode), |
| 53 | + ChangeWindowMode(window::Mode), |
56 | 54 | } |
57 | 55 |
|
58 | 56 | impl Application for Todos { |
@@ -163,7 +161,7 @@ impl Application for Todos { |
163 | 161 | widget::focus_next() |
164 | 162 | } |
165 | 163 | } |
166 | | - Message::ToggleFullscreen(mode) => { |
| 164 | + Message::ChangeWindowMode(mode) => { |
167 | 165 | window::change_mode(mode) |
168 | 166 | } |
169 | 167 | _ => Command::none(), |
@@ -262,33 +260,19 @@ impl Application for Todos { |
262 | 260 | } |
263 | 261 |
|
264 | 262 | fn subscription(&self) -> Subscription<Message> { |
265 | | - subscription::events_with(|event, status| match (event, status) { |
266 | | - ( |
267 | | - Event::Keyboard(keyboard::Event::KeyPressed { |
268 | | - key_code: keyboard::KeyCode::Tab, |
269 | | - modifiers, |
270 | | - .. |
| 263 | + keyboard::on_key_press(|key_code, modifiers| { |
| 264 | + match (key_code, modifiers) { |
| 265 | + (keyboard::KeyCode::Tab, _) => Some(Message::TabPressed { |
| 266 | + shift: modifiers.shift(), |
271 | 267 | }), |
272 | | - event::Status::Ignored, |
273 | | - ) => Some(Message::TabPressed { |
274 | | - shift: modifiers.shift(), |
275 | | - }), |
276 | | - ( |
277 | | - Event::Keyboard(keyboard::Event::KeyPressed { |
278 | | - key_code, |
279 | | - modifiers: Modifiers::SHIFT, |
280 | | - }), |
281 | | - event::Status::Ignored, |
282 | | - ) => match key_code { |
283 | | - KeyCode::Up => { |
284 | | - Some(Message::ToggleFullscreen(window::Mode::Fullscreen)) |
| 268 | + (keyboard::KeyCode::Up, keyboard::Modifiers::SHIFT) => { |
| 269 | + Some(Message::ChangeWindowMode(window::Mode::Fullscreen)) |
285 | 270 | } |
286 | | - KeyCode::Down => { |
287 | | - Some(Message::ToggleFullscreen(window::Mode::Windowed)) |
| 271 | + (keyboard::KeyCode::Down, keyboard::Modifiers::SHIFT) => { |
| 272 | + Some(Message::ChangeWindowMode(window::Mode::Windowed)) |
288 | 273 | } |
289 | 274 | _ => None, |
290 | | - }, |
291 | | - _ => None, |
| 275 | + } |
292 | 276 | }) |
293 | 277 | } |
294 | 278 | } |
|
0 commit comments