Experimented with manually specifying control sizes for nonstretchy controls in Box. This resolves ambiguities!
This commit is contained in:
parent
819d778b46
commit
372cfd048d
|
@ -90,6 +90,8 @@ class Box : NSView, Control {
|
||||||
self.parent = p
|
self.parent = p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO do we still need to set hugging?
|
||||||
|
// TODO try unsetting spinbox intrinsics and seeing what happens
|
||||||
private func relayout() {
|
private func relayout() {
|
||||||
var constraint: String
|
var constraint: String
|
||||||
|
|
||||||
|
@ -103,8 +105,12 @@ class Box : NSView, Control {
|
||||||
var views = [String: NSView]()
|
var views = [String: NSView]()
|
||||||
var n = 0
|
var n = 0
|
||||||
var firstStretchy = -1
|
var firstStretchy = -1
|
||||||
|
var metrics = [String: CGFloat]()
|
||||||
for c in self.controls {
|
for c in self.controls {
|
||||||
views["view\(n)"] = c.c.View()
|
views["view\(n)"] = c.c.View()
|
||||||
|
var s = fittingAlignmentSize(c.c.View())
|
||||||
|
metrics["view\(n)width"] = s.width
|
||||||
|
metrics["view\(n)height"] = s.height
|
||||||
if firstStretchy == -1 && c.stretchy {
|
if firstStretchy == -1 && c.stretchy {
|
||||||
firstStretchy = n
|
firstStretchy = n
|
||||||
}
|
}
|
||||||
|
@ -136,13 +142,21 @@ class Box : NSView, Control {
|
||||||
if self.controls[i].stretchy && i != firstStretchy {
|
if self.controls[i].stretchy && i != firstStretchy {
|
||||||
constraint += "(==view\(firstStretchy))"
|
constraint += "(==view\(firstStretchy))"
|
||||||
}
|
}
|
||||||
|
// if the control is not stretchy, restrict it to the fitting size
|
||||||
|
if !self.controls[i].stretchy {
|
||||||
|
if self.vertical {
|
||||||
|
constraint += "(==view\(i)height)"
|
||||||
|
} else {
|
||||||
|
constraint += "(==view\(i)width)"
|
||||||
|
}
|
||||||
|
}
|
||||||
constraint += "]"
|
constraint += "]"
|
||||||
}
|
}
|
||||||
if firstStretchy == -1 { // don't space between the last control and the no-stretchy view
|
if firstStretchy == -1 { // don't space between the last control and the no-stretchy view
|
||||||
constraint += "[noStretchyView]"
|
constraint += "[noStretchyView]"
|
||||||
}
|
}
|
||||||
constraint += "|"
|
constraint += "|"
|
||||||
var constraints = mkconstraints(constraint, nil, views)
|
var constraints = mkconstraints(constraint, metrics, views)
|
||||||
self.addConstraints(constraints)
|
self.addConstraints(constraints)
|
||||||
|
|
||||||
// next: assemble the views in the secondary direction
|
// next: assemble the views in the secondary direction
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// 8 august 2015
|
// 8 august 2015
|
||||||
import Cocoa
|
import Cocoa
|
||||||
|
|
||||||
func mkconstraints(constraint: String, metrics: [String: Double]?, views: [String: NSView]) -> [AnyObject] {
|
func mkconstraints(constraint: String, metrics: [String: CGFloat]?, views: [String: NSView]) -> [AnyObject] {
|
||||||
return NSLayoutConstraint.constraintsWithVisualFormat(
|
return NSLayoutConstraint.constraintsWithVisualFormat(
|
||||||
constraint,
|
constraint,
|
||||||
options: NSLayoutFormatOptions(0),
|
options: NSLayoutFormatOptions(0),
|
||||||
|
|
Loading…
Reference in New Issue