From d8e02dad9e4a19b5b4e5234ea14b6f0f0bef9fab Mon Sep 17 00:00:00 2001 From: David Robillard Date: Fri, 20 May 2022 14:22:01 -0400 Subject: MacOS: Specify maximum size constraint on draw view I am not sure why the minimum was only specified before, but it seems like an oversight. --- src/mac.m | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/src/mac.m b/src/mac.m index 136680e..865355a 100644 --- a/src/mac.m +++ b/src/mac.m @@ -875,16 +875,18 @@ puglInitViewInternals(void) } static NSLayoutConstraint* -puglConstraint(id item, NSLayoutAttribute attribute, float constant) +puglConstraint(const id item, + const NSLayoutAttribute attribute, + const NSLayoutRelation relation, + const float constant) { - return - [NSLayoutConstraint constraintWithItem:item - attribute:attribute - relatedBy:NSLayoutRelationGreaterThanOrEqual - toItem:nil - attribute:NSLayoutAttributeNotAnAttribute - multiplier:1.0 - constant:(CGFloat)constant]; + return [NSLayoutConstraint constraintWithItem:item + attribute:attribute + relatedBy:relation + toItem:nil + attribute:NSLayoutAttributeNotAnAttribute + multiplier:1.0 + constant:(CGFloat)constant]; } PuglStatus @@ -959,12 +961,32 @@ puglRealize(PuglView* view) impl->wrapperView->markedText = [[NSMutableAttributedString alloc] init]; [impl->wrapperView setAutoresizesSubviews:YES]; [impl->wrapperView initWithFrame:framePt]; - [impl->wrapperView addConstraint:puglConstraint(impl->wrapperView, - NSLayoutAttributeWidth, - view->minWidth)]; - [impl->wrapperView addConstraint:puglConstraint(impl->wrapperView, - NSLayoutAttributeHeight, - view->minHeight)]; + + [impl->wrapperView + addConstraint:puglConstraint(impl->wrapperView, + NSLayoutAttributeWidth, + NSLayoutRelationGreaterThanOrEqual, + view->minWidth)]; + + [impl->wrapperView + addConstraint:puglConstraint(impl->wrapperView, + NSLayoutAttributeHeight, + NSLayoutRelationGreaterThanOrEqual, + view->minHeight)]; + + if (view->maxWidth && view->maxHeight) { + [impl->wrapperView + addConstraint:puglConstraint(impl->wrapperView, + NSLayoutAttributeWidth, + NSLayoutRelationLessThanOrEqual, + view->maxWidth)]; + + [impl->wrapperView + addConstraint:puglConstraint(impl->wrapperView, + NSLayoutAttributeHeight, + NSLayoutRelationLessThanOrEqual, + view->maxHeight)]; + } // Create draw view to be rendered to PuglStatus st = PUGL_SUCCESS; -- cgit v1.2.1