From 69cad5e6081b36b918b313670c19eaf97a57cd25 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 8 Jun 2016 16:26:23 -0400 Subject: [PATCH] Fixed uiForm on OS X. --- darwin/form.m | 43 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/darwin/form.m b/darwin/form.m index 7064c66c..67e3843b 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -1,6 +1,8 @@ // 7 june 2016 #import "uipriv_darwin.h" +// TODO in the test program, sometimes one of the radio buttons can disappear (try when spaced) + @interface formChild : NSView @property uiControl *c; @property (strong) NSTextField *label; @@ -8,8 +10,9 @@ @property NSLayoutPriority oldHorzHuggingPri; @property NSLayoutPriority oldVertHuggingPri; @property (strong) NSLayoutConstraint *baseline; -@property (strong) NSLayoutConstraint *trailing; +@property (strong) NSLayoutConstraint *leading; @property (strong) NSLayoutConstraint *top; +@property (strong) NSLayoutConstraint *trailing; @property (strong) NSLayoutConstraint *bottom; - (id)initWithLabel:(NSTextField *)l; - (void)onDestroy; @@ -59,20 +62,28 @@ struct uiForm { [self.label setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal]; [self.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical]; + [self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal]; + [self.label setContentCompressionResistancePriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical]; [self addSubview:self.label]; - self.trailing = mkConstraint(self.label, NSLayoutAttributeTrailing, - NSLayoutRelationEqual, - self, NSLayoutAttributeTrailing, + self.leading = mkConstraint(self.label, NSLayoutAttributeLeading, + NSLayoutRelationGreaterThanOrEqual, + self, NSLayoutAttributeLeading, 1, 0, - @"uiForm label trailing"); - [self addConstraint:self.trailing]; + @"uiForm label leading"); + [self addConstraint:self.leading]; self.top = mkConstraint(self.label, NSLayoutAttributeTop, NSLayoutRelationEqual, self, NSLayoutAttributeTop, 1, 0, @"uiForm label top"); [self addConstraint:self.top]; + self.trailing = mkConstraint(self.label, NSLayoutAttributeTrailing, + NSLayoutRelationEqual, + self, NSLayoutAttributeTrailing, + 1, 0, + @"uiForm label trailing"); + [self addConstraint:self.trailing]; self.bottom = mkConstraint(self.label, NSLayoutAttributeBottom, NSLayoutRelationEqual, self, NSLayoutAttributeBottom, @@ -253,7 +264,7 @@ struct uiForm { if (self->nStretchy != 0) relation = NSLayoutRelationLessThanOrEqual; self->last = mkConstraint(prev, NSLayoutAttributeBottom, - NSLayoutRelationEqual, + relation, self, NSLayoutAttributeBottom, 1, 0, @"uiForm last vertical constraint"); @@ -269,6 +280,16 @@ struct uiForm { @"uiForm leading constraint"); [self addConstraint:c]; [self->leadings addObject:c]; + // coerce the control to be as wide as possible + // see http://stackoverflow.com/questions/37710892/in-auto-layout-i-set-up-labels-that-shouldnt-grow-horizontally-and-controls-th + c = mkConstraint(self, NSLayoutAttributeLeading, + NSLayoutRelationEqual, + [fc view], NSLayoutAttributeLeading, + 1, 0, + @"uiForm leading constraint"); + [c setPriority:NSLayoutPriorityDefaultHigh]; + [self addConstraint:c]; + [self->leadings addObject:c]; c = mkConstraint(fc, NSLayoutAttributeTrailing, NSLayoutRelationEqual, [fc view], NSLayoutAttributeLeading, @@ -283,6 +304,14 @@ struct uiForm { @"uiForm trailing constraint"); [self addConstraint:c]; [self->trailings addObject:c]; + // TODO + c = mkConstraint(fc, NSLayoutAttributeBottom, + NSLayoutRelationLessThanOrEqual, + self, NSLayoutAttributeBottom, + 1, 0, + @"TODO"); + [self addConstraint:c]; + [self->trailings addObject:c]; } // we don't arrange the labels vertically; that's done when we add the control since those constraints don't need to change (they just need to be at their baseline)