Add Application::mode to iced_winit
This commit is contained in:
parent
1787377450
commit
d6b20d3e79
2 changed files with 44 additions and 2 deletions
|
|
@ -72,6 +72,18 @@ pub trait Application: Sized {
|
||||||
/// [`Application`]: trait.Application.html
|
/// [`Application`]: trait.Application.html
|
||||||
fn view(&mut self) -> Element<'_, Self::Message, Self::Renderer>;
|
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) -> window::Mode {
|
||||||
|
window::Mode::Windowed
|
||||||
|
}
|
||||||
|
|
||||||
/// Runs the [`Application`].
|
/// Runs the [`Application`].
|
||||||
///
|
///
|
||||||
/// This method will take control of the current thread and __will NOT
|
/// 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);
|
subscription_pool.update(subscription, &mut thread_pool, &proxy);
|
||||||
|
|
||||||
let mut title = application.title();
|
let mut title = application.title();
|
||||||
|
let mut mode = application.mode();
|
||||||
|
|
||||||
let window = {
|
let window = {
|
||||||
let mut window_builder = WindowBuilder::new();
|
let mut window_builder = WindowBuilder::new();
|
||||||
|
|
@ -123,7 +136,11 @@ pub trait Application: Sized {
|
||||||
height: f64::from(height),
|
height: f64::from(height),
|
||||||
})
|
})
|
||||||
.with_resizable(settings.window.resizable)
|
.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")]
|
#[cfg(target_os = "windows")]
|
||||||
{
|
{
|
||||||
|
|
@ -244,6 +261,18 @@ pub trait Application: Sized {
|
||||||
title = new_title;
|
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(
|
let user_interface = build_user_interface(
|
||||||
&mut application,
|
&mut application,
|
||||||
temp_cache,
|
temp_cache,
|
||||||
|
|
|
||||||
|
|
@ -7,9 +7,22 @@ use crate::{
|
||||||
keyboard::{KeyCode, ModifiersState},
|
keyboard::{KeyCode, ModifiersState},
|
||||||
mouse, ButtonState,
|
mouse, ButtonState,
|
||||||
},
|
},
|
||||||
MouseCursor,
|
window, MouseCursor,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Convert a `Mode` from [`iced_native`] to a [`winit`] fullscreen mode.
|
||||||
|
pub fn fullscreen(
|
||||||
|
monitor: winit::monitor::MonitorHandle,
|
||||||
|
mode: window::Mode,
|
||||||
|
) -> Option<winit::window::Fullscreen> {
|
||||||
|
match mode {
|
||||||
|
window::Mode::Windowed => None,
|
||||||
|
window::Mode::Fullscreen => {
|
||||||
|
Some(winit::window::Fullscreen::Borderless(monitor))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
|
/// Convert a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
|
||||||
///
|
///
|
||||||
/// [`winit`]: https://github.com/rust-windowing/winit
|
/// [`winit`]: https://github.com/rust-windowing/winit
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue