Simplify internal type construction

This commit is contained in:
Mads Marquart 2022-09-21 10:04:28 +02:00 committed by GitHub
parent 25b129362f
commit fafdedfb7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 242 additions and 285 deletions

View file

@ -1,4 +1,5 @@
pub use self::platform::*;
use crate::monitor::{MonitorHandle as RootMonitorHandle, VideoMode as RootVideoMode};
use crate::window::Fullscreen as RootFullscreen;
#[cfg(target_os = "windows")]
#[path = "windows/mod.rs"]
@ -25,6 +26,37 @@ mod platform;
#[path = "web/mod.rs"]
mod platform;
pub use self::platform::*;
/// Helper for converting between platform-specific and generic VideoMode/MonitorHandle
#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) enum Fullscreen {
Exclusive(VideoMode),
Borderless(Option<MonitorHandle>),
}
impl From<RootFullscreen> for Fullscreen {
fn from(f: RootFullscreen) -> Self {
match f {
RootFullscreen::Exclusive(mode) => Self::Exclusive(mode.video_mode),
RootFullscreen::Borderless(Some(handle)) => Self::Borderless(Some(handle.inner)),
RootFullscreen::Borderless(None) => Self::Borderless(None),
}
}
}
impl From<Fullscreen> for RootFullscreen {
fn from(f: Fullscreen) -> Self {
match f {
Fullscreen::Exclusive(video_mode) => Self::Exclusive(RootVideoMode { video_mode }),
Fullscreen::Borderless(Some(inner)) => {
Self::Borderless(Some(RootMonitorHandle { inner }))
}
Fullscreen::Borderless(None) => Self::Borderless(None),
}
}
}
#[cfg(all(
not(target_os = "ios"),
not(target_os = "windows"),