Added labels to make sure those don't need minimum width constraints. They don't.

This commit is contained in:
Pietro Gagliardi 2015-08-03 13:35:36 -04:00
parent 1cdc7d3eb3
commit f185ca71c6
4 changed files with 71 additions and 1 deletions

61
redo/osxaltest/label.m Normal file
View File

@ -0,0 +1,61 @@
// 31 july 2015
#import "osxaltest.h"
@implementation tLabel {
NSTextField *t;
id<tControl> 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<tControl>)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

View File

@ -18,6 +18,7 @@ BOOL firstvert = YES;
tButton *button; tButton *button;
tSpinbox *spinbox; tSpinbox *spinbox;
tEntry *entry; tEntry *entry;
tLabel *label;
mainwin = [[tWindow alloc] init]; mainwin = [[tWindow alloc] init];
[mainwin tSetMargined:spaced]; [mainwin tSetMargined:spaced];
@ -69,6 +70,11 @@ BOOL firstvert = YES;
[hbox tAddControl:entry stretchy:YES]; [hbox tAddControl:entry stretchy:YES];
[box tAddControl:hbox stretchy:NO]; [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]; [mainwin tShow];
} }

View File

@ -41,6 +41,9 @@ struct tAutoLayoutParams {
@interface tEntry : NSObject<tControl> @interface tEntry : NSObject<tControl>
@end @end
@interface tLabel : NSObject<tControl>
@end
@interface tSpinbox : NSObject<tControl> @interface tSpinbox : NSObject<tControl>
@end @end

View File

@ -55,7 +55,7 @@
{ {
[self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)]; [self->w cascadeTopLeftFromPoint:NSMakePoint(20, 20)];
[self->w makeKeyAndOrderFront:self]; [self->w makeKeyAndOrderFront:self];
// [[self->w contentView] tIsAmbiguous:0]; [[self->w contentView] tIsAmbiguous:0];
} }
- (void)tRelayout - (void)tRelayout