summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Bingus <shankern@protonmail.com>2023-03-02 08:43:58 -0800
committerLibravatar Bingus <shankern@protonmail.com>2023-03-02 10:54:03 -0800
commita9ca89ca55157d7e94dc6422b4842826139ca2db (patch)
treee8c5a5227f2c02ae28cdc6f76d2e35d446fe6b6e
parentb2a9a1e73cb7b2026b2eeaa2be2c04a61c5efb21 (diff)
downloadiced-a9ca89ca55157d7e94dc6422b4842826139ca2db.tar.gz
iced-a9ca89ca55157d7e94dc6422b4842826139ca2db.tar.bz2
iced-a9ca89ca55157d7e94dc6422b4842826139ca2db.zip
Added example of toggling fullscreen to TODOs.
-rw-r--r--examples/todos/src/main.rs30
1 files changed, 28 insertions, 2 deletions
diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs
index 6408f09c..0f5bfe30 100644
--- a/examples/todos/src/main.rs
+++ b/examples/todos/src/main.rs
@@ -1,6 +1,6 @@
use iced::alignment::{self, Alignment};
use iced::event::{self, Event};
-use iced::keyboard;
+use iced::keyboard::{self, KeyCode, Modifiers};
use iced::subscription;
use iced::theme::{self, Theme};
use iced::widget::{
@@ -8,6 +8,8 @@ use iced::widget::{
text_input, Text,
};
use iced::window;
+#[cfg(not(target_arch = "wasm32"))]
+use iced::window::Mode;
use iced::{Application, Element};
use iced::{Color, Command, Font, Length, Settings, Subscription};
@@ -49,7 +51,11 @@ enum Message {
CreateTask,
FilterChanged(Filter),
TaskMessage(usize, TaskMessage),
- TabPressed { shift: bool },
+ TabPressed {
+ shift: bool,
+ },
+ #[cfg(not(target_arch = "wasm32"))]
+ ToggleFullscreen(Mode),
}
impl Application for Todos {
@@ -156,6 +162,10 @@ impl Application for Todos {
widget::focus_next()
}
}
+ #[cfg(not(target_arch = "wasm32"))]
+ Message::ToggleFullscreen(mode) => {
+ window::change_mode(mode)
+ }
_ => Command::none(),
};
@@ -266,6 +276,22 @@ impl Application for Todos {
) => Some(Message::TabPressed {
shift: modifiers.shift(),
}),
+ #[cfg(not(target_arch = "wasm32"))]
+ (
+ Event::Keyboard(keyboard::Event::KeyPressed {
+ key_code,
+ modifiers: Modifiers::SHIFT,
+ }),
+ event::Status::Ignored,
+ ) => match key_code {
+ KeyCode::Up => {
+ Some(Message::ToggleFullscreen(Mode::Fullscreen))
+ }
+ KeyCode::Down => {
+ Some(Message::ToggleFullscreen(Mode::Windowed))
+ }
+ _ => None,
+ },
_ => None,
})
}