diff options
-rw-r--r-- | glfw/src/window.rs | 22 |
1 files changed, 22 insertions, 0 deletions
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<Size, Error> + { + 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. |