Skip to content

Commit

Permalink
Added example of toggling fullscreen to TODOs.
Browse files Browse the repository at this point in the history
  • Loading branch information
bungoboingo committed Mar 2, 2023
1 parent b2a9a1e commit a9ca89c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions examples/todos/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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::{
self, button, checkbox, column, container, row, scrollable, text,
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};

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
};

Expand Down Expand Up @@ -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,
})
}
Expand Down

0 comments on commit a9ca89c

Please sign in to comment.