diff --git a/redo/osxaltest/button.m b/redo/osxaltest/button.m deleted file mode 100644 index 669e8bf5..00000000 --- a/redo/osxaltest/button.m +++ /dev/null @@ -1,56 +0,0 @@ -// 31 july 2015 -#import "osxaltest.h" - -@implementation tButton { - NSButton *b; - id parent; - NSLayoutPriority horzpri, vertpri; -} - -- (id)tInitWithText:(NSString *)text -{ - self = [super init]; - if (self) { - self->b = [[NSButton alloc] initWithFrame:NSZeroRect]; - [self->b setTitle:text]; - [self->b setButtonType:NSMomentaryPushInButton]; - [self->b setBordered:YES]; - [self->b setBezelStyle:NSRoundedBezelStyle]; - [self->b setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; - [self->b setTranslatesAutoresizingMaskIntoConstraints:NO]; - - self->parent = nil; - - self->horzpri = [self->b contentHuggingPriorityForOrientation:NSLayoutConstraintOrientationHorizontal]; - self->vertpri = [self->b contentHuggingPriorityForOrientation:NSLayoutConstraintOrientationVertical]; - } - return self; -} - -- (void)tSetParent:(id)p addToView:(NSView *)v relayout:(BOOL)relayout -{ - self->parent = p; - [v addSubview:self->b]; - if (relayout) - [self tRelayout]; -} - -- (void)tFillAutoLayout:(tAutoLayoutParams *)p -{ - // reset the hugging priority - [self->b setContentHuggingPriority:self->horzpri forOrientation:NSLayoutConstraintOrientationHorizontal]; - [self->b setContentHuggingPriority:self->vertpri forOrientation:NSLayoutConstraintOrientationVertical]; - p->view = self->b; - 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/button.swift b/redo/osxaltest/button.swift new file mode 100644 index 00000000..b3132493 --- /dev/null +++ b/redo/osxaltest/button.swift @@ -0,0 +1,46 @@ +// 31 july 2015 +import Cocoa + +class tButton : tControl { + private var b: NSButton + private var parent: tControl + private var horzpri, vertpri: NSLayoutPriority + + init(text: String) { + self.b = NSButton(NSZeroRect) + self.b.title = text + self.b.buttonType =NSMomentaryPushInButton + self.b bordered = true + self.b.bezelStyle = NSRoundedBezelStyle + self.b.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSRegularControlSize)) + self.b.translatesAutoresizingMaskIntoConstraints = false + + self.parent = nil + + self.horzpri = self.b.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientationHorizontal) + self.vertpri = self.b.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientationVertical) + } + + func tSetParent(p: tControl, v addToView: NSView) { + self.parent = p + v.addSubview(self.b) + } + + func tFillAutoLayout:(p: tAutoLayoutParams) { + // reset the hugging priority + self.b.setContentHuggingPriority(self.horzpri, orientation:NSLayoutConstraintOrientationHorizontal) + self.b.setContentHuggingPriority(self.vertpri, orientation:NSLayoutConstraintOrientationVertical) + + p.view = self.b + p.attachLeft = true + p.attachTop = true + p.attachRight = true + p.attachBottom = true + } + + func tRelayout() { + if self->parent != nil { + self.parent.tRelayout() + } + } +} diff --git a/redo/osxaltest/entry.m b/redo/osxaltest/entry.m deleted file mode 100644 index e32af5ed..00000000 --- a/redo/osxaltest/entry.m +++ /dev/null @@ -1,59 +0,0 @@ -// 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; - p->nonStretchyWidthPredicate = @"(==96)"; // TODO verify against Interface Builder -} - -- (void)tRelayout -{ - if (self->parent != nil) - [self->parent tRelayout]; -} - -@end diff --git a/redo/osxaltest/entry.swift b/redo/osxaltest/entry.swift new file mode 100644 index 00000000..64f9e11b --- /dev/null +++ b/redo/osxaltest/entry.swift @@ -0,0 +1,49 @@ +// 31 july 2015 +import Cocoa + +class tEntry : tControl { + private var b: NSButton + private var parent: tControl + private var horzpri, vertpri: NSLayoutPriority + + init() { + self.t = NSTextField(NSZeroRect) + self.t.selectable = true + self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSRegularControlSize)) + self.t.bordered = false + self.t.bezelStyle = NSTextFieldSquareBezel + self.t.bezeled = true + self.t.cell.lineBreakMode = NSLineBreakByClipping + self.t.cell.scrollable = true + self.t.translatesAutoresizingMaskIntoConstraints = false + + self.parent = nil + + self.horzpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientationHorizontal) + self.vertpri = self.t contentHuggingPriorityForOrientation(NSLayoutConstraintOrientationVertical) + } + + func tSetParent(p: tControl, v addToView: NSView) { + self.parent = p + v.addSubview(self.t) + } + + func tFillAutoLayout:(p: tAutoLayoutParams) { + // reset the hugging priority + self.t.setContentHuggingPriority(self.horzpri, orientation:NSLayoutConstraintOrientationHorizontal) + self.t.setContentHuggingPriority(self.vertpri, orientation:NSLayoutConstraintOrientationVertical) + + p.view = self.t + p.attachLeft = true + p.attachTop = true + p.attachRight = true + p.attachBottom = true + p.nonStretchyWidthPredicate = "(==96)" // TODO verify against Interface Builder + } + + func tRelayout() { + if self->parent != nil { + self.parent.tRelayout() + } + } +} diff --git a/redo/osxaltest/label.m b/redo/osxaltest/label.m deleted file mode 100644 index d715b04a..00000000 --- a/redo/osxaltest/label.m +++ /dev/null @@ -1,61 +0,0 @@ -// 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/label.swift b/redo/osxaltest/label.swift new file mode 100644 index 00000000..4518d579 --- /dev/null +++ b/redo/osxaltest/label.swift @@ -0,0 +1,51 @@ +// 31 july 2015 +import Cocoa + +class tEntry : tControl { + private var b: NSButton + private var parent: tControl + private var horzpri, vertpri: NSLayoutPriority + + init() { + self.t = NSTextField(NSZeroRect) + self.t.stringValue = "Label" + self.t.setEditable = false + self.t.selectable = false + self.t.drawsBackground = false + self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSRegularControlSize)) + self.t.bordered = false + self.t.bezelStyle = NSTextFieldSquareBezel + self.t.bezeled = false + self.t.cell.lineBreakMode = NSLineBreakByClipping + self.t.cell.scrollable = true + self.t.translatesAutoresizingMaskIntoConstraints = false + + self.parent = nil + + self.horzpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientationHorizontal) + self.vertpri = self.t contentHuggingPriorityForOrientation(NSLayoutConstraintOrientationVertical) + } + + func tSetParent(p: tControl, v addToView: NSView) { + self.parent = p + v.addSubview(self.t) + } + + func tFillAutoLayout:(p: tAutoLayoutParams) { + // reset the hugging priority + self.t.setContentHuggingPriority(self.horzpri, orientation:NSLayoutConstraintOrientationHorizontal) + self.t.setContentHuggingPriority(self.vertpri, orientation:NSLayoutConstraintOrientationVertical) + + p.view = self.t + p.attachLeft = true + p.attachTop = true + p.attachRight = true + p.attachBottom = true + } + + func tRelayout() { + if self->parent != nil { + self.parent.tRelayout() + } + } +}