summaryrefslogtreecommitdiff
path: root/glfw/src
diff options
context:
space:
mode:
Diffstat (limited to 'glfw/src')
-rw-r--r--glfw/src/window.rs54
1 files changed, 50 insertions, 4 deletions
diff --git a/glfw/src/window.rs b/glfw/src/window.rs
index 5261eec..879d17e 100644
--- a/glfw/src/window.rs
+++ b/glfw/src/window.rs
@@ -129,14 +129,32 @@ impl Window
/// [`Window`] builder.
#[derive(Debug, Clone, Default)]
-pub struct Builder {}
+pub struct Builder
+{
+ hints: Vec<(Hint, i32)>,
+}
impl Builder
{
#[must_use]
pub fn new() -> Self
{
- Self {}
+ Self { hints: Vec::new() }
+ }
+
+ /// Adds a window creation hint to set.
+ #[must_use]
+ pub fn hint(mut self, hint: Hint, value: i32) -> Self
+ {
+ self.hints.push((hint, value));
+
+ self
+ }
+
+ /// Sets the window hints to set.
+ pub fn hints(mut self, hints: impl IntoIterator<Item = (Hint, i32)>)
+ {
+ self.hints = hints.into_iter().collect();
}
/// Creates a new window.
@@ -147,11 +165,22 @@ impl Builder
/// - A GLFW error occurs
pub fn create(&self, size: &Size, title: &str) -> Result<Window, Error>
{
- let init = initialize()?;
-
let c_title =
CString::new(title).map_err(|_| Error::InternalNulByteInWindowTitle)?;
+ let init = initialize()?;
+
+ for (hint, value) in &self.hints {
+ // SAFETY: The initialize function makes sure the current thread is the main
+ // thread
+ //
+ // 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.to_glfw(), *value);
+ }
+ }
+
// SAFETY: The initialize function makes sure the current thread is the main
// thread
let handle = unsafe {
@@ -174,6 +203,23 @@ impl Builder
}
}
+/// Window creation hint
+#[derive(Debug, Clone, Copy)]
+pub enum Hint
+{
+ OpenGLDebugContext,
+}
+
+impl Hint
+{
+ fn to_glfw(self) -> c_int
+ {
+ match self {
+ Self::OpenGLDebugContext => crate::ffi::GLFW_OPENGL_DEBUG_CONTEXT,
+ }
+ }
+}
+
/// Window size.
pub struct Size
{