use crate::{RenderError, Vec2};
use std::{error::Error, fmt};
use winit::dpi::PhysicalSize;
#[derive(Clone, Debug, PartialEq)]
pub struct WindowInfo {
pub size: PhysicalSize<u32>,
pub logical_size: Vec2,
pub scale_factor: f64,
pub focused: bool,
pub minimized: bool,
pub maximized: bool,
pub fullscreen: bool,
pub occluded: bool,
pub visible: bool,
}
impl WindowInfo {
pub fn is_drawable(&self) -> bool {
self.visible
&& !self.occluded
&& !self.minimized
&& self.size.width > 0
&& self.size.height > 0
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum WindowStatus {
Pending,
Open,
Failed(String),
}
#[derive(Debug)]
pub enum WindowError {
Create(winit::error::OsError),
Render(RenderError),
UnknownParent(super::WindowKey),
Unsupported(String),
}
impl fmt::Display for WindowError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Create(error) => write!(f, "creating the window: {error}"),
Self::Render(error) => write!(f, "preparing the window surface: {error}"),
Self::UnknownParent(key) => write!(f, "parent window {key} is not open"),
Self::Unsupported(reason) => write!(f, "window not opened: {reason}"),
}
}
}
impl Error for WindowError {
fn source(&self) -> Option<&(dyn Error + 'static)> {
match self {
Self::Create(error) => Some(error),
Self::Render(error) => Some(error),
Self::UnknownParent(_) | Self::Unsupported(_) => None,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct AppStats {
pub windows_open: usize,
pub windows_opened: u64,
pub windows_closed: u64,
pub frames_presented: u64,
pub windows_failed: u64,
}