browser_window/window/
builder.rs1use unsafe_send_sync::UnsafeSend;
2
3use crate::{application::*, core::prelude::*, window::*, HasHandle};
4
5
6pub struct WindowBuilder {
8 pub(crate) borders: bool,
9 pub(crate) height: Option<u32>,
10 pub(crate) minimizable: bool,
11 pub(crate) parent: Option<UnsafeSend<WindowImpl>>,
12 pub(crate) resizable: bool,
13 pub(crate) title: Option<String>,
14 pub(crate) width: Option<u32>,
15}
16
17#[allow(dead_code)]
18pub type WindowOptions = cbw_WindowOptions;
19
20impl WindowBuilder {
21 pub fn borders(&mut self, value: bool) { self.borders = value; }
24
25 #[allow(dead_code)]
27 fn build(self, app: ApplicationHandle) {
28 let title: &str = match self.title.as_ref() {
30 None => "",
31 Some(t) => t,
32 };
33
34 let window_options = WindowOptions {
36 borders: self.borders,
37 minimizable: self.minimizable,
38 resizable: self.resizable,
39 };
40
41 let parent_impl_handle = match self.parent {
43 None => WindowImpl::default(),
44 Some(parent) => (*parent).clone(),
45 };
46
47 let _impl_handle = WindowImpl::new(
48 app.inner,
49 parent_impl_handle,
50 title.into(),
51 self.width as _,
52 self.height as _,
53 &window_options,
54 );
55 }
56
57 pub fn height(&mut self, height: u32) { self.height = Some(height); }
59
60 pub fn minimizable(&mut self, value: bool) { self.minimizable = value; }
63
64 pub fn parent<W>(&mut self, bw: &W)
68 where
69 W: HasHandle<WindowHandle>,
70 {
71 self.parent = Some(UnsafeSend::new(bw.handle().0.clone()));
72 }
73
74 pub fn new() -> Self {
75 Self {
76 borders: true,
77 height: None,
78 minimizable: true,
79 parent: None,
80 resizable: true,
81 title: None,
82 width: None,
83 }
84 }
85
86 pub fn size(&mut self, width: u32, height: u32) {
88 self.width = Some(width);
89 self.height = Some(height);
90 }
91
92 pub fn title<S: Into<String>>(&mut self, title: S) { self.title = Some(title.into()); }
94
95 pub fn width(&mut self, width: u32) { self.width = Some(width); }
97
98 pub fn resizable(&mut self, resizable: bool) { self.resizable = resizable; }
101}