diff --git a/redo/osxaltest/box.swift b/redo/osxaltest/box.swift index 1f083324..5a6fd590 100644 --- a/redo/osxaltest/box.swift +++ b/redo/osxaltest/box.swift @@ -4,6 +4,8 @@ import Cocoa struct BoxControl { var c: Control var stretchy: Bool + var horzHuggingPri: NSLayoutPriority + var vertHuggingPri: NSLayoutPriority } class Box : NSView, Control { @@ -39,11 +41,15 @@ class Box : NSView, Control { func Add(control: Control, _ stretchy: Bool) { var c: BoxControl + var view = control.View() c = BoxControl( - c: control, - stretchy: stretchy) - self.addSubview(c.c.View()) + c: control, + stretchy: stretchy + horzHuggingPri: horzHuggingPri(view), + vertHuggingPri: vertHuggingPri(view)) + self.addSubview(view) self.controls.append(c) + // TODO set secondary hugging priority to low self.relayout() } diff --git a/redo/osxaltest/control.swift b/redo/osxaltest/control.swift index 8b2bb57f..a92fe300 100644 --- a/redo/osxaltest/control.swift +++ b/redo/osxaltest/control.swift @@ -6,6 +6,8 @@ protocol Control : class { func SetParent(p: Control) } +// TODO move to layout.swift + func mkconstraints(constraint: String, views: [String: NSView]) -> [AnyObject] { return NSLayoutConstraint.constraintsWithVisualFormat( constraint, @@ -13,3 +15,23 @@ func mkconstraints(constraint: String, views: [String: NSView]) -> [AnyObject] { metrics: nil, views: views) } + +func horzHuggingPri(view: NSView) -> NSLayoutPriority { + return view.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Horizontal) +} + +func vertHuggingPri(view: NSView) -> NSLayoutPriority { + return view.contentHuggingPriorityForOrientation(NSLayoutConstraintOrientation.Vertical) +} + +func setHuggingPri(view: NSView, priority: NSLayoutPriority, orientation: NSLayoutConstraintOrientation) { + view.setContentHuggingPriority(priority, forOrientation: orientation) +} + +func setHorzHuggingPri(view: NSView, priority: NSLayoutPriority) { + setHuggingPri(view, priority, NSLayoutConstraintOrientation.Horizontal) +} + +func setVertHuggingPri(view: NSView, priority: NSLayoutPriority) { + setHuggingPri(view, priority, NSLayoutConstraintOrientation.Vertical) +}