Implement min/max window dimension constraints for MacOS.
Fixes https://github.com/tomaka/winit/issues/80.
This commit is contained in:
parent
25b5768cd3
commit
e3fce3d5ec
2 changed files with 21 additions and 7 deletions
|
|
@ -26,7 +26,7 @@ objc = "0.2"
|
||||||
[target.'cfg(target_os = "macos")'.dependencies]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
objc = "0.2"
|
objc = "0.2"
|
||||||
cgl = "0.1"
|
cgl = "0.1"
|
||||||
cocoa = "0.5.0"
|
cocoa = "0.5.1"
|
||||||
core-foundation = "0"
|
core-foundation = "0"
|
||||||
core-graphics = "0.4"
|
core-graphics = "0.4"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ use objc::declare::ClassDecl;
|
||||||
|
|
||||||
use cocoa::base::{id, nil};
|
use cocoa::base::{id, nil};
|
||||||
use cocoa::foundation::{NSAutoreleasePool, NSDate, NSDefaultRunLoopMode, NSPoint, NSRect, NSSize,
|
use cocoa::foundation::{NSAutoreleasePool, NSDate, NSDefaultRunLoopMode, NSPoint, NSRect, NSSize,
|
||||||
NSString, NSUInteger};
|
NSString, NSUInteger, NSArray};
|
||||||
use cocoa::appkit::{self, NSApplication, NSEvent, NSView, NSWindow};
|
use cocoa::appkit::{self, NSApplication, NSEvent, NSView, NSWindow, NSLayoutConstraint, NSLayoutDimension};
|
||||||
|
|
||||||
use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh, CGWarpMouseCursorPosition};
|
use core_graphics::display::{CGAssociateMouseAndMouseCursorPosition, CGMainDisplayID, CGDisplayPixelsHigh, CGWarpMouseCursorPosition};
|
||||||
|
|
||||||
|
|
@ -269,10 +269,6 @@ impl Window {
|
||||||
pl_attribs: &PlatformSpecificWindowBuilderAttributes)
|
pl_attribs: &PlatformSpecificWindowBuilderAttributes)
|
||||||
-> Result<Window, CreationError>
|
-> Result<Window, CreationError>
|
||||||
{
|
{
|
||||||
// not implemented
|
|
||||||
assert!(win_attribs.min_dimensions.is_none());
|
|
||||||
assert!(win_attribs.max_dimensions.is_none());
|
|
||||||
|
|
||||||
// let app = match Window::create_app() {
|
// let app = match Window::create_app() {
|
||||||
let app = match Window::create_app(pl_attribs.activation_policy) {
|
let app = match Window::create_app(pl_attribs.activation_policy) {
|
||||||
Some(app) => app,
|
Some(app) => app,
|
||||||
|
|
@ -300,6 +296,24 @@ impl Window {
|
||||||
} else {
|
} else {
|
||||||
window.makeKeyWindow();
|
window.makeKeyWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let mut constraints = vec![];
|
||||||
|
if let Some((width, height)) = win_attribs.min_dimensions {
|
||||||
|
constraints.extend_from_slice(&[
|
||||||
|
view.widthAnchor().constraintGreaterThanOrEqualToConstant(width.into()),
|
||||||
|
view.heightAnchor().constraintGreaterThanOrEqualToConstant(height.into()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if let Some((width, height)) = win_attribs.max_dimensions {
|
||||||
|
constraints.extend_from_slice(&[
|
||||||
|
view.widthAnchor().constraintLessThanOrEqualToConstant(width.into()),
|
||||||
|
view.heightAnchor().constraintLessThanOrEqualToConstant(height.into()),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
if !constraints.is_empty() {
|
||||||
|
let constraints_nsarray = NSArray::arrayWithObjects(nil, &constraints);
|
||||||
|
NSLayoutConstraint::activateConstraints(nil, constraints_nsarray);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let ds = DelegateState {
|
let ds = DelegateState {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue