From 48e1ccdb1088e448206089c44317e82c79e2f81a Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sat, 8 Aug 2015 21:31:15 -0400 Subject: [PATCH] Implemented stretchiness. --- redo/osxaltest/box.swift | 10 ++++++++++ redo/osxaltest/entry.swift | 14 ++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/redo/osxaltest/box.swift b/redo/osxaltest/box.swift index f39b511b..af7c3857 100644 --- a/redo/osxaltest/box.swift +++ b/redo/osxaltest/box.swift @@ -55,8 +55,18 @@ class Box : NSView, Control { vertHuggingPri: vertHuggingPri(view)) self.addSubview(view) self.controls.append(c) + + // if a control is stretchy, it should not hug in the primary direction + // otherwise, it should *forcibly* hug + if c.stretchy { + setHuggingPri(view, myNSLayoutPriorityDefaultLow, self.primaryOrientation) + } else { + setHuggingPri(view, myNSLayoutPriorityRequired, self.primaryOrientation) + } + // make sure controls don't hug their secondary direction so they fill the width of the view setHuggingPri(view, myNSLayoutPriorityDefaultLow, self.secondaryOrientation) + self.relayout() } diff --git a/redo/osxaltest/entry.swift b/redo/osxaltest/entry.swift index df8a7ec2..c4980fb6 100644 --- a/redo/osxaltest/entry.swift +++ b/redo/osxaltest/entry.swift @@ -32,6 +32,16 @@ class Entry : NSTextField, Control { func SetParent(p: Control) { self.parent = p } -} -//TODO p.nonStretchyWidthPredicate = "(==96)" // TODO verify against Interface Builder + // by default a text entry has no intrinsic content width + // in order for our layout containers to work, we need to give it one + // give it what Interface Builder uses as a default + // TODO verify against Interface Builder + override var intrinsicContentSize: NSSize { + get { + var s = super.intrinsicContentSize + s.width = 96 + return s + } + } +}