use crate::core::{Display, Monitor, Point2, Context, Result};
#[must_use]
#[derive(Clone)]
pub struct DisplayBuilder {
pub(crate) width : u32,
pub(crate) height : u32,
pub(crate) title : String,
pub(crate) transparent : bool,
pub(crate) decorations : bool,
pub(crate) monitor : Option<Monitor>,
pub(crate) vsync : bool,
pub(crate) visible : bool,
pub(crate) context : Option<Context>,
}
impl DisplayBuilder {
pub fn width(mut self: Self, width: u32) -> Self {
self.width = width;
self
}
pub fn height(mut self: Self, height: u32) -> Self {
self.height = height;
self
}
pub fn dimensions<T>(mut self: Self, dimensions: T) -> Self where Point2<u32>: From<T> {
let dimensions = Point2::<u32>::from(dimensions);
self.width = dimensions.0;
self.height = dimensions.1;
self
}
pub fn title(mut self: Self, title: &str) -> Self {
self.title = title.to_string();
self
}
pub fn transparent(mut self: Self) -> Self {
self.transparent = true;
self
}
pub fn borderless(mut self: Self) -> Self {
self.decorations = false;
self
}
pub fn monitor(mut self: Self, monitor: Monitor) -> Self {
self.monitor = Some(monitor);
self
}
pub fn vsync(mut self: Self) -> Self {
self.vsync = true;
self
}
pub fn context(mut self: Self, context: &Context) -> Self {
self.context = Some(context.clone());
self
}
pub fn hidden(mut self: Self) -> Self {
self.visible = false;
self
}
pub fn build(self: Self) -> Result<Display> {
Display::new(self)
}
pub(crate) fn new() -> Self {
DisplayBuilder { ..DisplayBuilder::default() }
}
}
impl Default for DisplayBuilder {
fn default() -> DisplayBuilder {
DisplayBuilder {
width : 640,
height : 480,
title : "".to_string(),
transparent : false,
decorations : true,
monitor : None,
vsync : false,
visible : true,
context : None,
}
}
}