Skip to content

Commit 0f35f1e

Browse files
committed
add default methods to WindowOpenOptions
1 parent 237d323 commit 0f35f1e

2 files changed

Lines changed: 34 additions & 3 deletions

File tree

src/gl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod macos;
2121
#[cfg(target_os = "macos")]
2222
use macos as platform;
2323

24-
#[derive(Clone, Debug)]
24+
#[derive(Clone, Debug, PartialEq)]
2525
pub struct GlConfig {
2626
pub version: (u8, u8),
2727
pub profile: Profile,

src/window_open_options.rs

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
use crate::Size;
22

3+
#[cfg(feature = "opengl")]
4+
use crate::gl::GlConfig;
5+
36
/// The dpi scaling policy of the window
4-
#[derive(Debug, Clone, Copy, PartialEq)]
7+
#[derive(Default, Debug, Clone, Copy, PartialEq)]
58
pub enum WindowScalePolicy {
69
/// Use the system's dpi scale factor
10+
#[default]
711
SystemScaleFactor,
812
/// Use the given dpi scale factor (e.g. `1.0` = 96 dpi)
913
ScaleFactor(f64),
1014
}
1115

1216
/// The options for opening a new window
17+
#[derive(Debug, Clone, PartialEq)]
1318
pub struct WindowOpenOptions {
1419
pub title: String,
1520

@@ -24,6 +29,32 @@ pub struct WindowOpenOptions {
2429

2530
/// If provided, then an OpenGL context will be created for this window. You'll be able to
2631
/// access this context through [crate::Window::gl_context].
32+
///
33+
/// By default this is set to `Some(GlConfig::default())`.
2734
#[cfg(feature = "opengl")]
28-
pub gl_config: Option<crate::gl::GlConfig>,
35+
pub gl_config: Option<GlConfig>,
36+
}
37+
38+
impl WindowOpenOptions {
39+
pub fn default_no_gl() -> Self {
40+
Self {
41+
title: String::from("baseview window"),
42+
size: Size { width: 500.0, height: 400.0 },
43+
scale: WindowScalePolicy::default(),
44+
#[cfg(feature = "opengl")]
45+
gl_config: None,
46+
}
47+
}
48+
}
49+
50+
impl Default for WindowOpenOptions {
51+
fn default() -> Self {
52+
Self {
53+
title: String::from("baseview window"),
54+
size: Size { width: 500.0, height: 400.0 },
55+
scale: WindowScalePolicy::default(),
56+
#[cfg(feature = "opengl")]
57+
gl_config: Some(GlConfig::default()),
58+
}
59+
}
2960
}

0 commit comments

Comments
 (0)