summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
Diffstat (limited to 'winit')
-rw-r--r--winit/src/application.rs33
-rw-r--r--winit/src/conversion.rs29
-rw-r--r--winit/src/lib.rs2
-rw-r--r--winit/src/mode.rs9
4 files changed, 64 insertions, 9 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 42511fb0..a14924ac 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -2,7 +2,7 @@ use crate::{
conversion,
input::{keyboard, mouse},
subscription, window, Cache, Clipboard, Command, Debug, Element, Event,
- MouseCursor, Settings, Size, Subscription, UserInterface,
+ Mode, MouseCursor, Settings, Size, Subscription, UserInterface,
};
/// An interactive, native cross-platform application.
@@ -72,6 +72,18 @@ pub trait Application: Sized {
/// [`Application`]: trait.Application.html
fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer>;
+ /// Returns the current [`Application`] mode.
+ ///
+ /// The runtime will automatically transition your application if a new mode
+ /// is returned.
+ ///
+ /// By default, an application will run in windowed mode.
+ ///
+ /// [`Application`]: trait.Application.html
+ fn mode(&self) -> Mode {
+ Mode::Windowed
+ }
+
/// Runs the [`Application`].
///
/// This method will take control of the current thread and __will NOT
@@ -110,6 +122,7 @@ pub trait Application: Sized {
subscription_pool.update(subscription, &mut thread_pool, &proxy);
let mut title = application.title();
+ let mut mode = application.mode();
let window = {
let mut window_builder = WindowBuilder::new();
@@ -123,7 +136,11 @@ pub trait Application: Sized {
height: f64::from(height),
})
.with_resizable(settings.window.resizable)
- .with_decorations(settings.window.decorations);
+ .with_decorations(settings.window.decorations)
+ .with_fullscreen(conversion::fullscreen(
+ event_loop.primary_monitor(),
+ mode,
+ ));
#[cfg(target_os = "windows")]
{
@@ -245,6 +262,18 @@ pub trait Application: Sized {
title = new_title;
}
+ // Update window mode
+ let new_mode = application.mode();
+
+ if mode != new_mode {
+ window.set_fullscreen(conversion::fullscreen(
+ window.current_monitor(),
+ new_mode,
+ ));
+
+ mode = new_mode;
+ }
+
let user_interface = build_user_interface(
&mut application,
temp_cache,
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index 279b975a..725b2d86 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -7,10 +7,25 @@ use crate::{
keyboard::{KeyCode, ModifiersState},
mouse, ButtonState,
},
- MouseCursor,
+ Mode, MouseCursor,
};
-/// Convert a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
+/// Converts a [`Mode`] to a [`winit`] fullscreen mode.
+///
+/// [`Mode`]:
+pub fn fullscreen(
+ monitor: winit::monitor::MonitorHandle,
+ mode: Mode,
+) -> Option<winit::window::Fullscreen> {
+ match mode {
+ Mode::Windowed => None,
+ Mode::Fullscreen => {
+ Some(winit::window::Fullscreen::Borderless(monitor))
+ }
+ }
+}
+
+/// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
@@ -26,7 +41,7 @@ pub fn mouse_cursor(mouse_cursor: MouseCursor) -> winit::window::CursorIcon {
}
}
-/// Convert a `MouseButton` from [`winit`] to an [`iced_native`] mouse button.
+/// Converts a `MouseButton` from [`winit`] to an [`iced_native`] mouse button.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
@@ -39,7 +54,7 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
}
}
-/// Convert an `ElementState` from [`winit`] to an [`iced_native`] button state.
+/// Converts an `ElementState` from [`winit`] to an [`iced_native`] button state.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
@@ -50,8 +65,8 @@ pub fn button_state(element_state: winit::event::ElementState) -> ButtonState {
}
}
-/// Convert some `ModifiersState` from [`winit`] to an [`iced_native`] modifiers
-/// state.
+/// Converts some `ModifiersState` from [`winit`] to an [`iced_native`]
+/// modifiers state.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
@@ -66,7 +81,7 @@ pub fn modifiers_state(
}
}
-/// Convert a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
+/// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
///
/// [`winit`]: https://github.com/rust-windowing/winit
/// [`iced_native`]: https://github.com/hecrj/iced/tree/master/native
diff --git a/winit/src/lib.rs b/winit/src/lib.rs
index ffc662fb..9000f977 100644
--- a/winit/src/lib.rs
+++ b/winit/src/lib.rs
@@ -30,6 +30,7 @@ pub mod settings;
mod application;
mod clipboard;
+mod mode;
mod subscription;
// We disable debug capabilities on release builds unless the `debug` feature
@@ -42,6 +43,7 @@ mod debug;
mod debug;
pub use application::Application;
+pub use mode::Mode;
pub use settings::Settings;
use clipboard::Clipboard;
diff --git a/winit/src/mode.rs b/winit/src/mode.rs
new file mode 100644
index 00000000..37464711
--- /dev/null
+++ b/winit/src/mode.rs
@@ -0,0 +1,9 @@
+/// The mode of a window-based application.
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum Mode {
+ /// The application appears in its own window.
+ Windowed,
+
+ /// The application takes the whole screen of its current monitor.
+ Fullscreen,
+}