diff --git a/redo/osxaltest/label.m b/redo/osxaltest/label.m new file mode 100644 index 00000000..d715b04a --- /dev/null +++ b/redo/osxaltest/label.m @@ -0,0 +1,61 @@ +// 31 july 2015 +#import "osxaltest.h" + +@implementation tLabel { + NSTextField *t; + id parent; + NSLayoutPriority horzpri, vertpri; +} + +- (id)init +{ + self = [super init]; + if (self) { + self->t = [[NSTextField alloc] initWithFrame:NSZeroRect]; + [self->t setStringValue:@"Label"]; + [self->t setEditable:NO]; + [self->t setSelectable:NO]; + [self->t setDrawsBackground:NO]; + [self->t setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; + [self->t setBordered:NO]; + [self->t setBezelStyle:NSTextFieldSquareBezel]; + [self->t setBezeled:NO]; + [[self->t cell] setLineBreakMode:NSLineBreakByClipping]; + [[self->t cell] setScrollable:YES]; + [self->t setTranslatesAutoresizingMaskIntoConstraints:NO]; + + self->parent = nil; + + self->horzpri = [self->t contentHuggingPriorityForOrientation:NSLayoutConstraintOrientationHorizontal]; + self->vertpri = [self->t contentHuggingPriorityForOrientation:NSLayoutConstraintOrientationVertical]; + } + return self; +} + +- (void)tSetParent:(id)p addToView:(NSView *)v relayout:(BOOL)relayout +{ + self->parent = p; + [v addSubview:self->t]; + if (relayout) + [self tRelayout]; +} + +- (void)tFillAutoLayout:(tAutoLayoutParams *)p +{ + // reset the hugging priority + [self->t setContentHuggingPriority:self->horzpri forOrientation:NSLayoutConstraintOrientationHorizontal]; + [self->t setContentHuggingPriority:self->vertpri forOrientation:NSLayoutConstraintOrientationVertical]; + p->view = self->t; + p->attachLeft = YES; + p->attachTop = YES; + p->attachRight = YES; + p->attachBottom = YES; +} + +- (void)tRelayout +{ + if (self->parent != nil) + [self->parent tRelayout]; +} + +@end diff --git a/redo/osxaltest/main.m b/redo/osxaltest/main.m index 0d899a90..6c94c08d 100644 --- a/redo/osxaltest/main.m +++ b/redo/osxaltest/main.m @@ -18,6 +18,7 @@ BOOL firstvert = YES; tButton *button; tSpinbox *spinbox; tEntry *entry; + tLabel *label; mainwin = [[tWindow alloc] init]; [mainwin tSetMargined:spaced]; @@ -69,6 +70,11 @@ BOOL firstvert = YES; [hbox tAddControl:entry stretchy:YES]; [box tAddControl:hbox stretchy:NO]; + hbox = [[tBox alloc] tInitVertical:!firstvert spaced:spaced]; + label = [[tLabel alloc] init]; + [hbox tAddControl:label stretchy:NO]; + [box tAddControl:hbox stretchy:NO]; + [mainwin tShow]; } diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index 6fb8f073..4f456f64 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -41,6 +41,9 @@ struct tAutoLayoutParams { @interface tEntry : NSObject @end +@interface tLabel : NSObject +@end + @interface tSpinbox : NSObject @end diff --git a/redo/osxaltest/window.m b/redo/osxaltest/window.m index 3769e405..89c9b763 100644 --- a/redo/osxaltest/window.m +++ b/redo/osxaltest/window.m @@ -55,7 +55,7 @@ { [self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; [self->w makeKeyAndOrderFront:self]; -// [[self->w contentView] tIsAmbiguous:0]; + [[self->w contentView] tIsAmbiguous:0]; } - (void)tRelayout