Add Application::mode to iced_winit

This commit is contained in:
Héctor Ramón Jiménez 2020-01-16 04:54:48 +01:00
parent 1787377450
commit d6b20d3e79
2 changed files with 44 additions and 2 deletions

View file

@ -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) -> window::Mode {
window::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")]
{
@ -244,6 +261,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,