mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 22:31:30 +11:00
child window creation improvement
This commit is contained in:
parent
5a09e8ba21
commit
2b25bf1480
|
@ -1,3 +1,5 @@
|
||||||
|
#![cfg(target_os = "windows")]
|
||||||
|
|
||||||
extern crate winit;
|
extern crate winit;
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use winit::os::windows::WindowBuilderExt;
|
use winit::os::windows::WindowBuilderExt;
|
||||||
|
@ -5,7 +7,10 @@ use winit::os::windows::WindowBuilderExt;
|
||||||
fn resize_callback(width: u32, height: u32) {
|
fn resize_callback(width: u32, height: u32) {
|
||||||
println!("Window resized to {}x{}", width, height);
|
println!("Window resized to {}x{}", width, height);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Creates a main window and a child within it and handle their events separetely.
|
||||||
|
* Currently windows only
|
||||||
|
*/
|
||||||
fn main() {
|
fn main() {
|
||||||
let window = winit::WindowBuilder::new()
|
let window = winit::WindowBuilder::new()
|
||||||
.with_title("A fantastic window!")
|
.with_title("A fantastic window!")
|
||||||
|
@ -19,6 +24,7 @@ fn main() {
|
||||||
.with_title("child window!")
|
.with_title("child window!")
|
||||||
.with_window_resize_callback(resize_callback)
|
.with_window_resize_callback(resize_callback)
|
||||||
.with_decorations(false)
|
.with_decorations(false)
|
||||||
|
.with_dimensions(100, 100)
|
||||||
.with_parent_window(proxy)
|
.with_parent_window(proxy)
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
@ -4,6 +4,8 @@ use libc;
|
||||||
use Window;
|
use Window;
|
||||||
use WindowBuilder;
|
use WindowBuilder;
|
||||||
use window;
|
use window;
|
||||||
|
use winapi;
|
||||||
|
use platform;
|
||||||
|
|
||||||
/// Additional methods on `Window` that are specific to Windows.
|
/// Additional methods on `Window` that are specific to Windows.
|
||||||
pub trait WindowExt {
|
pub trait WindowExt {
|
||||||
|
@ -35,3 +37,11 @@ impl WindowBuilderExt for WindowBuilder {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl WindowBuilderExt {
|
||||||
|
/// Creates a new WindowProxy from a winapi::HWND
|
||||||
|
#[inline]
|
||||||
|
pub fn create_window_proxy_from_handle(handle: winapi::HWND) -> window::WindowProxy {
|
||||||
|
window::WindowProxy::create_proxy(platform::WindowProxy{hwnd: handle})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ unsafe fn init(title: Vec<u16>, window: &WindowAttributes, pl_attribs: PlatformS
|
||||||
style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN,
|
style | winapi::WS_CLIPSIBLINGS | winapi::WS_CLIPCHILDREN,
|
||||||
x.unwrap_or(winapi::CW_USEDEFAULT), y.unwrap_or(winapi::CW_USEDEFAULT),
|
x.unwrap_or(winapi::CW_USEDEFAULT), y.unwrap_or(winapi::CW_USEDEFAULT),
|
||||||
width.unwrap_or(winapi::CW_USEDEFAULT), height.unwrap_or(winapi::CW_USEDEFAULT),
|
width.unwrap_or(winapi::CW_USEDEFAULT), height.unwrap_or(winapi::CW_USEDEFAULT),
|
||||||
pl_attribs.parent.map_or(ptr::null_mut(), |v| v.proxy.hwnd),
|
pl_attribs.parent.map_or(ptr::null_mut(), |v| v.get_proxy_data().hwnd),
|
||||||
ptr::null_mut(), kernel32::GetModuleHandleW(ptr::null()),
|
ptr::null_mut(), kernel32::GetModuleHandleW(ptr::null()),
|
||||||
ptr::null_mut());
|
ptr::null_mut());
|
||||||
|
|
||||||
|
|
|
@ -361,7 +361,7 @@ impl Window {
|
||||||
/// threads.
|
/// threads.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct WindowProxy {
|
pub struct WindowProxy {
|
||||||
pub proxy: platform::WindowProxy,
|
proxy: platform::WindowProxy,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WindowProxy {
|
impl WindowProxy {
|
||||||
|
@ -372,6 +372,18 @@ impl WindowProxy {
|
||||||
pub fn wakeup_event_loop(&self) {
|
pub fn wakeup_event_loop(&self) {
|
||||||
self.proxy.wakeup_event_loop();
|
self.proxy.wakeup_event_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the platform specific proxy data
|
||||||
|
#[inline]
|
||||||
|
pub fn get_proxy_data(&self) -> &platform::WindowProxy {
|
||||||
|
&self.proxy
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a WindowProxy by directly setting its platform specific data
|
||||||
|
#[inline]
|
||||||
|
pub fn create_proxy(data: platform::WindowProxy) -> WindowProxy {
|
||||||
|
WindowProxy {proxy: data}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/// An iterator for the `poll_events` function.
|
/// An iterator for the `poll_events` function.
|
||||||
pub struct PollEventsIterator<'a>(platform::PollEventsIterator<'a>);
|
pub struct PollEventsIterator<'a>(platform::PollEventsIterator<'a>);
|
||||||
|
|
Loading…
Reference in a new issue