summaryrefslogtreecommitdiff
path: root/glfw/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2024-05-24 23:45:34 +0200
committerHampusM <hampus@hampusmat.com>2024-05-24 23:45:34 +0200
commit05ecf4c78b4e74ec64f877b2c7944117f2fafe43 (patch)
treea24526b249a748f6f509523811ee487223e5b660 /glfw/src
parent05bd5ccbc5dd9bd8516162ac9a253e2d99be3ba9 (diff)
refactor(glfw): add window creation hint enum
Diffstat (limited to 'glfw/src')
-rw-r--r--glfw/src/window.rs29
1 files changed, 25 insertions, 4 deletions
diff --git a/glfw/src/window.rs b/glfw/src/window.rs
index 25c7425..ca712a9 100644
--- a/glfw/src/window.rs
+++ b/glfw/src/window.rs
@@ -355,7 +355,7 @@ impl Window
#[derive(Debug, Clone, Default)]
pub struct Builder
{
- hints: Vec<(Hint, i32)>,
+ hints: Vec<(Hint, HintValue)>,
}
impl Builder
@@ -368,7 +368,7 @@ impl Builder
/// Adds a window creation hint to set.
#[must_use]
- pub fn hint(mut self, hint: Hint, value: i32) -> Self
+ pub fn hint(mut self, hint: Hint, value: HintValue) -> Self
{
self.hints.push((hint, value));
@@ -376,7 +376,7 @@ impl Builder
}
/// Sets the window hints to set.
- pub fn hints(mut self, hints: impl IntoIterator<Item = (Hint, i32)>)
+ pub fn hints(mut self, hints: impl IntoIterator<Item = (Hint, HintValue)>)
{
self.hints = hints.into_iter().collect();
}
@@ -401,7 +401,19 @@ impl Builder
// Error is not checked for after since the two possible errors
// (GLFW_NOT_INITIALIZED and GLFW_INVALID_ENUM) cannot occur.
unsafe {
- crate::ffi::glfwWindowHint(*hint as i32, *value);
+ crate::ffi::glfwWindowHint(
+ *hint as i32,
+ match value {
+ HintValue::Number(num) => *num,
+ HintValue::Bool(boolean) => {
+ if *boolean {
+ crate::ffi::GLFW_TRUE
+ } else {
+ crate::ffi::GLFW_FALSE
+ }
+ }
+ },
+ );
}
}
@@ -435,6 +447,15 @@ pub enum Hint
DoubleBuffer = crate::ffi::GLFW_DOUBLEBUFFER,
}
+/// Window creation hint value.
+#[derive(Debug, Clone)]
+#[non_exhaustive]
+pub enum HintValue
+{
+ Number(i32),
+ Bool(bool),
+}
+
/// Window size.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Size