1
0
Fork 0

x11: WindowHandle.app_run_blocking()

This commit is contained in:
William Light 2020-09-11 18:25:50 +02:00
parent 5207d961d9
commit 196883b390
2 changed files with 26 additions and 19 deletions

View file

@ -1,16 +1,5 @@
use baseview::{Event, Window, WindowHandler};
fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview".into(),
width: 512,
height: 512,
parent: baseview::Parent::None,
};
let _handle = Window::open::<MyProgram>(window_open_options);
}
struct MyProgram {}
impl WindowHandler for MyProgram {
@ -33,3 +22,15 @@ impl WindowHandler for MyProgram {
fn on_message(&mut self, _window: &mut Window, _message: Self::Message) {}
}
fn main() {
let window_open_options = baseview::WindowOpenOptions {
title: "baseview".into(),
width: 512,
height: 512,
parent: baseview::Parent::None,
};
let handle = Window::open::<MyProgram>(window_open_options);
handle.app_run_blocking();
}

View file

@ -21,18 +21,24 @@ pub struct Window {
}
// FIXME: move to outer crate context
pub struct WindowHandle;
pub struct WindowHandle {
thread: std::thread::JoinHandle<()>
}
impl WindowHandle {
pub fn app_run_blocking(self) {
let _ = self.thread.join();
}
}
impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
let runner = thread::spawn(move || {
WindowHandle {
thread: thread::spawn(move || {
Self::window_thread::<H>(options);
});
let _ = runner.join();
WindowHandle
})
}
}
fn window_thread<H: WindowHandler>(options: WindowOpenOptions) {