I give up. MCVE time.

This commit is contained in:
Pietro Gagliardi 2016-06-08 08:55:57 -04:00
parent 45d394fc81
commit d232342779
1 changed files with 62 additions and 13 deletions

View File

@ -1,13 +1,18 @@
// 7 june 2016 // 7 june 2016
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
@interface formChild : NSObject @interface formChild : NSView
@property uiControl *c; @property uiControl *c;
@property (strong) NSTextField *label; @property (strong) NSTextField *label;
@property BOOL stretchy; @property BOOL stretchy;
@property NSLayoutPriority oldHorzHuggingPri; @property NSLayoutPriority oldHorzHuggingPri;
@property NSLayoutPriority oldVertHuggingPri; @property NSLayoutPriority oldVertHuggingPri;
@property (strong) NSLayoutConstraint *baseline; @property (strong) NSLayoutConstraint *baseline;
@property (strong) NSLayoutConstraint *trailing;
@property (strong) NSLayoutConstraint *top;
@property (strong) NSLayoutConstraint *bottom;
- (id)initWithLabel:(NSTextField *)l;
- (void)onDestroy;
- (NSView *)view; - (NSView *)view;
@end @end
@ -46,6 +51,51 @@ struct uiForm {
@implementation formChild @implementation formChild
- (id)initWithLabel:(NSTextField *)l
{
self = [super initWithFrame:NSZeroRect];
if (self) {
self.label = l;
[self.label setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal];
[self.label setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationVertical];
[self addSubview:self.label];
self.trailing = mkConstraint(self.label, NSLayoutAttributeTrailing,
NSLayoutRelationEqual,
self, NSLayoutAttributeTrailing,
1, 0,
@"uiForm label trailing");
[self addConstraint:self.trailing];
self.top = mkConstraint(self.label, NSLayoutAttributeTop,
NSLayoutRelationEqual,
self, NSLayoutAttributeTop,
1, 0,
@"uiForm label top");
[self addConstraint:self.top];
self.bottom = mkConstraint(self.label, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
1, 0,
@"uiForm label bottom");
[self addConstraint:self.bottom];
}
return self;
}
- (void)onDestroy
{
[self removeConstraint:self.trailing];
self.trailing = nil;
[self removeConstraint:self.top];
self.top = nil;
[self removeConstraint:self.bottom];
self.bottom = nil;
[self.label removeFromSuperview];
self.label = nil;
}
- (NSView *)view - (NSView *)view
{ {
return (NSView *) uiControlHandle(self.c); return (NSView *) uiControlHandle(self.c);
@ -90,8 +140,8 @@ struct uiForm {
uiControlSetParent(fc.c, NULL); uiControlSetParent(fc.c, NULL);
uiDarwinControlSetSuperview(uiDarwinControl(fc.c), nil); uiDarwinControlSetSuperview(uiDarwinControl(fc.c), nil);
uiControlDestroy(fc.c); uiControlDestroy(fc.c);
[fc.label removeFromSuperview]; [fc onDestroy];
fc.label = nil; [fc removeFromSuperview];
} }
[self->children release]; [self->children release];
} }
@ -149,7 +199,7 @@ struct uiForm {
{ {
formChild *fc; formChild *fc;
CGFloat padding; CGFloat padding;
NSView *prev, *prevlabel;; NSView *prev, *prevlabel;
NSLayoutConstraint *c; NSLayoutConstraint *c;
NSLayoutRelation relation; NSLayoutRelation relation;
@ -170,7 +220,7 @@ struct uiForm {
[self addConstraint:self->first]; [self addConstraint:self->first];
[self->first retain]; [self->first retain];
prev = [fc view]; prev = [fc view];
prevlabel = fc.label; prevlabel = fc;
continue; continue;
} }
// not the first; link it // not the first; link it
@ -191,13 +241,13 @@ struct uiForm {
[self->widths addObject:c]; [self->widths addObject:c];
c = mkConstraint(prevlabel, NSLayoutAttributeWidth, c = mkConstraint(prevlabel, NSLayoutAttributeWidth,
NSLayoutRelationEqual, NSLayoutRelationEqual,
fc.label, NSLayoutAttributeWidth, fc, NSLayoutAttributeWidth,
1, 0, 1, 0,
@"uiForm label lwidth constraint"); @"uiForm label lwidth constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->widths addObject:c]; [self->widths addObject:c];
prev = [fc view]; prev = [fc view];
prevlabel = fc.label; prevlabel = fc;
} }
relation = NSLayoutRelationEqual; relation = NSLayoutRelationEqual;
if (self->nStretchy != 0) if (self->nStretchy != 0)
@ -214,12 +264,12 @@ struct uiForm {
for (fc in self->children) { for (fc in self->children) {
c = mkConstraint(self, NSLayoutAttributeLeading, c = mkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual, NSLayoutRelationEqual,
fc.label, NSLayoutAttributeLeading, fc, NSLayoutAttributeLeading,
1, 0, 1, 0,
@"uiForm leading constraint"); @"uiForm leading constraint");
[self addConstraint:c]; [self addConstraint:c];
[self->leadings addObject:c]; [self->leadings addObject:c];
c = mkConstraint(fc.label, NSLayoutAttributeTrailing, c = mkConstraint(fc, NSLayoutAttributeTrailing,
NSLayoutRelationEqual, NSLayoutRelationEqual,
[fc view], NSLayoutAttributeLeading, [fc view], NSLayoutAttributeLeading,
1, -padding, 1, -padding,
@ -245,14 +295,13 @@ struct uiForm {
NSLayoutAttribute attribute; NSLayoutAttribute attribute;
uintmax_t oldnStretchy; uintmax_t oldnStretchy;
fc = [formChild new]; fc = [[formChild alloc] initWithLabel:newLabel(label)];
fc.c = c; fc.c = c;
fc.label = newLabel(label);
[fc.label setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:fc.label];
fc.stretchy = stretchy; fc.stretchy = stretchy;
fc.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationHorizontal); fc.oldHorzHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationHorizontal);
fc.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationVertical); fc.oldVertHuggingPri = uiDarwinControlHuggingPriority(uiDarwinControl(fc.c), NSLayoutConstraintOrientationVertical);
[fc setTranslatesAutoresizingMaskIntoConstraints:NO];
[self addSubview:fc];
uiControlSetParent(fc.c, uiControl(self->f)); uiControlSetParent(fc.c, uiControl(self->f));
uiDarwinControlSetSuperview(uiDarwinControl(fc.c), self); uiDarwinControlSetSuperview(uiDarwinControl(fc.c), self);