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

View File

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