1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
use crate::backend::Backend;
use crate::builder::{AppBuilder, BuildConfig};
/// Builder configuration for the window options
#[derive(Clone)]
pub struct WindowConfig {
/// Window's title
/// `Web: no-op`
pub title: String,
/// Window's width
pub width: i32,
/// Window's height
pub height: i32,
/// Start window in fullscreen mode
/// `Web: no-op`
pub fullscreen: bool,
/// Minimum resizable window's size
pub min_size: Option<(i32, i32)>,
/// Maximum resizable window's size
pub max_size: Option<(i32, i32)>,
/// Start the window maximized
/// `Web: no-op`
pub maximized: bool,
/// Allow to resize the window
/// `Web: no-op`
pub resizable: bool,
/// Enable V-Sync
/// `Web: no-op`
pub vsync: bool,
/// Antialias nultisamples level
/// `Web: WebGL will use this as antialias = false if the value is 0 or true otherwise`
pub multisampling: u16,
/// Enable High DPI viewport and drawing if the device pixel ratio is higher than 1
/// This is `false` by default, enable it could consume more resources and require
/// a custom way of drawing things. The advice is using it if you know what you're doing
pub high_dpi: bool,
/// Inner loop will run only after an input event
pub lazy_loop: bool,
/// Background as transparent
pub transparent: bool,
/// Enable decorations
/// `Web: Does nothing`
pub decorations: bool,
/// Hide the windows
pub visible: bool,
/// Use or create the canvas with this id. Only Web.
pub canvas_id: String,
}
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,
decorations: true,
visible: true,
canvas_id: String::from("notan_canvas"),
}
}
}
impl WindowConfig {
/// Create a new instance using default values
pub fn new() -> Self {
Default::default()
}
/// Sets the window's title
pub fn title(mut self, title: &str) -> Self {
self.title = title.to_string();
self
}
/// Inner loop will run only after an input event
pub fn lazy_loop(mut self, lazy: bool) -> Self {
self.lazy_loop = lazy;
self
}
/// Sets the window's width and height
pub fn size(mut self, width: i32, height: i32) -> Self {
self.width = width;
self.height = height;
self
}
/// Enable fullscreen mode
pub fn fullscreen(mut self, fullscreen: bool) -> Self {
self.fullscreen = fullscreen;
self
}
/// Sets the window's minimum size
pub fn min_size(mut self, width: i32, height: i32) -> Self {
self.min_size = Some((width, height));
self
}
/// Sets the window's maximum size
pub fn max_size(mut self, width: i32, height: i32) -> Self {
self.max_size = Some((width, height));
self
}
/// Starts the window maximized
pub fn maximized(mut self, maximized: bool) -> Self {
self.maximized = maximized;
self
}
/// Allow the window to be resizable
pub fn resizable(mut self, resizable: bool) -> Self {
self.resizable = resizable;
self
}
/// Enable vsync
pub fn vsync(mut self, vsync: bool) -> Self {
self.vsync = vsync;
self
}
/// Enabled multisampling aliasing (opengl)
pub fn multisampling(mut self, samples: u16) -> Self {
self.multisampling = samples;
self
}
/// Enable High DPI
pub fn high_dpi(mut self, enabled: bool) -> Self {
self.high_dpi = enabled;
self
}
/// Set the background as transparent
pub fn transparent(mut self, transparent: bool) -> Self {
self.transparent = transparent;
self
}
/// Enable or disable decorations
pub fn decorations(mut self, decorations: bool) -> Self {
self.decorations = decorations;
self
}
/// Hide or show the window
pub fn visible(mut self, visible: bool) -> Self {
self.visible = visible;
self
}
/// Use or create the canvas with this id. Only Web.
pub fn canvas_id(mut self, canvas_id: &str) -> Self {
self.canvas_id = canvas_id.to_string();
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
}
}