summaryrefslogtreecommitdiff
path: root/sys/src/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'sys/src/window.rs')
-rw-r--r--sys/src/window.rs25
1 files changed, 16 insertions, 9 deletions
diff --git a/sys/src/window.rs b/sys/src/window.rs
index f9a8832..e66747d 100644
--- a/sys/src/window.rs
+++ b/sys/src/window.rs
@@ -1,13 +1,13 @@
-use std::ffi::{c_void, CString};
-use std::ops::ControlFlow;
+use std::ffi::CString;
+use std::num::NonZeroU32;
use crate::{CWindowConfig, CWindowEvent};
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct WindowConfig {
- pub title: String,
- pub default_width: u32,
- pub default_height: u32,
+ pub title: Option<String>,
+ pub default_width: NonZeroU32,
+ pub default_height: NonZeroU32,
pub default_x: u32,
pub default_y: u32,
pub visible: bool,
@@ -34,18 +34,24 @@ impl Drop for Window {
impl Window {
pub fn new(config: WindowConfig) -> Self {
- let title = CString::new(config.title.as_bytes()).unwrap();
+ let title = config
+ .title
+ .map(|title| CString::new(title.as_bytes()).unwrap());
let config = CWindowConfig {
- default_width: config.default_width,
- default_height: config.default_height,
+ default_width: config.default_width.get(),
+ default_height: config.default_height.get(),
default_x: config.default_x,
default_y: config.default_y,
visible: config.visible,
borderless_fullscreen: config.borderless_fullscreen,
- title: title.as_ptr(),
+ title: title
+ .as_ref()
+ .map(|title| title.as_ptr())
+ .unwrap_or(std::ptr::null()),
};
let window = unsafe { crate::create_window(config) };
+ drop(title);
Self { ptr: window }
}
@@ -58,6 +64,7 @@ impl Window {
let string = CString::new(title.to_string().as_bytes()).unwrap();
let bytes = string.as_ptr();
unsafe { crate::set_title(self.ptr, bytes) }
+ drop(string);
}
pub fn resize(&mut self, width: u32, height: u32) {