summaryrefslogtreecommitdiff
path: root/glfw/src/window.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-06 21:59:52 +0200
committerHampusM <hampus@hampusmat.com>2023-10-06 21:59:52 +0200
commit5c0374e61be0ba39c89af8d3e801437255253ffb (patch)
tree40dad0b76c8ff12469e9c8eba32ed43985674983 /glfw/src/window.rs
parentf255db0f9252f4041b120dcaa00470889c4cb9f4 (diff)
feat(glfw): add window size function
Diffstat (limited to 'glfw/src/window.rs')
-rw-r--r--glfw/src/window.rs22
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.