Started migrating controls back.

This commit is contained in:
Pietro Gagliardi 2015-08-07 19:44:08 -04:00
parent 96e857dbee
commit a6b16d6473
7 changed files with 126 additions and 152 deletions

View File

@ -0,0 +1,36 @@
// 31 july 2015
import Cocoa
class Button : NSButton, Control {
private var parent: Control?
init(_ text: String) {
self.parent = nil
super.init(frame: NSZeroRect)
self.title = text
self.setButtonType(NSButtonType.MomentaryPushInButton)
self.bordered = true
self.bezelStyle = NSBezelStyle.RoundedBezelStyle
self.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
self.translatesAutoresizingMaskIntoConstraints = false
}
required init?(coder: NSCoder) {
fatalError("can't use this constructor, sorry")
}
func View() -> NSView {
return self
}
func SetParent(p: Control) {
self.parent = p
}
func Relayout() {
if self.parent != nil {
self.parent?.Relayout()
}
}
}

View File

@ -1,46 +0,0 @@
// 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(frame: NSZeroRect)
self.b.title = text
self.b.setButtonType(NSButtonType.MomentaryPushInButton)
self.b.bordered = true
self.b.bezelStyle = NSBezelStyle.RoundedBezelStyle
self.b.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
self.b.translatesAutoresizingMaskIntoConstraints = false
self.parent = nil
self.horzpri = self.b.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Horizontal)
self.vertpri = self.b.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Vertical)
}
func tSetParent(p: tControl, addToView v: NSView) {
self.parent = p
v.addSubview(self.b)
}
func tFillAutoLayout(inout p: tAutoLayoutParams) {
// reset the hugging priority
self.b.setContentHuggingPriority(self.horzpri, forOrientation:NSLayoutConstraintOrientation.Horizontal)
self.b.setContentHuggingPriority(self.vertpri, forOrientation:NSLayoutConstraintOrientation.Vertical)
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()
}
}
}

View File

@ -0,0 +1,43 @@
// 31 july 2015
import Cocoa
class Entry : NSTextField, Control {
private var parent: Control?
init() {
var cell: NSTextFieldCell
self.parent = nil
super.init(frame: NSZeroRect)
self.selectable = true
self.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
self.bordered = false
self.bezelStyle = NSTextFieldBezelStyle.SquareBezel
self.bezeled = true
cell = self.cell() as! NSTextFieldCell
cell.lineBreakMode = NSLineBreakMode.ByClipping
cell.scrollable = true
self.translatesAutoresizingMaskIntoConstraints = false
}
required init?(coder: NSCoder) {
fatalError("can't use this constructor, sorry")
}
func View() -> NSView {
return self
}
func SetParent(p: Control) {
self.parent = p
}
func Relayout() {
if self.parent != nil {
self.parent?.Relayout()
}
}
}
//TODO p.nonStretchyWidthPredicate = "(==96)" // TODO verify against Interface Builder

View File

@ -1,52 +0,0 @@
// 31 july 2015
import Cocoa
class tEntry : tControl {
private var t: NSTextField
private var parent: tControl?
private var horzpri, vertpri: NSLayoutPriority
init() {
var cell: NSTextFieldCell
self.t = NSTextField(frame: NSZeroRect)
self.t.selectable = true
self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
self.t.bordered = false
self.t.bezelStyle = NSTextFieldBezelStyle.SquareBezel
self.t.bezeled = true
cell = self.t.cell() as! NSTextFieldCell
cell.lineBreakMode = NSLineBreakMode.ByClipping
cell.scrollable = true
self.t.translatesAutoresizingMaskIntoConstraints = false
self.parent = nil
self.horzpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Horizontal)
self.vertpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Vertical)
}
func tSetParent(p: tControl, addToView v: NSView) {
self.parent = p
v.addSubview(self.t)
}
func tFillAutoLayout(inout p: tAutoLayoutParams) {
// reset the hugging priority
self.t.setContentHuggingPriority(self.horzpri, forOrientation:NSLayoutConstraintOrientation.Horizontal)
self.t.setContentHuggingPriority(self.vertpri, forOrientation:NSLayoutConstraintOrientation.Vertical)
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()
}
}
}

View File

@ -0,0 +1,44 @@
// 31 july 2015
import Cocoa
class Label : NSTextField, Control {
private var parent: Control?
init() {
var cell: NSTextFieldCell
self.parent = nil
super.init(frame: NSZeroRect)
self.stringValue = "Label"
self.editable = false
self.selectable = false
self.drawsBackground = false
self.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
self.bordered = false
self.bezelStyle = NSTextFieldBezelStyle.SquareBezel
self.bezeled = false
cell = self.cell() as! NSTextFieldCell
cell.lineBreakMode = NSLineBreakMode.ByClipping
cell.scrollable = true
self.translatesAutoresizingMaskIntoConstraints = false
}
required init?(coder: NSCoder) {
fatalError("can't use this constructor, sorry")
}
func View() -> NSView {
return self
}
func SetParent(p: Control) {
self.parent = p
}
func Relayout() {
if self.parent != nil {
self.parent?.Relayout()
}
}
}

View File

@ -1,54 +0,0 @@
// 31 july 2015
import Cocoa
class tLabel : tControl {
private var t: NSTextField
private var parent: tControl?
private var horzpri, vertpri: NSLayoutPriority
init() {
var cell: NSTextFieldCell
self.t = NSTextField(frame: NSZeroRect)
self.t.stringValue = "Label"
self.t.editable = false
self.t.selectable = false
self.t.drawsBackground = false
self.t.font = NSFont.systemFontOfSize(NSFont.systemFontSizeForControlSize(NSControlSize.RegularControlSize))
self.t.bordered = false
self.t.bezelStyle = NSTextFieldBezelStyle.SquareBezel
self.t.bezeled = false
cell = self.t.cell() as! NSTextFieldCell
cell.lineBreakMode = NSLineBreakMode.ByClipping
cell.scrollable = true
self.t.translatesAutoresizingMaskIntoConstraints = false
self.parent = nil
self.horzpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Horizontal)
self.vertpri = self.t.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Vertical)
}
func tSetParent(p: tControl, addToView v: NSView) {
self.parent = p
v.addSubview(self.t)
}
func tFillAutoLayout(inout p: tAutoLayoutParams) {
// reset the hugging priority
self.t.setContentHuggingPriority(self.horzpri, forOrientation:NSLayoutConstraintOrientation.Horizontal)
self.t.setContentHuggingPriority(self.vertpri, forOrientation:NSLayoutConstraintOrientation.Vertical)
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()
}
}
}

View File

@ -13,6 +13,9 @@ func appLaunched() {
var mainwin = Window()
mainwin.SetMargined(spaced)
var control = Label()
mainwin.SetControl(control)
mainwin.Show()
keepAliveMainwin = mainwin