use unsafe_send_sync::UnsafeSend;
use crate::{application::*, core::prelude::*, window::*, HasHandle};
pub struct WindowBuilder {
pub(crate) borders: bool,
pub(crate) height: Option<u32>,
pub(crate) minimizable: bool,
pub(crate) parent: Option<UnsafeSend<WindowImpl>>,
pub(crate) resizable: bool,
pub(crate) title: Option<String>,
pub(crate) width: Option<u32>,
}
#[allow(dead_code)]
pub type WindowOptions = cbw_WindowOptions;
impl WindowBuilder {
pub fn borders(&mut self, value: bool) { self.borders = value; }
#[allow(dead_code)]
fn build(self, app: ApplicationHandle) {
let title: &str = match self.title.as_ref() {
None => "",
Some(t) => t,
};
let window_options = WindowOptions {
borders: self.borders,
minimizable: self.minimizable,
resizable: self.resizable,
};
let parent_impl_handle = match self.parent {
None => WindowImpl::default(),
Some(parent) => (*parent).clone(),
};
let _impl_handle = WindowImpl::new(
app.inner,
parent_impl_handle,
title.into(),
self.width as _,
self.height as _,
&window_options,
);
}
pub fn height(&mut self, height: u32) { self.height = Some(height); }
pub fn minimizable(&mut self, value: bool) { self.minimizable = value; }
pub fn parent<W>(&mut self, bw: &W)
where
W: HasHandle<WindowHandle>,
{
self.parent = Some(UnsafeSend::new(bw.handle().0.clone()));
}
pub fn new() -> Self {
Self {
borders: true,
height: None,
minimizable: true,
parent: None,
resizable: true,
title: None,
width: None,
}
}
pub fn size(&mut self, width: u32, height: u32) {
self.width = Some(width);
self.height = Some(height);
}
pub fn title<S: Into<String>>(&mut self, title: S) { self.title = Some(title.into()); }
pub fn width(&mut self, width: u32) { self.width = Some(width); }
pub fn resizable(&mut self, resizable: bool) { self.resizable = resizable; }
}