use super::WindowKey;
use crate::PresentationMode;
use winit::{
dpi::{LogicalPosition, LogicalSize},
window::{Icon, Window, WindowAttributes, WindowLevel},
};
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum ExitPolicy {
#[default]
MainWindow,
LastWindow,
}
#[derive(Debug, Clone)]
pub struct WindowOptions {
pub attributes: WindowAttributes,
pub(crate) parent: Option<WindowKey>,
pub(crate) presentation_mode: Option<PresentationMode>,
pub(crate) accessibility: bool,
}
impl WindowOptions {
pub fn new(title: impl Into<String>) -> Self {
Self::from_attributes(
Window::default_attributes()
.with_title(title)
.with_inner_size(LogicalSize::new(640.0, 480.0)),
)
}
pub fn from_attributes(attributes: WindowAttributes) -> Self {
Self {
attributes,
parent: None,
presentation_mode: None,
accessibility: true,
}
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.attributes = self.attributes.with_title(title);
self
}
pub fn with_inner_size(mut self, width: f64, height: f64) -> Self {
self.attributes = self
.attributes
.with_inner_size(LogicalSize::new(width, height));
self
}
pub fn with_position(mut self, x: f64, y: f64) -> Self {
self.attributes = self.attributes.with_position(LogicalPosition::new(x, y));
self
}
pub fn with_min_inner_size(mut self, width: f64, height: f64) -> Self {
self.attributes = self
.attributes
.with_min_inner_size(LogicalSize::new(width, height));
self
}
pub fn with_max_inner_size(mut self, width: f64, height: f64) -> Self {
self.attributes = self
.attributes
.with_max_inner_size(LogicalSize::new(width, height));
self
}
pub fn with_decorations(mut self, decorations: bool) -> Self {
self.attributes = self.attributes.with_decorations(decorations);
self
}
pub fn with_resizable(mut self, resizable: bool) -> Self {
self.attributes = self.attributes.with_resizable(resizable);
self
}
pub fn with_always_on_top(mut self, on_top: bool) -> Self {
self.attributes = self.attributes.with_window_level(if on_top {
WindowLevel::AlwaysOnTop
} else {
WindowLevel::Normal
});
self
}
pub fn with_transparent(mut self, transparent: bool) -> Self {
self.attributes = self.attributes.with_transparent(transparent);
self
}
pub fn with_icon(mut self, icon: Icon) -> Self {
self.attributes = self.attributes.with_window_icon(Some(icon));
self
}
pub fn with_visible(mut self, visible: bool) -> Self {
self.attributes = self.attributes.with_visible(visible);
self
}
pub fn with_maximized(mut self, maximized: bool) -> Self {
self.attributes = self.attributes.with_maximized(maximized);
self
}
pub fn with_parent(mut self, parent: impl Into<WindowKey>) -> Self {
self.parent = Some(parent.into());
self
}
pub fn with_presentation_mode(mut self, mode: PresentationMode) -> Self {
self.presentation_mode = Some(mode);
self
}
pub fn with_rounded_corners(mut self, rounded: bool) -> Self {
self.attributes = super::round_corners(self.attributes, rounded);
self
}
pub fn with_accessibility(mut self, accessibility: bool) -> Self {
self.accessibility = accessibility;
self
}
pub fn parent(&self) -> Option<&WindowKey> {
self.parent.as_ref()
}
}