Changed tWindow to use the single-view-per-control model.
This commit is contained in:
parent
90cd19fca6
commit
bdf3bed5f4
|
@ -7,24 +7,11 @@ typedef struct tAutoLayoutParams tAutoLayoutParams;
|
||||||
// TODO stretchy across both dimensions
|
// TODO stretchy across both dimensions
|
||||||
// for a vertical box, the horizontal width should be variable
|
// for a vertical box, the horizontal width should be variable
|
||||||
struct tAutoLayoutParams {
|
struct tAutoLayoutParams {
|
||||||
NSMutableArray *horz;
|
NSView *view;
|
||||||
NSMutableArray *horzAttachLeft;
|
BOOL attachLeft;
|
||||||
NSMutableArray *horzAttachRight;
|
BOOL attachTop;
|
||||||
BOOL horzFirst;
|
BOOL attachRight;
|
||||||
BOOL horzLast;
|
BOOL attachBottom;
|
||||||
NSMutableArray *vert;
|
|
||||||
NSMutableArray *vertAttachTop;
|
|
||||||
NSMutableArray *vertAttachBottom;
|
|
||||||
BOOL vertFirst;
|
|
||||||
BOOL vertLast;
|
|
||||||
NSMutableDictionary *views;
|
|
||||||
uintmax_t n;
|
|
||||||
BOOL horzStretchy;
|
|
||||||
BOOL horzFirstStretchy;
|
|
||||||
uintmax_t horzStretchyTo;
|
|
||||||
BOOL vertStretchy;
|
|
||||||
BOOL vertFirstStretchy;
|
|
||||||
uintmax_t vertStretchyTo;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@protocol tControl
|
@protocol tControl
|
||||||
|
|
|
@ -43,8 +43,10 @@
|
||||||
{
|
{
|
||||||
NSView *contentView;
|
NSView *contentView;
|
||||||
tAutoLayoutParams p;
|
tAutoLayoutParams p;
|
||||||
|
NSDictionary *views;
|
||||||
NSString *margin;
|
NSString *margin;
|
||||||
void (^run)(NSArray *, NSArray *, NSArray *, NSString *);
|
NSMutableString *constraint;
|
||||||
|
NSArray *constraints;
|
||||||
|
|
||||||
if (self->c == nil)
|
if (self->c == nil)
|
||||||
return;
|
return;
|
||||||
|
@ -52,58 +54,45 @@
|
||||||
contentView = [self->w contentView];
|
contentView = [self->w contentView];
|
||||||
[contentView removeConstraints:[contentView constraints]];
|
[contentView removeConstraints:[contentView constraints]];
|
||||||
|
|
||||||
p.horz = [NSMutableArray new];
|
|
||||||
p.horzAttachLeft = [NSMutableArray new];
|
|
||||||
p.horzAttachRight = [NSMutableArray new];
|
|
||||||
p.horzFirst = YES; // only control here
|
|
||||||
p.horzLast = YES;
|
|
||||||
p.vert = [NSMutableArray new];
|
|
||||||
p.vertAttachTop = [NSMutableArray new];
|
|
||||||
p.vertAttachBottom = [NSMutableArray new];
|
|
||||||
p.vertFirst = YES;
|
|
||||||
p.vertLast = YES;
|
|
||||||
p.views = [NSMutableDictionary new];
|
|
||||||
p.n = 0;
|
|
||||||
p.horzStretchy = YES; // assumption for the sole control to avoid fixed size hacks
|
|
||||||
p.horzFirstStretchy = YES;
|
|
||||||
p.vertStretchy = YES;
|
|
||||||
p.vertFirstStretchy = YES;
|
|
||||||
[self->c tFillAutoLayout:&p];
|
[self->c tFillAutoLayout:&p];
|
||||||
|
|
||||||
|
views = [NSDictionary dictionaryWithObject:p.view forKey:@"view"];
|
||||||
|
|
||||||
margin = @"";
|
margin = @"";
|
||||||
if (self->margined)
|
if (self->margined)
|
||||||
margin = @"-";
|
margin = @"-";
|
||||||
|
|
||||||
run = ^(NSArray *side, NSArray *attachStart, NSArray *attachEnd, NSString *prefix) {
|
// TODO always append margins even if not attached?
|
||||||
NSUInteger i;
|
// or if not attached, append ->=0- as well?
|
||||||
|
constraint = [NSMutableString stringWithString:@"H:"];
|
||||||
for (i = 0; i < [side count]; i++) {
|
if (p.attachLeft) {
|
||||||
NSMutableString *constraint;
|
|
||||||
NSNumber *attach;
|
|
||||||
NSArray *constraints;
|
|
||||||
|
|
||||||
constraint = [NSMutableString stringWithString:prefix];
|
|
||||||
attach = (NSNumber *) [attachStart objectAtIndex:i];
|
|
||||||
if ([attach boolValue]) {
|
|
||||||
[constraint appendString:@"|"];
|
[constraint appendString:@"|"];
|
||||||
[constraint appendString:margin];
|
[constraint appendString:margin];
|
||||||
}
|
}
|
||||||
[constraint appendString:[side objectAtIndex:i]];
|
[constraint appendString:@"[view]"];
|
||||||
attach = (NSNumber *) [attachEnd objectAtIndex:i];
|
if (p.attachRight) {
|
||||||
if ([attach boolValue]) {
|
|
||||||
[constraint appendString:margin];
|
[constraint appendString:margin];
|
||||||
[constraint appendString:@"|"];
|
[constraint appendString:@"|"];
|
||||||
}
|
}
|
||||||
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:p.views];
|
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:p.views];
|
||||||
[contentView addConstraints:constraints];
|
[contentView addConstraints:constraints];
|
||||||
//TODO uncomment this and the program tries to access after free [constraint release];
|
[constraint release];
|
||||||
|
|
||||||
|
constraint = [NSMutableString stringWithString:@"V:"];
|
||||||
|
if (p.attachTop) {
|
||||||
|
[constraint appendString:@"|"];
|
||||||
|
[constraint appendString:margin];
|
||||||
}
|
}
|
||||||
};
|
[constraint appendString:@"[view]"];
|
||||||
|
if (p.attachBottom) {
|
||||||
|
[constraint appendString:margin];
|
||||||
|
[constraint appendString:@"|"];
|
||||||
|
}
|
||||||
|
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:p.views];
|
||||||
|
[contentView addConstraints:constraints];
|
||||||
|
[constraint release];
|
||||||
|
|
||||||
run(p.horz, p.horzAttachLeft, p.horzAttachRight, @"H:");
|
[views release];
|
||||||
run(p.vert, p.vertAttachTop, p.vertAttachBottom, @"V:");
|
|
||||||
|
|
||||||
// TODO release everything
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue