From 19d831c5b1d56070c193d0c8310272f34ad3160d Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 8 Dec 2025 19:50:10 -0500 Subject: Stuff --- sys/src/window.rs | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'sys/src/window.rs') 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, + 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) { -- cgit v1.2.3