diff options
Diffstat (limited to 'glfw/src/window.rs')
-rw-r--r-- | glfw/src/window.rs | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/glfw/src/window.rs b/glfw/src/window.rs index fa5dcd7..5261eec 100644 --- a/glfw/src/window.rs +++ b/glfw/src/window.rs @@ -15,40 +15,6 @@ pub struct Window impl Window { - /// Creates a new window. - /// - /// # Errors - /// Will return `Err` if - /// - The title contains an internal nul byte - /// - A GLFW error occurs - pub fn create(size: &Size, title: &str) -> Result<Self, Error> - { - let init = initialize()?; - - let c_title = - CString::new(title).map_err(|_| Error::InternalNulByteInWindowTitle)?; - - // SAFETY: The initialize function makes sure the current thread is the main - // thread - let handle = unsafe { - #[allow(clippy::cast_possible_wrap)] - crate::ffi::glfwCreateWindow( - size.width as i32, - size.height as i32, - c_title.as_ptr(), - null_mut(), - null_mut(), - ) - }; - - get_glfw_error()?; - - Ok(Self { - _init: init, - handle, - }) - } - /// Makes the context of the window current for the calling thread. /// /// # Errors @@ -161,6 +127,53 @@ impl Window } } +/// [`Window`] builder. +#[derive(Debug, Clone, Default)] +pub struct Builder {} + +impl Builder +{ + #[must_use] + pub fn new() -> Self + { + Self {} + } + + /// Creates a new window. + /// + /// # Errors + /// Will return `Err` if + /// - The title contains an internal nul byte + /// - 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)?; + + // SAFETY: The initialize function makes sure the current thread is the main + // thread + let handle = unsafe { + #[allow(clippy::cast_possible_wrap)] + crate::ffi::glfwCreateWindow( + size.width as i32, + size.height as i32, + c_title.as_ptr(), + null_mut(), + null_mut(), + ) + }; + + get_glfw_error()?; + + Ok(Window { + _init: init, + handle, + }) + } +} + /// Window size. pub struct Size { |