From 06257b19a5d2ab2e2581b8b152c31d7656e94735 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 3 Aug 2015 11:14:05 -0400 Subject: [PATCH] Added tEntry as a test of the tSpinbox bug. THAT works fine. --- redo/osxaltest/box.m | 1 + redo/osxaltest/entry.m | 58 ++++++++++++++++++++++++++++++++++++++ redo/osxaltest/main.m | 8 ++++++ redo/osxaltest/osxaltest.h | 3 ++ 4 files changed, 70 insertions(+) create mode 100644 redo/osxaltest/entry.m diff --git a/redo/osxaltest/box.m b/redo/osxaltest/box.m index 36536129..c1ceee9a 100644 --- a/redo/osxaltest/box.m +++ b/redo/osxaltest/box.m @@ -55,6 +55,7 @@ } // TODO spaced +// TODO custom minimum width for non-stretchy controls - (void)tFillAutoLayout:(tAutoLayoutParams *)p { NSMutableDictionary *views; diff --git a/redo/osxaltest/entry.m b/redo/osxaltest/entry.m new file mode 100644 index 00000000..01558b98 --- /dev/null +++ b/redo/osxaltest/entry.m @@ -0,0 +1,58 @@ +// 31 july 2015 +#import "osxaltest.h" + +@implementation tEntry { + NSTextField *t; + id parent; + NSLayoutPriority horzpri, vertpri; +} + +- (id)init +{ + self = [super init]; + if (self) { + self->t = [[NSTextField alloc] initWithFrame:NSZeroRect]; + [self->t setSelectable:YES]; + [self->t setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; + [self->t setBordered:NO]; + [self->t setBezelStyle:NSTextFieldSquareBezel]; + [self->t setBezeled:YES]; + [[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 5de82802..db7aa268 100644 --- a/redo/osxaltest/main.m +++ b/redo/osxaltest/main.m @@ -17,6 +17,7 @@ BOOL firstvert = YES; tBox *box, *hbox; tButton *button; tSpinbox *spinbox; + tEntry *entry; mainwin = [[tWindow alloc] init]; [mainwin tSetMargined:spaced]; @@ -61,6 +62,13 @@ BOOL firstvert = YES; [hbox tAddControl:spinbox stretchy:YES]; [box tAddControl:hbox stretchy:NO]; + hbox = [[tBox alloc] tInitVertical:!firstvert]; + entry = [[tEntry alloc] init]; + [hbox tAddControl:entry stretchy:NO]; + entry = [[tEntry alloc] init]; + [hbox tAddControl:entry stretchy:YES]; + [box tAddControl:hbox stretchy:NO]; + [mainwin tShow]; } diff --git a/redo/osxaltest/osxaltest.h b/redo/osxaltest/osxaltest.h index b9ccd511..19d01c20 100644 --- a/redo/osxaltest/osxaltest.h +++ b/redo/osxaltest/osxaltest.h @@ -36,6 +36,9 @@ struct tAutoLayoutParams { - (id)tInitWithText:(NSString *)text; @end +@interface tEntry : NSObject +@end + @interface tSpinbox : NSObject @end