From 5c0374e61be0ba39c89af8d3e801437255253ffb Mon Sep 17 00:00:00 2001 From: HampusM Date: Fri, 6 Oct 2023 21:59:52 +0200 Subject: feat(glfw): add window size function --- glfw/src/window.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'glfw/src/window.rs') diff --git a/glfw/src/window.rs b/glfw/src/window.rs index 6f5c845..e3e6383 100644 --- a/glfw/src/window.rs +++ b/glfw/src/window.rs @@ -118,6 +118,28 @@ impl Window should_close == crate::ffi::GLFW_TRUE } + + /// Retrieves the size of the window. + /// + /// # Errors + /// Will return `Err` if a GLFW platform error occurs. + pub fn size(&self) -> Result + { + let mut width = 0; + let mut height = 0; + + // SAFETY: The initialize function (called when the window is created) makes sure + // the current thread is the main thread + unsafe { crate::ffi::glfwGetWindowSize(self.handle, &mut width, &mut height) }; + + get_glfw_error()?; + + #[allow(clippy::cast_sign_loss)] + Ok(Size { + width: width as u32, + height: height as u32, + }) + } } /// Window size. -- cgit v1.2.3-18-g5258