Implement iced_glutin 🎉
This commit is contained in:
parent
a1a5fcfd46
commit
e0e4ee73fe
31 changed files with 718 additions and 498 deletions
|
|
@ -129,7 +129,6 @@ pub trait Application: Sized {
|
|||
use winit::{
|
||||
event::{self, WindowEvent},
|
||||
event_loop::{ControlFlow, EventLoop},
|
||||
window::WindowBuilder,
|
||||
};
|
||||
|
||||
let mut debug = Debug::new();
|
||||
|
|
@ -155,32 +154,11 @@ pub trait Application: Sized {
|
|||
let mut title = application.title();
|
||||
let mut mode = application.mode();
|
||||
|
||||
let window = {
|
||||
let mut window_builder = WindowBuilder::new();
|
||||
|
||||
let (width, height) = settings.window.size;
|
||||
|
||||
window_builder = window_builder
|
||||
.with_title(&title)
|
||||
.with_inner_size(winit::dpi::LogicalSize { width, height })
|
||||
.with_resizable(settings.window.resizable)
|
||||
.with_decorations(settings.window.decorations)
|
||||
.with_fullscreen(conversion::fullscreen(
|
||||
event_loop.primary_monitor(),
|
||||
mode,
|
||||
));
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use winit::platform::windows::WindowBuilderExtWindows;
|
||||
|
||||
if let Some(parent) = settings.window.platform_specific.parent {
|
||||
window_builder = window_builder.with_parent_window(parent);
|
||||
}
|
||||
}
|
||||
|
||||
window_builder.build(&event_loop).expect("Open window")
|
||||
};
|
||||
let window = settings
|
||||
.window
|
||||
.into_builder(&title, mode, event_loop.primary_monitor())
|
||||
.build(&event_loop)
|
||||
.expect("Open window");
|
||||
|
||||
let physical_size = window.inner_size();
|
||||
let mut viewport = Viewport::with_physical_size(
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
//! [`winit`]: https://github.com/rust-windowing/winit
|
||||
//! [`Application`]: trait.Application.html
|
||||
//! [`conversion`]: conversion
|
||||
#![deny(missing_docs)]
|
||||
//#![deny(missing_docs)]
|
||||
#![deny(missing_debug_implementations)]
|
||||
#![deny(unused_results)]
|
||||
#![forbid(unsafe_code)]
|
||||
|
|
@ -44,8 +44,7 @@ mod debug;
|
|||
|
||||
pub use application::Application;
|
||||
pub use clipboard::Clipboard;
|
||||
pub use debug::Debug;
|
||||
pub use mode::Mode;
|
||||
pub use proxy::Proxy;
|
||||
pub use settings::Settings;
|
||||
|
||||
use debug::Debug;
|
||||
use proxy::Proxy;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use iced_native::futures::{
|
|||
};
|
||||
use std::pin::Pin;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Proxy<Message: 'static> {
|
||||
raw: winit::event_loop::EventLoopProxy<Message>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,11 @@ mod platform;
|
|||
|
||||
pub use platform::PlatformSpecific;
|
||||
|
||||
use crate::conversion;
|
||||
use crate::Mode;
|
||||
use winit::monitor::MonitorHandle;
|
||||
use winit::window::WindowBuilder;
|
||||
|
||||
/// The settings of an application.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Default)]
|
||||
pub struct Settings<Flags> {
|
||||
|
|
@ -38,6 +43,37 @@ pub struct Window {
|
|||
pub platform_specific: platform::PlatformSpecific,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
pub fn into_builder(
|
||||
self,
|
||||
title: &str,
|
||||
mode: Mode,
|
||||
primary_monitor: MonitorHandle,
|
||||
) -> WindowBuilder {
|
||||
let mut window_builder = WindowBuilder::new();
|
||||
|
||||
let (width, height) = self.size;
|
||||
|
||||
window_builder = window_builder
|
||||
.with_title(title)
|
||||
.with_inner_size(winit::dpi::LogicalSize { width, height })
|
||||
.with_resizable(self.resizable)
|
||||
.with_decorations(self.decorations)
|
||||
.with_fullscreen(conversion::fullscreen(primary_monitor, mode));
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
use winit::platform::windows::WindowBuilderExtWindows;
|
||||
|
||||
if let Some(parent) = self.platform_specific.parent {
|
||||
window_builder = window_builder.with_parent_window(parent);
|
||||
}
|
||||
}
|
||||
|
||||
window_builder
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Window {
|
||||
fn default() -> Window {
|
||||
Window {
|
||||
|
|
|
|||
|
|
@ -1,30 +0,0 @@
|
|||
pub struct Size {
|
||||
physical: winit::dpi::PhysicalSize<u32>,
|
||||
logical: winit::dpi::LogicalSize<f64>,
|
||||
scale_factor: f64,
|
||||
}
|
||||
|
||||
impl Size {
|
||||
pub fn new(
|
||||
physical: winit::dpi::PhysicalSize<u32>,
|
||||
scale_factor: f64,
|
||||
) -> Size {
|
||||
Size {
|
||||
logical: physical.to_logical(scale_factor),
|
||||
physical,
|
||||
scale_factor,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn physical(&self) -> winit::dpi::PhysicalSize<u32> {
|
||||
self.physical
|
||||
}
|
||||
|
||||
pub fn logical(&self) -> winit::dpi::LogicalSize<f64> {
|
||||
self.logical
|
||||
}
|
||||
|
||||
pub fn scale_factor(&self) -> f64 {
|
||||
self.scale_factor
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue