Implemented stretchiness.

This commit is contained in:
Pietro Gagliardi 2015-08-08 21:31:15 -04:00
parent 15eadff66b
commit 48e1ccdb10
2 changed files with 22 additions and 2 deletions

View File

@ -55,8 +55,18 @@ class Box : NSView, Control {
vertHuggingPri: vertHuggingPri(view)) vertHuggingPri: vertHuggingPri(view))
self.addSubview(view) self.addSubview(view)
self.controls.append(c) 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 // make sure controls don't hug their secondary direction so they fill the width of the view
setHuggingPri(view, myNSLayoutPriorityDefaultLow, self.secondaryOrientation) setHuggingPri(view, myNSLayoutPriorityDefaultLow, self.secondaryOrientation)
self.relayout() self.relayout()
} }

View File

@ -32,6 +32,16 @@ class Entry : NSTextField, Control {
func SetParent(p: Control) { func SetParent(p: Control) {
self.parent = p 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
}
}
}