diff options
| author | Mica White <botahamec@outlook.com> | 2025-12-08 19:50:10 -0500 |
|---|---|---|
| committer | Mica White <botahamec@outlook.com> | 2025-12-08 19:50:10 -0500 |
| commit | 19d831c5b1d56070c193d0c8310272f34ad3160d (patch) | |
| tree | e3886c715fbd0f63930d4a43f964ea1e575785ba /sys/src/window.rs | |
| parent | ea5db5846bc700f0da912225ddcb4be372359044 (diff) | |
Diffstat (limited to 'sys/src/window.rs')
| -rw-r--r-- | sys/src/window.rs | 25 |
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) {
|
