Added margined to tWindow.

This commit is contained in:
Pietro Gagliardi 2015-08-01 15:44:06 -04:00
parent 391f6dd265
commit 554454f036
3 changed files with 21 additions and 2 deletions

View File

@ -3,6 +3,8 @@
// #qo LDFLAGS: -framework Foundation -framework AppKit
BOOL margined = NO;
@interface appDelegate : NSObject<NSApplicationDelegate>
@end
@ -14,6 +16,7 @@
tButton *button;
mainwin = [[tWindow alloc] init];
[mainwin tSetMargined:margined];
button = [[tButton alloc] tInitWithText:@"Button"];
[mainwin tSetControl:button];
@ -32,6 +35,8 @@ int main(int argc, char *argv[])
{
NSApplication *app;
margined = argc > 1;
app = [NSApplication sharedApplication];
[app setActivationPolicy:NSApplicationActivationPolicyRegular];
[app setDelegate:[appDelegate new]];

View File

@ -15,6 +15,7 @@
@interface tWindow : NSObject<tControl>
- (void)tSetControl:(id<tControl>)cc;
- (void)tSetMargined:(BOOL)m;
- (void)tShow;
// TODO this should probably in tControl
- (void)tRelayout;

View File

@ -4,6 +4,7 @@
@implementation tWindow {
NSWindow *w;
id<tControl> c;
BOOL margined;
}
- (id)init
@ -26,6 +27,12 @@
[self tRelayout];
}
- (void)tSetMargined:(BOOL)m
{
self->margined = m;
[self tRelayout];
}
- (void)tShow
{
[self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)];
@ -39,7 +46,10 @@
NSMutableArray *extra, *extraVert;
NSMutableDictionary *views;
NSInteger i;
NSString *margin;
if (self->c == nil)
return;
contentView = [self->w contentView];
[contentView removeConstraints:[contentView constraints]];
horz = [NSMutableString new];
@ -48,9 +58,12 @@
extraVert = [NSMutableArray new];
views = [NSMutableDictionary new];
[self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views];
[extra addObject:[NSString stringWithFormat:@"|%@|", horz]];
margin = @"";
if (self->margined)
margin = @"-";
[extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, horz, margin]];
[extraVert addObject:@NO];
[extra addObject:[NSString stringWithFormat:@"|%@|", vert]];
[extra addObject:[NSString stringWithFormat:@"|%@%@%@|", margin, vert, margin]];
[extraVert addObject:@YES];
for (i = 0; i < [extra count]; i++) {
NSString *constraint;