diff --git a/src/lib.rs b/src/lib.rs index 67ac9dd..47a95a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,26 +2,21 @@ use raw_window_handle::RawWindowHandle; #[cfg(target_os = "windows")] mod win; -#[cfg(target_os = "windows")] -pub use win::*; - #[cfg(target_os = "linux")] mod x11; -#[cfg(target_os = "linux")] -pub use crate::x11::*; - #[cfg(target_os = "macos")] mod macos; -#[cfg(target_os = "macos")] -pub use macos::*; mod event; mod keyboard; mod mouse_cursor; +mod window; mod window_info; mod window_open_options; + pub use event::*; pub use mouse_cursor::MouseCursor; +pub use window::*; pub use window_info::*; pub use window_open_options::*; diff --git a/src/macos/window.rs b/src/macos/window.rs index 7194eb8..755a390 100644 --- a/src/macos/window.rs +++ b/src/macos/window.rs @@ -58,12 +58,12 @@ impl WindowHandle { impl Window { pub fn open(options: WindowOpenOptions, build: B) -> WindowHandle where H: WindowHandler, - B: FnOnce(&mut Window) -> H, + B: FnOnce(&mut crate::window::Window) -> H, B: Send + 'static { let _pool = unsafe { NSAutoreleasePool::new(nil) }; - let mut window = match options.parent { + let window = match options.parent { Parent::WithParent(parent) => { if let RawWindowHandle::MacOS(handle) = parent { let ns_view = handle.ns_view as *mut objc::runtime::Object; @@ -155,10 +155,12 @@ impl Window { }, }; + let mut window = crate::window::Window(window); + let window_handler = build(&mut window); let window_state_arc = Arc::new(WindowState { - window, + window: window, window_handler, keyboard_state: KeyboardState::new(), }); @@ -168,7 +170,7 @@ impl Window { ) as *mut c_void; unsafe { - (*window_state_arc.window.ns_view).set_ivar( + (*window_state_arc.window.0.ns_view).set_ivar( WINDOW_STATE_IVAR_NAME, window_state_pointer ); @@ -183,13 +185,13 @@ impl Window { let timer: id = msg_send![ ::objc::class!(NSTimer), scheduledTimerWithTimeInterval:timer_interval - target:window_state_arc.window.ns_view + target:window_state_arc.window.0.ns_view selector:selector userInfo:nil repeats:YES ]; - (*window_state_arc.window.ns_view).set_ivar( + (*window_state_arc.window.0.ns_view).set_ivar( FRAME_TIMER_IVAR_NAME, timer as *mut c_void, ) @@ -201,7 +203,7 @@ impl Window { pub(super) struct WindowState { - window: Window, + window: crate::window::Window, window_handler: H, keyboard_state: KeyboardState, } diff --git a/src/window.rs b/src/window.rs new file mode 100644 index 0000000..3d67573 --- /dev/null +++ b/src/window.rs @@ -0,0 +1,36 @@ +use crate::WindowHandler; +use crate::window_open_options::WindowOpenOptions; + +#[cfg(target_os = "windows")] +use crate::win as platform; +#[cfg(target_os = "linux")] +use crate::x11 as platform; +#[cfg(target_os = "macos")] +use crate::macos as platform; + + +pub struct WindowHandle(platform::WindowHandle); + + +impl WindowHandle { + pub fn app_run_blocking(self){ + self.0.app_run_blocking(); + } +} + + +pub struct Window(pub(crate) platform::Window); + + +impl Window { + pub fn open( + options: WindowOpenOptions, + build: B + ) -> WindowHandle + where H: WindowHandler, + B: FnOnce(&mut Window) -> H, + B: Send + 'static + { + WindowHandle(platform::Window::open::(options, build)) + } +} \ No newline at end of file