three_d/window/winit_window/
settings.rs

1/// Selects the level of hardware graphics acceleration.
2#[derive(Clone, Copy, Debug, PartialEq, Eq)]
3pub enum HardwareAcceleration {
4    /// Require graphics acceleration.
5    Required,
6    /// Prefer graphics acceleration, but fall back to software.
7    Preferred,
8    /// Do NOT use graphics acceleration.
9    /// On some platforms (MacOS) this is ignored and treated the same as
10    /// [Self::Preferred].
11    /// On web, "willReadFrequently" is set to true.
12    Off,
13}
14
15/// Settings controlling the behavior of the surface on where to draw, to present it on the screen.
16#[derive(Clone, Copy, Debug, PartialEq, Eq)]
17#[allow(dead_code)]
18pub struct SurfaceSettings {
19    /// Turn on vertical syncing, limiting the FPS to the display refresh rate.
20    /// The default is true.
21    /// On web this has no effect since vsync is always on.
22    pub vsync: bool,
23    /// Sets the number of bits in the depth buffer.
24    /// A value of 0 means no depth buffer.
25    /// The default value is 24.
26    /// On web, this can only be off (0) or on (>0).
27    pub depth_buffer: u8,
28    /// Sets the number of bits in the stencil buffer.
29    /// A value of 0 means no stencil buffer.
30    /// The default value is 0.
31    /// On web, this can only be off (0) or on (>0).
32    pub stencil_buffer: u8,
33    /// Set the level of the multisampling anti-aliasing (MSAA).
34    /// Must be a power-of-two. Higher = more smooth edges.
35    /// A value of 0 turns it off.
36    /// The default value is 4.
37    /// On web, this can only be off (0) or on (>0).
38    /// The actual number of samples depends on browser settings.
39    pub multisamples: u8,
40    /// Specify whether or not hardware acceleration is preferred, required, or
41    /// off. The default is [HardwareAcceleration::Preferred].
42    pub hardware_acceleration: HardwareAcceleration,
43}
44
45impl Default for SurfaceSettings {
46    fn default() -> Self {
47        Self {
48            vsync: true,
49            depth_buffer: 24,
50            stencil_buffer: 0,
51            multisamples: 4,
52            hardware_acceleration: HardwareAcceleration::Preferred,
53        }
54    }
55}
56
57///
58/// Settings for the default [Window](super::Window).
59///
60#[derive(Debug, Clone, PartialEq, Eq)]
61pub struct WindowSettings {
62    /// The title of the window.
63    ///
64    /// On web this has no effect.
65    pub title: String,
66    /// The minimum size of the window `(width, height)`, in logical pixels.
67    ///
68    /// On web this has no effect.
69    pub min_size: (u32, u32),
70    /// The maximum size of the window `(width, height)`, in logical pixels.
71    /// If `None` is specified, the window can be maximized.
72    pub max_size: Option<(u32, u32)>,
73    /// The initial size of the window `(width, height)`, in logical pixels.
74    /// If `None` is specified, defaults to max_size.
75    ///
76    /// On web, the size will be applied to the [canvas][WindowSettings::canvas], in logical pixels.
77    /// If `None` is specified on both this and max_size, the canvas will be
78    /// resized to the same size as the owner `Window`'s inner width and height.
79    pub initial_size: Option<(u32, u32)>,
80    /// Borderless mode.
81    ///
82    /// On web this has no effect.
83    pub borderless: bool,
84    /// An optional [canvas element][web_sys::HtmlCanvasElement] for using as winit window.
85    /// If this is `None`, the DOM (`index.html`) must contain a canvas element
86    #[cfg(target_arch = "wasm32")]
87    pub canvas: Option<web_sys::HtmlCanvasElement>,
88
89    /// Settings related to the surface on where to draw.
90    pub surface_settings: SurfaceSettings,
91}
92impl Default for WindowSettings {
93    fn default() -> Self {
94        Self {
95            title: "".to_string(),
96            min_size: (2, 2),
97            max_size: None,
98            initial_size: None,
99            borderless: false,
100            #[cfg(target_arch = "wasm32")]
101            canvas: None,
102            surface_settings: SurfaceSettings::default(),
103        }
104    }
105}
106
107impl std::ops::Deref for WindowSettings {
108    type Target = SurfaceSettings;
109    fn deref(&self) -> &Self::Target {
110        &self.surface_settings
111    }
112}
113
114impl std::ops::DerefMut for WindowSettings {
115    fn deref_mut(&mut self) -> &mut Self::Target {
116        &mut self.surface_settings
117    }
118}