aboutsummaryrefslogtreecommitdiffstats
path: root/pugl
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2017-10-03 16:10:42 +0200
committerDavid Robillard <d@drobilla.net>2017-10-03 16:20:52 +0200
commit39ad8490488fdb61b0afd21963ec0d6da4732270 (patch)
tree961f05837f131d65140b03e862e44fdb14d6b00c /pugl
parent706166497d2cc2f71fd417c398630fe8790a23e7 (diff)
downloadpugl-39ad8490488fdb61b0afd21963ec0d6da4732270.tar.gz
pugl-39ad8490488fdb61b0afd21963ec0d6da4732270.tar.bz2
pugl-39ad8490488fdb61b0afd21963ec0d6da4732270.zip
Fix size constraints on OSX
Diffstat (limited to 'pugl')
-rw-r--r--pugl/pugl_osx.m54
1 files changed, 39 insertions, 15 deletions
diff --git a/pugl/pugl_osx.m b/pugl/pugl_osx.m
index d911441..8ce6881 100644
--- a/pugl/pugl_osx.m
+++ b/pugl/pugl_osx.m
@@ -64,16 +64,13 @@ struct PuglInternalsImpl {
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag
{
- if (![super initWithContentRect:contentRect
- styleMask:(NSClosableWindowMask |
- NSTitledWindowMask |
- NSResizableWindowMask)
- backing:NSBackingStoreBuffered defer:NO]) {
- return nil;
- }
+ NSWindow* result = [super initWithContentRect:contentRect
+ styleMask:aStyle
+ backing:bufferingType
+ defer:NO];
- [self setAcceptsMouseMovedEvents:YES];
- return (PuglWindow*)self;
+ [result setAcceptsMouseMovedEvents:YES];
+ return (PuglWindow*)result;
}
- (void)setPuglview:(PuglView*)view
@@ -563,6 +560,19 @@ puglLeaveContext(PuglView* view, bool flush)
}
}
+static NSLayoutConstraint*
+puglConstraint(id item, NSLayoutAttribute attribute, float constant)
+{
+ return [NSLayoutConstraint
+ constraintWithItem: item
+ attribute: attribute
+ relatedBy: NSLayoutRelationGreaterThanOrEqual
+ toItem: nil
+ attribute: NSLayoutAttributeNotAnAttribute
+ multiplier: 1.0
+ constant: constant];
+}
+
int
puglCreateWindow(PuglView* view, const char* title)
{
@@ -574,6 +584,15 @@ puglCreateWindow(PuglView* view, const char* title)
impl->glview = [PuglOpenGLView new];
impl->glview->puglview = view;
+ [impl->glview setFrameSize:NSMakeSize(view->width, view->height)];
+ [impl->glview addConstraint:
+ puglConstraint(impl->glview, NSLayoutAttributeWidth, view->min_width)];
+ [impl->glview addConstraint:
+ puglConstraint(impl->glview, NSLayoutAttributeHeight, view->min_height)];
+ if (!view->resizable) {
+ [impl->glview setAutoresizingMask:NSViewNotSizable];
+ }
+
if (view->transient_parent) {
NSView* pview = (NSView*)view->transient_parent;
[pview addSubview:impl->glview];
@@ -583,8 +602,18 @@ puglCreateWindow(PuglView* view, const char* title)
initWithBytes:title
length:strlen(title)
encoding:NSUTF8StringEncoding];
+ NSRect frame = NSMakeRect(0, 0, view->min_width, view->min_height);
+ unsigned style = NSClosableWindowMask | NSTitledWindowMask;
+ if (view->resizable) {
+ style |= NSResizableWindowMask;
+ }
- id window = [[PuglWindow new] retain];
+ id window = [[[PuglWindow alloc]
+ initWithContentRect:frame
+ styleMask:style
+ backing:NSBackingStoreBuffered
+ defer:NO
+ ] retain];
[window setPuglview:view];
[window setTitle:titleString];
if (view->min_width || view->min_height) {
@@ -597,11 +626,6 @@ puglCreateWindow(PuglView* view, const char* title)
[impl->app activateIgnoringOtherApps:YES];
[window makeFirstResponder:impl->glview];
[window makeKeyAndOrderFront:window];
-#if 0
- if (resizable) {
- [impl->glview setAutoresizingMask:NSViewWidthSizable|NSViewHeightSizable];
- }
-#endif
}
return 0;