bevy/crates/bevy_window/src/window.rs
Thomas Herzog b4c185eb0c cargo fmt
2020-07-26 21:10:18 +02:00

69 lines
1.3 KiB
Rust

use uuid::Uuid;
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub struct WindowId(Uuid);
impl WindowId {
pub fn new() -> Self {
WindowId(Uuid::new_v4())
}
pub fn primary() -> Self {
WindowId(Uuid::from_u128(0))
}
pub fn is_primary(&self) -> bool {
*self == WindowId::primary()
}
pub fn to_string(&self) -> String {
self.0.to_simple().to_string()
}
}
impl Default for WindowId {
fn default() -> Self {
WindowId::primary()
}
}
#[derive(Debug)]
pub struct Window {
pub id: WindowId,
pub width: u32,
pub height: u32,
pub title: String,
pub vsync: bool,
}
impl Window {
pub fn new(id: WindowId, window_descriptor: &WindowDescriptor) -> Self {
Window {
id,
height: window_descriptor.height,
width: window_descriptor.width,
title: window_descriptor.title.clone(),
vsync: window_descriptor.vsync,
}
}
}
#[derive(Debug, Clone)]
pub struct WindowDescriptor {
pub width: u32,
pub height: u32,
pub title: String,
pub vsync: bool,
}
impl Default for WindowDescriptor {
fn default() -> Self {
WindowDescriptor {
title: "bevy".to_string(),
width: 1280,
height: 720,
vsync: true,
}
}
}