mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Merge pull request #88 from mitchmindtree/resize_cb_builder
Add a `WindowBuilder::with_window_resize_callback` method.
This commit is contained in:
commit
25b5768cd3
|
@ -12,9 +12,11 @@ fn resize_callback(width: u32, height: u32) {
|
|||
}
|
||||
|
||||
fn main() {
|
||||
let mut window = winit::WindowBuilder::new().build().unwrap();
|
||||
window.set_title("A fantastic window!");
|
||||
window.set_window_resize_callback(Some(resize_callback as fn(u32, u32)));
|
||||
let window = winit::WindowBuilder::new()
|
||||
.with_title("A fantastic window!")
|
||||
.with_window_resize_callback(resize_callback)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
for event in window.wait_events() {
|
||||
println!("{:?}", event);
|
||||
|
|
|
@ -259,6 +259,10 @@ pub struct WindowAttributes {
|
|||
/// [iOS only] Enable multitouch, see [UIView#multipleTouchEnabled]
|
||||
/// (https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instp/UIView/multipleTouchEnabled)
|
||||
pub multitouch: bool,
|
||||
|
||||
/// A function called upon resizing, necessary to receive resize events on Mac and possibly
|
||||
/// other systems.
|
||||
pub resize_callback: Option<fn(u32, u32)>,
|
||||
}
|
||||
|
||||
impl Default for WindowAttributes {
|
||||
|
@ -274,6 +278,7 @@ impl Default for WindowAttributes {
|
|||
transparent: false,
|
||||
decorations: true,
|
||||
multitouch: false,
|
||||
resize_callback: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -93,6 +93,15 @@ impl WindowBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
/// Provides a resize callback that is called by Mac (and potentially other
|
||||
/// operating systems) during resize operations. This can be used to repaint
|
||||
/// during window resizing.
|
||||
#[inline]
|
||||
pub fn with_window_resize_callback(mut self, cb: fn(u32, u32)) -> WindowBuilder {
|
||||
self.window.resize_callback = Some(cb);
|
||||
self
|
||||
}
|
||||
|
||||
/// Builds the window.
|
||||
///
|
||||
/// Error should be very rare and only occur in case of permission denied, incompatible system,
|
||||
|
@ -109,7 +118,14 @@ impl WindowBuilder {
|
|||
}
|
||||
|
||||
// building
|
||||
platform::Window::new(&self.window, &self.platform_specific).map(|w| Window { window: w })
|
||||
let mut w = try!(platform::Window::new(&self.window, &self.platform_specific));
|
||||
|
||||
// a window resize callback was given
|
||||
if let Some(callback) = self.window.resize_callback {
|
||||
w.set_window_resize_callback(Some(callback));
|
||||
}
|
||||
|
||||
Ok(Window { window: w })
|
||||
}
|
||||
|
||||
/// Builds the window.
|
||||
|
|
Loading…
Reference in a new issue