mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
Add resize example, fix warnings, make callback an option so it can be removed.
This commit is contained in:
parent
0ad9c3d453
commit
fa5cb66cff
|
@ -15,10 +15,15 @@ android_start!(main)
|
||||||
fn main() { println!("This example requires glutin to be compiled with the `window` feature"); }
|
fn main() { println!("This example requires glutin to be compiled with the `window` feature"); }
|
||||||
|
|
||||||
#[cfg(feature = "window")]
|
#[cfg(feature = "window")]
|
||||||
fn main() {
|
fn resize_callback(width: uint, height: uint) {
|
||||||
let window = glutin::Window::new().unwrap();
|
println!("Window resized to {}x{}", width, height);
|
||||||
window.set_title("A fantastic window!");
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "window")]
|
||||||
|
fn main() {
|
||||||
|
let mut window = glutin::Window::new().unwrap();
|
||||||
|
window.set_title("A fantastic window!");
|
||||||
|
window.set_window_resize_callback(Some(resize_callback));
|
||||||
unsafe { window.make_current() };
|
unsafe { window.make_current() };
|
||||||
|
|
||||||
let context = support::load(&window);
|
let context = support::load(&window);
|
||||||
|
|
|
@ -274,7 +274,7 @@ impl Window {
|
||||||
::Api::OpenGlEs
|
::Api::OpenGlEs
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -486,7 +486,7 @@ impl Window {
|
||||||
/// Sets a resize callback that is called by Mac (and potentially other
|
/// Sets a resize callback that is called by Mac (and potentially other
|
||||||
/// operating systems) during resize operations. This can be used to repaint
|
/// operating systems) during resize operations. This can be used to repaint
|
||||||
/// during window resizing.
|
/// during window resizing.
|
||||||
pub fn set_window_resize_callback(&mut self, callback: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, callback: Option<fn(uint, uint)>) {
|
||||||
self.window.set_window_resize_callback(callback);
|
self.window.set_window_resize_callback(callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -550,7 +550,7 @@ impl HeadlessContext {
|
||||||
self.context.get_api()
|
self.context.get_api()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,7 @@ struct DelegateState<'a> {
|
||||||
is_closed: bool,
|
is_closed: bool,
|
||||||
context: id,
|
context: id,
|
||||||
view: id,
|
view: id,
|
||||||
window: &'a Window,
|
handler: Option<fn(uint, uint)>,
|
||||||
handler: fn(uint, uint),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
|
@ -57,7 +56,7 @@ pub struct Window {
|
||||||
window: id,
|
window: id,
|
||||||
context: id,
|
context: id,
|
||||||
delegate: id,
|
delegate: id,
|
||||||
resize: fn(uint, uint),
|
resize: Option<fn(uint, uint)>,
|
||||||
|
|
||||||
is_closed: Cell<bool>,
|
is_closed: Cell<bool>,
|
||||||
}
|
}
|
||||||
|
@ -118,15 +117,20 @@ extern fn window_did_resize(this: id, _: id) -> id {
|
||||||
|
|
||||||
let _: id = msg_send()(state.context, selector("update"));
|
let _: id = msg_send()(state.context, selector("update"));
|
||||||
|
|
||||||
let rect = NSView::frame(state.view);
|
match state.handler {
|
||||||
(state.handler)(rect.size.width as uint, rect.size.height as uint);
|
Some(handler) => {
|
||||||
|
let rect = NSView::frame(state.view);
|
||||||
|
(handler)(rect.size.width as uint, rect.size.height as uint);
|
||||||
|
}
|
||||||
|
None => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option<MonitorID>,
|
fn new_impl(dimensions: Option<(uint, uint)>, title: &str, monitor: Option<MonitorID>,
|
||||||
vsync: bool, visible: bool) -> Result<Window, CreationError> {
|
vsync: bool, _visible: bool) -> Result<Window, CreationError> {
|
||||||
let app = match Window::create_app() {
|
let app = match Window::create_app() {
|
||||||
Some(app) => app,
|
Some(app) => app,
|
||||||
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
None => { return Err(OsError(format!("Couldn't create NSApplication"))); },
|
||||||
|
@ -173,7 +177,7 @@ impl Window {
|
||||||
window: window,
|
window: window,
|
||||||
context: context,
|
context: context,
|
||||||
delegate: delegate,
|
delegate: delegate,
|
||||||
resize: Window::resize,
|
resize: None,
|
||||||
|
|
||||||
is_closed: Cell::new(false),
|
is_closed: Cell::new(false),
|
||||||
};
|
};
|
||||||
|
@ -181,10 +185,6 @@ impl Window {
|
||||||
Ok(window)
|
Ok(window)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resize(_: uint, _: uint) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fn create_app() -> Option<id> {
|
fn create_app() -> Option<id> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let app = NSApp();
|
let app = NSApp();
|
||||||
|
@ -349,7 +349,6 @@ impl Window {
|
||||||
is_closed: self.is_closed.get(),
|
is_closed: self.is_closed.get(),
|
||||||
context: self.context,
|
context: self.context,
|
||||||
view: self.view,
|
view: self.view,
|
||||||
window: self,
|
|
||||||
handler: self.resize,
|
handler: self.resize,
|
||||||
};
|
};
|
||||||
object_setInstanceVariable(self.delegate,
|
object_setInstanceVariable(self.delegate,
|
||||||
|
@ -476,7 +475,7 @@ impl Window {
|
||||||
::Api::OpenGl
|
::Api::OpenGl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, callback: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, callback: Option<fn(uint, uint)>) {
|
||||||
self.resize = callback;
|
self.resize = callback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,7 @@ impl HeadlessContext {
|
||||||
::Api::OpenGl
|
::Api::OpenGl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -280,7 +280,7 @@ impl Window {
|
||||||
::Api::OpenGl
|
::Api::OpenGl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ impl HeadlessContext {
|
||||||
::Api::OpenGl
|
::Api::OpenGl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -599,6 +599,6 @@ impl Window {
|
||||||
::Api::OpenGl
|
::Api::OpenGl
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_window_resize_callback(&mut self, _: fn(uint, uint)) {
|
pub fn set_window_resize_callback(&mut self, _: Option<fn(uint, uint)>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue