#[derive(Debug, Clone, Copy, PartialEq)]
pub struct WindowPosition {
pub x: i32,
pub y: i32,
}
impl WindowPosition {
#[must_use]
pub const fn new(x: i32, y: i32) -> Self {
Self { x, y }
}
pub const ORIGIN: Self = Self { x: 0, y: 0 };
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct WindowSize {
pub width: u32,
pub height: u32,
}
impl WindowSize {
#[must_use]
pub const fn new(width: u32, height: u32) -> Self {
Self { width, height }
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum WindowState {
#[default]
Normal,
Minimized,
Maximized,
Fullscreen,
}
#[derive(Debug, Clone)]
pub struct WindowSettings {
pub title: String,
pub size: WindowSize,
pub position: Option<WindowPosition>,
pub min_size: Option<WindowSize>,
pub max_size: Option<WindowSize>,
pub resizable: bool,
pub decorations: bool,
pub transparent: bool,
pub always_on_top: bool,
pub state: WindowState,
}
impl Default for WindowSettings {
fn default() -> Self {
Self {
title: String::new(),
size: WindowSize::new(800, 600),
position: None,
min_size: None,
max_size: None,
resizable: true,
decorations: true,
transparent: false,
always_on_top: false,
state: WindowState::Normal,
}
}
}
impl WindowSettings {
#[must_use]
pub fn new(title: impl Into<String>) -> Self {
Self {
title: title.into(),
..Default::default()
}
}
#[must_use]
pub fn size(mut self, width: u32, height: u32) -> Self {
self.size = WindowSize::new(width, height);
self
}
#[must_use]
pub fn position(mut self, x: i32, y: i32) -> Self {
self.position = Some(WindowPosition::new(x, y));
self
}
#[must_use]
pub fn centered(mut self) -> Self {
self.position = None;
self
}
#[must_use]
pub fn min_size(mut self, width: u32, height: u32) -> Self {
self.min_size = Some(WindowSize::new(width, height));
self
}
#[must_use]
pub fn max_size(mut self, width: u32, height: u32) -> Self {
self.max_size = Some(WindowSize::new(width, height));
self
}
#[must_use]
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
#[must_use]
pub fn decorations(mut self, decorations: bool) -> Self {
self.decorations = decorations;
self
}
#[must_use]
pub fn transparent(mut self, transparent: bool) -> Self {
self.transparent = transparent;
self
}
#[must_use]
pub fn always_on_top(mut self, always_on_top: bool) -> Self {
self.always_on_top = always_on_top;
self
}
#[must_use]
pub fn state(mut self, state: WindowState) -> Self {
self.state = state;
self
}
#[must_use]
pub fn maximized(self) -> Self {
self.state(WindowState::Maximized)
}
#[must_use]
pub fn fullscreen(self) -> Self {
self.state(WindowState::Fullscreen)
}
}