use std::path::PathBuf;
use crate::backend::Backend;
use crate::builder::{AppBuilder, BuildConfig};
#[derive(Clone)]
pub struct WindowConfig {
pub title: String,
pub width: i32,
pub height: i32,
pub fullscreen: bool,
pub min_size: Option<(i32, i32)>,
pub max_size: Option<(i32, i32)>,
pub maximized: bool,
pub resizable: bool,
pub vsync: bool,
pub multisampling: u8,
pub high_dpi: bool,
pub lazy_loop: bool,
pub transparent: bool,
pub always_on_top: bool,
pub decorations: bool,
pub visible: bool,
pub mouse_passthrough: bool,
pub canvas_id: String,
pub window_icon_path: Option<PathBuf>,
pub taskbar_icon_path: Option<PathBuf>,
}
impl Default for WindowConfig {
fn default() -> Self {
Self {
title: String::from("Notan App"),
width: 800,
height: 600,
fullscreen: false,
min_size: None,
max_size: None,
maximized: false,
resizable: false,
vsync: false,
multisampling: 0,
high_dpi: false,
lazy_loop: false,
transparent: false,
always_on_top: false,
decorations: true,
visible: true,
mouse_passthrough: false,
canvas_id: String::from("notan_canvas"),
window_icon_path: None,
taskbar_icon_path: None,
}
}
}
impl WindowConfig {
pub fn new() -> Self {
Default::default()
}
pub fn title(mut self, title: &str) -> Self {
self.title = title.to_string();
self
}
pub fn lazy_loop(mut self, lazy: bool) -> Self {
self.lazy_loop = lazy;
self
}
pub fn size(mut self, width: i32, height: i32) -> Self {
self.width = width;
self.height = height;
self
}
pub fn fullscreen(mut self, fullscreen: bool) -> Self {
self.fullscreen = fullscreen;
self
}
pub fn min_size(mut self, width: i32, height: i32) -> Self {
self.min_size = Some((width, height));
self
}
pub fn max_size(mut self, width: i32, height: i32) -> Self {
self.max_size = Some((width, height));
self
}
pub fn maximized(mut self, maximized: bool) -> Self {
self.maximized = maximized;
self
}
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
pub fn vsync(mut self, vsync: bool) -> Self {
self.vsync = vsync;
self
}
pub fn multisampling(mut self, samples: u8) -> Self {
self.multisampling = samples;
self
}
pub fn high_dpi(mut self, enabled: bool) -> Self {
self.high_dpi = enabled;
self
}
pub fn transparent(mut self, transparent: bool) -> Self {
self.transparent = transparent;
self
}
pub fn always_on_top(mut self, always_on_top: bool) -> Self {
self.always_on_top = always_on_top;
self
}
pub fn decorations(mut self, decorations: bool) -> Self {
self.decorations = decorations;
self
}
pub fn visible(mut self, visible: bool) -> Self {
self.visible = visible;
self
}
pub fn mouse_passthrough(mut self, mouse_passthrough: bool) -> Self {
self.mouse_passthrough = mouse_passthrough;
self
}
pub fn canvas_id(mut self, canvas_id: &str) -> Self {
self.canvas_id = canvas_id.to_string();
self
}
pub fn window_icon(mut self, window_icon_path: Option<PathBuf>) -> Self {
self.window_icon_path = window_icon_path;
self
}
pub fn taskbar_icon(mut self, taskbar_icon_path: Option<PathBuf>) -> Self {
self.taskbar_icon_path = taskbar_icon_path;
self
}
}
impl<S, B> BuildConfig<S, B> for WindowConfig
where
B: Backend,
{
fn apply(&self, mut builder: AppBuilder<S, B>) -> AppBuilder<S, B> {
builder.window = self.clone();
builder
}
}