2020-04-05 21:12:14 +00:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
|
|
|
|
pub struct WindowId(Uuid);
|
|
|
|
|
|
|
|
impl WindowId {
|
2020-06-25 23:02:21 +00:00
|
|
|
pub fn new() -> Self {
|
|
|
|
WindowId(Uuid::new_v4())
|
|
|
|
}
|
|
|
|
|
2020-07-25 06:04:45 +00:00
|
|
|
pub fn primary() -> Self {
|
|
|
|
WindowId(Uuid::from_u128(0))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_primary(&self) -> bool {
|
2020-07-26 19:10:18 +00:00
|
|
|
*self == WindowId::primary()
|
2020-07-25 06:04:45 +00:00
|
|
|
}
|
2020-08-16 07:30:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
use std::fmt;
|
2020-07-25 06:04:45 +00:00
|
|
|
|
2020-08-16 07:30:04 +00:00
|
|
|
impl fmt::Display for WindowId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
self.0.to_simple().fmt(f)
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-25 06:04:45 +00:00
|
|
|
impl Default for WindowId {
|
|
|
|
fn default() -> Self {
|
|
|
|
WindowId::primary()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 20:21:39 +00:00
|
|
|
#[derive(Debug)]
|
2020-04-05 21:12:14 +00:00
|
|
|
pub struct Window {
|
|
|
|
pub id: WindowId,
|
|
|
|
pub width: u32,
|
|
|
|
pub height: u32,
|
|
|
|
pub title: String,
|
|
|
|
pub vsync: bool,
|
2020-08-13 08:47:40 +00:00
|
|
|
pub resizable: bool,
|
2020-10-05 17:51:36 +00:00
|
|
|
pub decorations: bool,
|
2020-08-13 08:47:40 +00:00
|
|
|
pub mode: WindowMode,
|
2020-09-21 23:12:34 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
pub canvas: Option<String>,
|
2020-08-13 08:47:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Defines the way a window is displayed
|
|
|
|
/// The use_size option that is used in the Fullscreen variant
|
|
|
|
/// defines whether a videomode is chosen that best fits the width and height
|
|
|
|
/// in the Window structure, or if these are ignored.
|
|
|
|
/// E.g. when use_size is set to false the best video mode possible is chosen.
|
|
|
|
#[derive(Debug, Clone, Copy)]
|
|
|
|
pub enum WindowMode {
|
|
|
|
Windowed,
|
|
|
|
BorderlessFullscreen,
|
|
|
|
Fullscreen { use_size: bool },
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Window {
|
2020-06-25 23:02:21 +00:00
|
|
|
pub fn new(id: WindowId, window_descriptor: &WindowDescriptor) -> Self {
|
2020-04-05 21:12:14 +00:00
|
|
|
Window {
|
2020-06-25 23:02:21 +00:00
|
|
|
id,
|
2020-04-05 21:12:14 +00:00
|
|
|
height: window_descriptor.height,
|
|
|
|
width: window_descriptor.width,
|
|
|
|
title: window_descriptor.title.clone(),
|
|
|
|
vsync: window_descriptor.vsync,
|
2020-08-13 08:47:40 +00:00
|
|
|
resizable: window_descriptor.resizable,
|
2020-10-05 17:51:36 +00:00
|
|
|
decorations: window_descriptor.decorations,
|
2020-08-13 08:47:40 +00:00
|
|
|
mode: window_descriptor.mode,
|
2020-09-21 23:12:34 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
canvas: window_descriptor.canvas.clone(),
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
2020-08-16 07:30:04 +00:00
|
|
|
#[allow(clippy::manual_non_exhaustive)]
|
2020-04-05 21:12:14 +00:00
|
|
|
pub struct WindowDescriptor {
|
|
|
|
pub width: u32,
|
|
|
|
pub height: u32,
|
|
|
|
pub title: String,
|
|
|
|
pub vsync: bool,
|
2020-08-13 08:47:40 +00:00
|
|
|
pub resizable: bool,
|
2020-10-05 17:51:36 +00:00
|
|
|
pub decorations: bool,
|
2020-08-13 08:47:40 +00:00
|
|
|
pub mode: WindowMode,
|
2020-09-21 23:12:34 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
pub canvas: Option<String>,
|
2020-08-16 07:30:04 +00:00
|
|
|
|
|
|
|
// this is a manual implementation of the non exhaustive pattern,
|
|
|
|
// especially made to allow ..Default::default()
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub __non_exhaustive: (),
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for WindowDescriptor {
|
|
|
|
fn default() -> Self {
|
|
|
|
WindowDescriptor {
|
|
|
|
title: "bevy".to_string(),
|
|
|
|
width: 1280,
|
|
|
|
height: 720,
|
|
|
|
vsync: true,
|
2020-08-13 08:47:40 +00:00
|
|
|
resizable: true,
|
2020-10-05 17:51:36 +00:00
|
|
|
decorations: true,
|
2020-08-13 08:47:40 +00:00
|
|
|
mode: WindowMode::Windowed,
|
2020-09-21 23:12:34 +00:00
|
|
|
#[cfg(target_arch = "wasm32")]
|
|
|
|
canvas: None,
|
2020-08-16 07:30:04 +00:00
|
|
|
__non_exhaustive: (),
|
2020-04-05 21:12:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-04-06 23:15:59 +00:00
|
|
|
}
|