Implemented multiple stretchy controls.

This commit is contained in:
Pietro Gagliardi 2015-08-08 21:38:21 -04:00
parent 48e1ccdb10
commit 64dedfe540
2 changed files with 11 additions and 2 deletions

View File

@ -92,8 +92,12 @@ class Box : NSView, Control {
// first collect the views
var views = [String: NSView]()
var n = 0
var firstStretchy = -1
for c in self.controls {
views["view\(n)"] = c.c.View()
if firstStretchy == -1 && c.stretchy {
firstStretchy = n
}
n++
}
@ -104,7 +108,12 @@ class Box : NSView, Control {
if self.padded && i != 0 {
constraint += "-"
}
constraint += "[view\(i)]"
constraint += "[view\(i)"
// implement multiple stretchiness properly
if self.controls[i].stretchy && i != firstStretchy {
constraint += "(==view\(firstStretchy))"
}
constraint += "]"
}
constraint += "|"
var constraints = mkconstraints(constraint, views)

View File

@ -16,7 +16,7 @@ func appLaunched() {
var box = Box(vertical: firstvert, padded: spaced)
mainwin.SetControl(box)
box.Add(Entry(), false)
box.Add(Entry(), true)
box.Add(Button("Button"), true)
mainwin.Show()