Wrote some preparation for stretchiness.
This commit is contained in:
parent
240dc25d74
commit
b2f5254fe2
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue