Implemented the basic Auto Layout manager for tWindow and tButton. Added tWindow this time too >_>
This commit is contained in:
parent
9ecf15f4e0
commit
391f6dd265
|
@ -15,6 +15,7 @@
|
|||
[self->b setBordered:YES];
|
||||
[self->b setBezelStyle:NSRoundedBezelStyle];
|
||||
[self->b setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]];
|
||||
[self->b setTranslatesAutoresizingMaskIntoConstraints:NO];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -31,4 +32,15 @@
|
|||
return n;
|
||||
}
|
||||
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableString *)horz
|
||||
vert:(NSMutableString *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views
|
||||
{
|
||||
[horz setString:@"[view0]"];
|
||||
[vert setString:@"[view0]"];
|
||||
[views setObject:self->b forKey:@"view0"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -5,7 +5,12 @@
|
|||
@protocol tControl
|
||||
@required
|
||||
- (void)tAddToView:(NSView *)v;
|
||||
- (uintmax_t)tAddToAutoLayoutDictionary:(NSMutableDictionary *)views keyNumber:(uintmax_t)n;
|
||||
//TODO- (uintmax_t)tAddToAutoLayoutDictionary:(NSMutableDictionary *)views keyNumber:(uintmax_t)n;
|
||||
- (void)tFillAutoLayoutHorz:(NSMutableString *)horz
|
||||
vert:(NSMutableString *)vert
|
||||
extra:(NSMutableArray *)extra
|
||||
extraVert:(NSMutableArray *)extraVert
|
||||
views:(NSMutableDictionary *)views;
|
||||
@end
|
||||
|
||||
@interface tWindow : NSObject<tControl>
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
// 1 august 2015
|
||||
#include "osxaltest.h"
|
||||
|
||||
@implementation tWindow {
|
||||
NSWindow *w;
|
||||
id<tControl> c;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self->w = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 320, 240)
|
||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||
backing:NSBackingStoreBuffered
|
||||
defer:YES];
|
||||
[self->w setTitle:@"Auto Layout Test"];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)tSetControl:(id<tControl>)cc
|
||||
{
|
||||
self->c = cc;
|
||||
[self->c tAddToView:[self->w contentView]];
|
||||
[self tRelayout];
|
||||
}
|
||||
|
||||
- (void)tShow
|
||||
{
|
||||
[self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)];
|
||||
[self->w makeKeyAndOrderFront:self];
|
||||
}
|
||||
|
||||
- (void)tRelayout
|
||||
{
|
||||
NSView *contentView;
|
||||
NSMutableString *horz, *vert;
|
||||
NSMutableArray *extra, *extraVert;
|
||||
NSMutableDictionary *views;
|
||||
NSInteger i;
|
||||
|
||||
contentView = [self->w contentView];
|
||||
[contentView removeConstraints:[contentView constraints]];
|
||||
horz = [NSMutableString new];
|
||||
vert = [NSMutableString new];
|
||||
extra = [NSMutableArray new];
|
||||
extraVert = [NSMutableArray new];
|
||||
views = [NSMutableDictionary new];
|
||||
[self->c tFillAutoLayoutHorz:horz vert:vert extra:extra extraVert:extraVert views:views];
|
||||
[extra addObject:[NSString stringWithFormat:@"|%@|", horz]];
|
||||
[extraVert addObject:@NO];
|
||||
[extra addObject:[NSString stringWithFormat:@"|%@|", vert]];
|
||||
[extraVert addObject:@YES];
|
||||
for (i = 0; i < [extra count]; i++) {
|
||||
NSString *constraint;
|
||||
NSNumber *vertical;
|
||||
NSArray *constraints;
|
||||
|
||||
vertical = (NSNumber *) [extraVert objectAtIndex:i];
|
||||
if ([vertical boolValue])
|
||||
constraint = [NSString stringWithFormat:@"V:%@", [extra objectAtIndex:i]];
|
||||
else
|
||||
constraint = [NSString stringWithFormat:@"H:%@", [extra objectAtIndex:i]];
|
||||
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint options:0 metrics:nil views:views];
|
||||
[contentView addConstraints:constraints];
|
||||
}
|
||||
// TODO release everything
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue