2016-11-29 23:02:42 +11:00
|
|
|
fn main() {
|
|
|
|
child_window_exemple::child_window();
|
|
|
|
}
|
2016-11-28 23:50:07 +11:00
|
|
|
|
2016-11-29 23:02:42 +11:00
|
|
|
#[cfg(windows)]
|
|
|
|
mod child_window_exemple {
|
2016-11-26 03:05:39 +11:00
|
|
|
|
2016-11-29 23:02:42 +11:00
|
|
|
extern crate winit;
|
|
|
|
extern crate winapi;
|
|
|
|
use std::thread;
|
|
|
|
use self::winit::os::windows::{WindowBuilderExt, WindowExt};
|
|
|
|
|
|
|
|
fn resize_callback(width: u32, height: u32) {
|
|
|
|
println!("Window resized to {}x{}", width, height);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Creates a main window and a child within it and handle their events separetely.
|
|
|
|
* Currently windows only
|
|
|
|
*/
|
|
|
|
pub fn child_window() {
|
|
|
|
let window = winit::WindowBuilder::new()
|
|
|
|
.with_title("A fantastic window!")
|
|
|
|
.with_window_resize_callback(resize_callback)
|
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let parent = window.get_hwnd() as winapi::HWND;
|
2016-11-26 03:05:39 +11:00
|
|
|
let child = winit::WindowBuilder::new()
|
|
|
|
.with_title("child window!")
|
|
|
|
.with_window_resize_callback(resize_callback)
|
|
|
|
.with_decorations(false)
|
2016-11-28 23:50:07 +11:00
|
|
|
.with_dimensions(100, 100)
|
2016-11-29 23:02:42 +11:00
|
|
|
.with_parent_window(parent)
|
2016-11-26 03:05:39 +11:00
|
|
|
.build()
|
|
|
|
.unwrap();
|
|
|
|
|
2016-11-29 23:02:42 +11:00
|
|
|
let child_thread = thread::spawn(move || {
|
|
|
|
for event in child.wait_events() {
|
|
|
|
println!("child {:?}", event);
|
|
|
|
|
|
|
|
match event {
|
|
|
|
winit::Event::Closed => break,
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
for event in window.wait_events() {
|
|
|
|
println!("parent {:?}", event);
|
2016-11-26 03:05:39 +11:00
|
|
|
|
|
|
|
match event {
|
|
|
|
winit::Event::Closed => break,
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-29 23:02:42 +11:00
|
|
|
child_thread.join().unwrap();
|
2016-11-26 03:05:39 +11:00
|
|
|
}
|
|
|
|
}
|
2016-11-29 23:02:42 +11:00
|
|
|
|
|
|
|
#[cfg(not(windows))]
|
|
|
|
mod child_window_exemple {
|
|
|
|
pub fn child_window() {}
|
|
|
|
}
|