remove WindowHandle
This commit is contained in:
parent
0633874266
commit
e02854452e
|
@ -39,7 +39,7 @@ fn main() {
|
||||||
|
|
||||||
let (mut tx, rx) = RingBuffer::new(128).split();
|
let (mut tx, rx) = RingBuffer::new(128).split();
|
||||||
|
|
||||||
let (_handle, opt_app_runner) = Window::open(
|
let opt_app_runner = Window::open(
|
||||||
window_open_options,
|
window_open_options,
|
||||||
|_| OpenWindowExample { rx }
|
|_| OpenWindowExample { rx }
|
||||||
);
|
);
|
||||||
|
|
|
@ -29,15 +29,6 @@ pub(super) const WINDOW_STATE_IVAR_NAME: &str = "WINDOW_STATE_IVAR_NAME";
|
||||||
pub(super) const FRAME_TIMER_IVAR_NAME: &str = "FRAME_TIMER";
|
pub(super) const FRAME_TIMER_IVAR_NAME: &str = "FRAME_TIMER";
|
||||||
|
|
||||||
|
|
||||||
pub struct Window {
|
|
||||||
/// Only set if we created the parent window, i.e. we are running in
|
|
||||||
/// parentless mode
|
|
||||||
ns_window: Option<id>,
|
|
||||||
/// Our subclassed NSView
|
|
||||||
ns_view: id,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
pub struct AppRunner;
|
pub struct AppRunner;
|
||||||
|
|
||||||
impl AppRunner {
|
impl AppRunner {
|
||||||
|
@ -51,14 +42,19 @@ impl AppRunner {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub struct WindowHandle;
|
pub struct Window {
|
||||||
|
/// Only set if we created the parent window, i.e. we are running in
|
||||||
|
/// parentless mode
|
||||||
|
ns_window: Option<id>,
|
||||||
|
/// Our subclassed NSView
|
||||||
|
ns_view: id,
|
||||||
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn open<H, B>(
|
pub fn open<H, B>(
|
||||||
options: WindowOpenOptions,
|
options: WindowOpenOptions,
|
||||||
build: B
|
build: B
|
||||||
) -> (crate::WindowHandle, Option<crate::AppRunner>)
|
) -> Option<crate::AppRunner>
|
||||||
where H: WindowHandler + 'static,
|
where H: WindowHandler + 'static,
|
||||||
B: FnOnce(&mut crate::Window) -> H,
|
B: FnOnce(&mut crate::Window) -> H,
|
||||||
B: Send + 'static
|
B: Send + 'static
|
||||||
|
@ -201,9 +197,7 @@ impl Window {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
let window_handle = crate::WindowHandle(WindowHandle);
|
opt_app_runner
|
||||||
|
|
||||||
(window_handle, opt_app_runner)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -195,8 +195,6 @@ pub struct Window {
|
||||||
hwnd: HWND,
|
hwnd: HWND,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WindowHandle;
|
|
||||||
|
|
||||||
pub struct AppRunner {
|
pub struct AppRunner {
|
||||||
hwnd: HWND,
|
hwnd: HWND,
|
||||||
}
|
}
|
||||||
|
@ -224,7 +222,7 @@ impl Window {
|
||||||
pub fn open<H, B>(
|
pub fn open<H, B>(
|
||||||
options: WindowOpenOptions,
|
options: WindowOpenOptions,
|
||||||
build: B
|
build: B
|
||||||
) -> (crate::WindowHandle, Option<crate::AppRunner>)
|
) -> Option<crate::AppRunner>
|
||||||
where H: WindowHandler + 'static,
|
where H: WindowHandler + 'static,
|
||||||
B: FnOnce(&mut crate::Window) -> H,
|
B: FnOnce(&mut crate::Window) -> H,
|
||||||
B: Send + 'static
|
B: Send + 'static
|
||||||
|
@ -301,15 +299,11 @@ impl Window {
|
||||||
SetWindowLongPtrA(hwnd, GWLP_USERDATA, Box::into_raw(window_state) as *const _ as _);
|
SetWindowLongPtrA(hwnd, GWLP_USERDATA, Box::into_raw(window_state) as *const _ as _);
|
||||||
SetTimer(hwnd, WIN_FRAME_TIMER, 15, None);
|
SetTimer(hwnd, WIN_FRAME_TIMER, 15, None);
|
||||||
|
|
||||||
let window_handle = crate::WindowHandle(WindowHandle);
|
if let crate::Parent::None = options.parent {
|
||||||
|
|
||||||
let opt_app_runner = if let crate::Parent::None = options.parent {
|
|
||||||
Some(crate::AppRunner(AppRunner { hwnd }))
|
Some(crate::AppRunner(AppRunner { hwnd }))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
}
|
||||||
|
|
||||||
(window_handle, opt_app_runner)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,13 @@ impl AppRunner {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct WindowHandle(pub(crate) platform::WindowHandle);
|
|
||||||
|
|
||||||
pub struct Window<'a>(pub(crate) &'a mut platform::Window);
|
pub struct Window<'a>(pub(crate) &'a mut platform::Window);
|
||||||
|
|
||||||
impl<'a> Window<'a> {
|
impl<'a> Window<'a> {
|
||||||
pub fn open<H, B>(
|
pub fn open<H, B>(
|
||||||
options: WindowOpenOptions,
|
options: WindowOpenOptions,
|
||||||
build: B
|
build: B
|
||||||
) -> (WindowHandle, Option<AppRunner>)
|
) -> Option<AppRunner>
|
||||||
where H: WindowHandler + 'static,
|
where H: WindowHandler + 'static,
|
||||||
B: FnOnce(&mut Window) -> H,
|
B: FnOnce(&mut Window) -> H,
|
||||||
B: Send + 'static
|
B: Send + 'static
|
||||||
|
@ -40,23 +38,3 @@ unsafe impl<'a> HasRawWindowHandle for Window<'a> {
|
||||||
self.0.raw_window_handle()
|
self.0.raw_window_handle()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile-time API assertions
|
|
||||||
#[doc(hidden)]
|
|
||||||
mod assertions {
|
|
||||||
use crate::{WindowHandle, WindowHandler, Event, Window};
|
|
||||||
|
|
||||||
struct TestWindowHandler {
|
|
||||||
#[allow(dead_code)]
|
|
||||||
ptr: *mut ::std::ffi::c_void,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl WindowHandler for TestWindowHandler {
|
|
||||||
fn on_event(&mut self, _: &mut Window, _: Event) {}
|
|
||||||
fn on_frame(&mut self) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assert that WindowHandle is Send even if WindowHandler isn't
|
|
||||||
static_assertions::assert_not_impl_any!(TestWindowHandler: Send);
|
|
||||||
static_assertions::assert_impl_all!(WindowHandle: Send);
|
|
||||||
}
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl Window {
|
||||||
pub fn open<H, B>(
|
pub fn open<H, B>(
|
||||||
options: WindowOpenOptions,
|
options: WindowOpenOptions,
|
||||||
build: B
|
build: B
|
||||||
) -> (crate::WindowHandle, Option<crate::AppRunner>)
|
) -> Option<crate::AppRunner>
|
||||||
where H: WindowHandler,
|
where H: WindowHandler,
|
||||||
B: FnOnce(&mut crate::Window) -> H,
|
B: FnOnce(&mut crate::Window) -> H,
|
||||||
B: Send + 'static
|
B: Send + 'static
|
||||||
|
@ -67,15 +67,11 @@ impl Window {
|
||||||
// FIXME: placeholder types for returning errors in the future
|
// FIXME: placeholder types for returning errors in the future
|
||||||
let _ = rx.recv();
|
let _ = rx.recv();
|
||||||
|
|
||||||
let window_handle = crate::WindowHandle(WindowHandle);
|
if is_not_parented {
|
||||||
|
|
||||||
let opt_app_runner = if is_not_parented {
|
|
||||||
Some(crate::AppRunner(AppRunner { thread }))
|
Some(crate::AppRunner(AppRunner { thread }))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
}
|
||||||
|
|
||||||
(window_handle, opt_app_runner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn window_thread<H, B>(
|
fn window_thread<H, B>(
|
||||||
|
|
Loading…
Reference in a new issue