More code conversion to Swift.
This commit is contained in:
parent
63df1b8e16
commit
e2605f5db9
|
@ -1,56 +0,0 @@
|
|||
// 31 july 2015
|
||||
#import "osxaltest.h"
|
||||
|
||||
@implementation tButton {
|
||||
NSButton *b;
|
||||
id<tControl> 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<tControl>)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
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
// 31 july 2015
|
||||
#import "osxaltest.h"
|
||||
|
||||
@implementation tEntry {
|
||||
NSTextField *t;
|
||||
id<tControl> 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<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;
|
||||
p->nonStretchyWidthPredicate = @"(==96)"; // TODO verify against Interface Builder
|
||||
}
|
||||
|
||||
- (void)tRelayout
|
||||
{
|
||||
if (self->parent != nil)
|
||||
[self->parent tRelayout];
|
||||
}
|
||||
|
||||
@end
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
// 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
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue