From 05ecf4c78b4e74ec64f877b2c7944117f2fafe43 Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 24 May 2024 23:45:34 +0200 Subject: refactor(glfw): add window creation hint enum --- glfw/src/window.rs | 29 +++++++++++++++++++++++++---- 1 file 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) + pub fn hints(mut self, hints: impl IntoIterator) { 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 -- cgit v1.2.3-18-g5258