Fixed some more runtime errors. I have no idea how this code even worked anymore.

This commit is contained in:
Pietro Gagliardi 2015-08-07 16:24:15 -04:00
parent 9aeeeab812
commit ad895a7f7e
5 changed files with 24 additions and 45 deletions

View File

@ -7,7 +7,6 @@ import Cocoa
class tBoxContainer : NSView {
override var alignmentRectInsets: NSEdgeInsets {
get {
print("in tBoxContainer.alignmentRectInsets")
return NSEdgeInsetsMake(50, 50, 50, 50)
}
}
@ -61,7 +60,7 @@ class tBox : tControl {
// TODO make the other dimension not hug (as an experiment)
func tFillAutoLayout(inout p: tAutoLayoutParams) {
var hasStretchy = false
if self.children.count == 0 {
if self.children.count != 0 {
hasStretchy = self.actualLayoutWork()
}
p.view = self.v
@ -117,9 +116,9 @@ class tBox : tControl {
}
// first string the views together
var constraint = "H:"
var constraint = "H:|"
if self.vertical {
constraint = "V:"
constraint = "V:|"
}
var firstStretchy = true
// swift can't tell that nStretchy isn't used until firstStretchy becomes false
@ -129,7 +128,7 @@ class tBox : tControl {
constraint += "-"
}
constraint += "[" + tAutoLayoutKey(i)
// swift currently can't do self.children[i].stretchy
// TODO swift currently can't do self.children[i].stretchy
var child = self.children[Int(i)]
if child.stretchy {
if firstStretchy {
@ -144,11 +143,7 @@ class tBox : tControl {
constraint += "]"
}
constraint += "|"
self.v.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
constraint,
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views))
self.v.addConstraints(mkconstraints(constraint, views))
// TODO do not release constraint; it's autoreleased?
// next make the views span the full other dimension
@ -159,11 +154,7 @@ class tBox : tControl {
constraint = "H:|["
}
constraint += tAutoLayoutKey(i) + "]|"
self.v.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(
constraint,
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views))
self.v.addConstraints(mkconstraints(constraint, views))
// TODO do not release constraint; it's autoreleased?
}

View File

@ -22,3 +22,12 @@ protocol tControl : class {
func tAutoLayoutKey(n: UIntMax) -> String {
return NSString(format: "view%d", n) as String
}
func mkconstraints(constraint: String, views: [String: NSView]) -> [AnyObject] {
println("making constraint \(constraint)")
return NSLayoutConstraint.constraintsWithVisualFormat(
constraint,
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views)
}

View File

@ -2,7 +2,7 @@
import Cocoa
var spaced = false
var firstvert = false
var firstvert = true
func appLaunched() {
var hbox: tBox
@ -57,9 +57,9 @@ func appLaunched() {
hbox = tBox(vertical: !firstvert, spaced: spaced)
entry = tEntry()
hbox.tAddControl(entry, stretchy: false)
entry = tEntry()
hbox.tAddControl(entry, stretchy: true)
entry = tEntry()
hbox.tAddControl(entry, stretchy: false)
box.tAddControl(hbox, stretchy: false)
hbox = tBox(vertical: !firstvert, spaced: spaced)

View File

@ -5,7 +5,6 @@ import Cocoa
class tSpinboxContainer : NSView {
override var alignmentRectInsets: NSEdgeInsets {
get {
print("in tSpinboxContainer.alignmentRectInsets")
return NSEdgeInsetsMake(50, 50, 50, 50)
}
}
@ -51,23 +50,11 @@ nspinbox++
"t": self.t,
"s": self.s,
]
var constraints = NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[t]-[s]|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views)
var constraints = mkconstraints("H:|[t]-[s]|", views)
self.c.addConstraints(constraints)
constraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[t]|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views)
constraints = mkconstraints("V:|[t]|", views)
self.c.addConstraints(constraints)
constraints = NSLayoutConstraint.constraintsWithVisualFormat(
"V:|[s]|",
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views)
constraints = mkconstraints("V:|[s]|", views)
self.c.addConstraints(constraints)
self.parent = nil

View File

@ -4,7 +4,7 @@ import Cocoa
// auto layout helpers
func tIsAmbiguous(view: NSView, indent: Int) {
var s = String(count: indent, repeatedValue: " " as Character)
print("\(s) \(view.className) \(view.hasAmbiguousLayout)")
println("\(s) \(view.className) \(view.hasAmbiguousLayout)")
if view.hasAmbiguousLayout {
view.window?.visualizeConstraints(view.superview!.constraints)
}
@ -85,11 +85,7 @@ class tWindow : tControl {
if p.attachRight {
constraint += margin + "|"
}
var constraints = NSLayoutConstraint.constraintsWithVisualFormat(
constraint,
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views)
var constraints = mkconstraints(constraint, views)
contentView.addConstraints(constraints)
constraint = "V:"
@ -100,11 +96,7 @@ class tWindow : tControl {
if p.attachBottom {
constraint += margin + "|"
}
constraints = NSLayoutConstraint.constraintsWithVisualFormat(
constraint,
options: NSLayoutFormatOptions(0),
metrics: nil,
views: views)
constraints = mkconstraints(constraint, views)
contentView.addConstraints(constraints)
}
}