From 240dc25d74c107de65cc4c568eeaa5e67bc6da06 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 8 Aug 2015 11:12:55 -0400 Subject: [PATCH] More Box work. --- redo/osxaltest/box.swift | 29 ++++++++++++++++++++++++----- redo/osxaltest/main.swift | 7 +++++-- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/redo/osxaltest/box.swift b/redo/osxaltest/box.swift index 19945802..1f083324 100644 --- a/redo/osxaltest/box.swift +++ b/redo/osxaltest/box.swift @@ -36,11 +36,12 @@ class Box : NSView, Control { fatalError("can't use this constructor, sorry") } - func Add(control: Control, stretchy: Stretchy) { - var c BoxControl + func Add(control: Control, _ stretchy: Bool) { + var c: BoxControl - c.c = control - c.stretchy = stretchy + c = BoxControl( + c: control, + stretchy: stretchy) self.addSubview(c.c.View()) self.controls.append(c) self.relayout() @@ -57,7 +58,9 @@ class Box : NSView, Control { // TODO stretchiness // - we will need a trailing view if there are no stretchy controls private func relayout() { - if self.children.count == 0 { + var constraint: String + + if self.controls.count == 0 { return } @@ -68,12 +71,28 @@ class Box : NSView, Control { var n = 0 for c in self.controls { views["view\(n)"] = c.c.View() + n++ } // next, assemble the views in the primary direction // they all go in a straight line + constraint = "\(self.primaryDirPrefix)|" + for i in 0..