|
@@ -21,6 +21,8 @@ class KMConvertSettingLimitTipView: NSView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ var itemClick: KMCommonClickBlock?
|
|
|
+
|
|
|
override init(frame frameRect: NSRect) {
|
|
|
super.init(frame: frameRect)
|
|
|
|
|
@@ -46,6 +48,8 @@ class KMConvertSettingLimitTipView: NSView {
|
|
|
self._funcBox.contentView = self._funcButtonVC!.view
|
|
|
self._funcButtonVC?.stringValue = NSLocalizedString("Unlock", comment: "")
|
|
|
self._funcButtonVC?.button(type: .Text, size: .m)
|
|
|
+ self._funcButtonVC?.target = self
|
|
|
+ self._funcButtonVC?.action = #selector(funcAction)
|
|
|
|
|
|
let _ = self.contentView.km_add_leading_constraint(attribute: .leading, constant: 0)
|
|
|
let _ = self.contentView.km_add_trailing_constraint(attribute: .trailing, constant: 0)
|
|
@@ -62,6 +66,8 @@ class KMConvertSettingLimitTipView: NSView {
|
|
|
let _ = self._funcBox.km_add_centerY_constraint(equalTo: self._iconIv, attribute: .centerY, constant: 0)
|
|
|
let _ = self._funcBox.km_add_width_constraint(attribute: .width, constant: 60)
|
|
|
let _ = self._funcBox.km_add_height_constraint(attribute: .height, constant: 30)
|
|
|
+
|
|
|
+// self._funcBox.km_add_centerY_constraint(attribute: .left, constant: 0)
|
|
|
}
|
|
|
|
|
|
func initDefaultValue() {
|
|
@@ -76,41 +82,65 @@ class KMConvertSettingLimitTipView: NSView {
|
|
|
self._funcBox.borderWidth = 0.0
|
|
|
}
|
|
|
|
|
|
+ @objc private func funcAction() {
|
|
|
+ guard let callback = self.itemClick else {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ callback(1)
|
|
|
+ }
|
|
|
}
|
|
|
extension NSView {
|
|
|
- public func km_add_leading_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_leading_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_leading_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_trailing_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_trailing_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_trailing_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_left_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_left_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_left_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_right_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_right_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_right_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_top_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_top_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_top_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_bottom_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_bottom_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_bottom_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
@@ -134,21 +164,35 @@ extension NSView {
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_centerX_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_centerX_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_centerX_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_add_centerY_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_add_centerY_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
let constraint = self.km_centerY_constraint(equalTo: targetV, attribute: a, constant: c)
|
|
|
- self.superview?.addConstraint(constraint)
|
|
|
+ if let _constraint = constraint {
|
|
|
+ self.superview?.addConstraint(_constraint)
|
|
|
+ }
|
|
|
+
|
|
|
return constraint
|
|
|
}
|
|
|
|
|
|
// MARK: - NSLayoutXAxisAnchor
|
|
|
|
|
|
- public func km_leading_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_leading_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_x_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutXAxisAnchor. eg leading | trailing | left | right | centerX.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var _targetV: NSView?
|
|
@@ -159,11 +203,7 @@ extension NSView {
|
|
|
}
|
|
|
|
|
|
var constraint: NSLayoutConstraint?
|
|
|
- if (a == .top) {
|
|
|
-// constraint = self.leadingAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
- } else if (a == .bottom) {
|
|
|
-// constraint = self.leadingAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
+ if (a == .leading) {
|
|
|
constraint = self.leadingAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
} else if (a == .trailing) {
|
|
|
constraint = self.leadingAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
@@ -171,19 +211,21 @@ extension NSView {
|
|
|
constraint = self.leadingAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
} else if (a == .right) {
|
|
|
constraint = self.leadingAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.leadingAnchor.constraint(equalTo: _targetV!.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.leadingAnchor.constraint(equalTo: _targetV!.heightAnchor, constant: c)
|
|
|
} else if (a == .centerX) {
|
|
|
constraint = self.leadingAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
- } else if (a == .centerY) {
|
|
|
-// constraint = self.leadingAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
}
|
|
|
return constraint!
|
|
|
}
|
|
|
|
|
|
- public func km_trailing_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_trailing_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_x_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutXAxisAnchor. eg leading | trailing | left | right | centerX.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var _targetV: NSView?
|
|
@@ -194,11 +236,7 @@ extension NSView {
|
|
|
}
|
|
|
|
|
|
var constraint: NSLayoutConstraint?
|
|
|
- if (a == .top) {
|
|
|
-// constraint = self.trailingAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
- } else if (a == .bottom) {
|
|
|
-// constraint = self.trailingAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
+ if (a == .leading) {
|
|
|
constraint = self.trailingAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
} else if (a == .trailing) {
|
|
|
constraint = self.trailingAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
@@ -206,19 +244,22 @@ extension NSView {
|
|
|
constraint = self.trailingAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
} else if (a == .right) {
|
|
|
constraint = self.trailingAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.trailingAnchor.constraint(equalTo: _targetV!.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.trailingAnchor.constraint(equalTo: _targetV!.heightAnchor, constant: c)
|
|
|
} else if (a == .centerX) {
|
|
|
constraint = self.trailingAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
- } else if (a == .centerY) {
|
|
|
-// constraint = self.trailingAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
}
|
|
|
- return constraint!
|
|
|
+
|
|
|
+ return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_left_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_left_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_x_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutXAxisAnchor. eg leading | trailing | left | right | centerX.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var _targetV: NSView?
|
|
@@ -229,11 +270,7 @@ extension NSView {
|
|
|
}
|
|
|
|
|
|
var constraint: NSLayoutConstraint?
|
|
|
- if (a == .top) {
|
|
|
-// constraint = self.leftAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
- } else if (a == .bottom) {
|
|
|
-// constraint = self.leftAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
+ if (a == .leading) {
|
|
|
constraint = self.leftAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
} else if (a == .trailing) {
|
|
|
constraint = self.leftAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
@@ -241,19 +278,22 @@ extension NSView {
|
|
|
constraint = self.leftAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
} else if (a == .right) {
|
|
|
constraint = self.leftAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.leftAnchor.constraint(equalTo: _targetV!.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.leftAnchor.constraint(equalTo: _targetV!.heightAnchor, constant: c)
|
|
|
} else if (a == .centerX) {
|
|
|
constraint = self.leftAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
- } else if (a == .centerY) {
|
|
|
-// constraint = self.leftAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
}
|
|
|
- return constraint!
|
|
|
+
|
|
|
+ return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_right_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_right_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_x_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutXAxisAnchor. eg leading | trailing | left | right | centerX.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var _targetV: NSView?
|
|
@@ -264,11 +304,7 @@ extension NSView {
|
|
|
}
|
|
|
|
|
|
var constraint: NSLayoutConstraint?
|
|
|
- if (a == .top) {
|
|
|
-// constraint = self.rightAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
- } else if (a == .bottom) {
|
|
|
-// constraint = self.rightAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
+ if (a == .leading) {
|
|
|
constraint = self.rightAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
} else if (a == .trailing) {
|
|
|
constraint = self.rightAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
@@ -276,19 +312,57 @@ extension NSView {
|
|
|
constraint = self.rightAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
} else if (a == .right) {
|
|
|
constraint = self.rightAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.rightAnchor.constraint(equalTo: _targetV!.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.rightAnchor.constraint(equalTo: _targetV!.heightAnchor, constant: c)
|
|
|
} else if (a == .centerX) {
|
|
|
constraint = self.rightAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
- } else if (a == .centerY) {
|
|
|
-// constraint = self.rightAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
}
|
|
|
- return constraint!
|
|
|
+
|
|
|
+ return constraint
|
|
|
+ }
|
|
|
+
|
|
|
+ public func km_centerX_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_x_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutXAxisAnchor. eg leading | trailing | left | right | centerX.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ self._km_layout_setup()
|
|
|
+
|
|
|
+ var constraint: NSLayoutConstraint?
|
|
|
+ var _targetV: NSView?
|
|
|
+ if let _ = targetV {
|
|
|
+ _targetV = targetV
|
|
|
+ } else {
|
|
|
+ _targetV = self.superview
|
|
|
+ }
|
|
|
+
|
|
|
+ if (a == .leading) {
|
|
|
+ constraint = self.centerXAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
+ } else if (a == .trailing) {
|
|
|
+ constraint = self.centerXAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
|
+ } else if (a == .left) {
|
|
|
+ constraint = self.centerXAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
+ } else if (a == .right) {
|
|
|
+ constraint = self.centerXAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
+ } else if (a == .centerX) {
|
|
|
+ constraint = self.centerXAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
+ }
|
|
|
+ return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_top_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ // MARK: - NSLayoutYAxisAnchor
|
|
|
+
|
|
|
+ public func km_top_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_y_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutYAxisAnchor. eg top | bottom | centerY.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var _targetV: NSView?
|
|
@@ -303,27 +377,21 @@ extension NSView {
|
|
|
constraint = self.topAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
} else if (a == .bottom) {
|
|
|
constraint = self.topAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
- } else if (a == .trailing) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
|
- } else if (a == .left) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
- } else if (a == .right) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.heightAnchor, constant: c)
|
|
|
- } else if (a == .centerX) {
|
|
|
-// constraint = self.topAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
} else if (a == .centerY) {
|
|
|
constraint = self.topAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
}
|
|
|
- return constraint!
|
|
|
+ return constraint
|
|
|
}
|
|
|
|
|
|
- public func km_bottom_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
+ public func km_bottom_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_y_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutYAxisAnchor. eg top | bottom | centerY.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var _targetV: NSView?
|
|
@@ -338,32 +406,49 @@ extension NSView {
|
|
|
constraint = self.bottomAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
} else if (a == .bottom) {
|
|
|
constraint = self.bottomAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
- } else if (a == .trailing) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
|
- } else if (a == .left) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
- } else if (a == .right) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.heightAnchor, constant: c)
|
|
|
- } else if (a == .centerX) {
|
|
|
-// constraint = self.bottomAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
} else if (a == .centerY) {
|
|
|
constraint = self.bottomAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
}
|
|
|
- return constraint!
|
|
|
+ return constraint
|
|
|
}
|
|
|
|
|
|
+ public func km_centerY_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint? {
|
|
|
+ if (!self._km_layout_is_y_anchor(attribute: a)) {
|
|
|
+ Swift.debugPrint(a)
|
|
|
+ #if DEBUG
|
|
|
+ assert(false, "need NSLayoutYAxisAnchor. eg top | bottom | centerY.")
|
|
|
+ #endif
|
|
|
+ return nil
|
|
|
+ }
|
|
|
+
|
|
|
+ self._km_layout_setup()
|
|
|
+
|
|
|
+ var constraint: NSLayoutConstraint?
|
|
|
+ var _targetV: NSView?
|
|
|
+ if let _ = targetV {
|
|
|
+ _targetV = targetV
|
|
|
+ } else {
|
|
|
+ _targetV = self.superview
|
|
|
+ }
|
|
|
+
|
|
|
+ if (a == .top) {
|
|
|
+ constraint = self.centerYAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
+ } else if (a == .bottom) {
|
|
|
+ constraint = self.centerYAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
+ } else if (a == .centerY) {
|
|
|
+ constraint = self.centerYAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
+ }
|
|
|
+ return constraint
|
|
|
+ }
|
|
|
+
|
|
|
+ // MARK: - NSLayoutDimension
|
|
|
+
|
|
|
public func km_width_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
self._km_layout_setup()
|
|
|
|
|
|
var constraint: NSLayoutConstraint?
|
|
|
if (a == .top) {
|
|
|
-// constraint = self.widthAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
+// constraint = self.widthAnchor.constraint(equalTo: targetV!.topAnchor, constant: c)
|
|
|
} else if (a == .bottom) {
|
|
|
// constraint = self.widthAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
} else if (a == .leading) {
|
|
@@ -430,79 +515,30 @@ extension NSView {
|
|
|
return constraint!
|
|
|
}
|
|
|
|
|
|
- public func km_centerX_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
- self._km_layout_setup()
|
|
|
-
|
|
|
- var constraint: NSLayoutConstraint?
|
|
|
- var _targetV: NSView?
|
|
|
- if let _ = targetV {
|
|
|
- _targetV = targetV
|
|
|
- } else {
|
|
|
- _targetV = self.superview
|
|
|
- }
|
|
|
-
|
|
|
- if (a == .top) {
|
|
|
-// constraint = self.centerXAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
- } else if (a == .bottom) {
|
|
|
-// constraint = self.centerXAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
- constraint = self.centerXAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
- } else if (a == .trailing) {
|
|
|
- constraint = self.centerXAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
|
- } else if (a == .left) {
|
|
|
- constraint = self.centerXAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
- } else if (a == .right) {
|
|
|
- constraint = self.centerXAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.centerXAnchor.constraint(equalTo: _targetV.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.centerXAnchor.constraint(equalTo: _targetV.heightAnchor, constant: c)
|
|
|
- } else if (a == .centerX) {
|
|
|
- constraint = self.centerXAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
- } else if (a == .centerY) {
|
|
|
-// constraint = self.centerXAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
- }
|
|
|
- return constraint!
|
|
|
+ // MARK: - Private Methods
|
|
|
+
|
|
|
+ private func _km_layout_setup() {
|
|
|
+ self.translatesAutoresizingMaskIntoConstraints = false
|
|
|
}
|
|
|
|
|
|
- public func km_centerY_constraint(equalTo targetV: NSView? = nil, attribute a: NSLayoutConstraint.Attribute, constant c: CGFloat) -> NSLayoutConstraint {
|
|
|
- self._km_layout_setup()
|
|
|
-
|
|
|
- var constraint: NSLayoutConstraint?
|
|
|
- var _targetV: NSView?
|
|
|
- if let _ = targetV {
|
|
|
- _targetV = targetV
|
|
|
- } else {
|
|
|
- _targetV = self.superview
|
|
|
- }
|
|
|
-
|
|
|
- if (a == .top) {
|
|
|
- constraint = self.centerYAnchor.constraint(equalTo: _targetV!.topAnchor, constant: c)
|
|
|
- } else if (a == .bottom) {
|
|
|
- constraint = self.centerYAnchor.constraint(equalTo: _targetV!.bottomAnchor, constant: c)
|
|
|
- } else if (a == .leading) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV!.leadingAnchor, constant: c)
|
|
|
- } else if (a == .trailing) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV!.trailingAnchor, constant: c)
|
|
|
- } else if (a == .left) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV!.leftAnchor, constant: c)
|
|
|
- } else if (a == .right) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV!.rightAnchor, constant: c)
|
|
|
- } else if (a == .width) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV.widthAnchor, constant: c)
|
|
|
- } else if (a == .height) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV.heightAnchor, constant: c)
|
|
|
- } else if (a == .centerX) {
|
|
|
-// constraint = self.centerYAnchor.constraint(equalTo: _targetV!.centerXAnchor, constant: c)
|
|
|
- } else if (a == .centerY) {
|
|
|
- constraint = self.centerYAnchor.constraint(equalTo: _targetV!.centerYAnchor, constant: c)
|
|
|
+ private func _km_layout_is_x_anchor(attribute a: NSLayoutConstraint.Attribute) -> Bool {
|
|
|
+ if (a == .leading || a == .trailing || a == .left || a == .right || a == .centerX) {
|
|
|
+ return true
|
|
|
}
|
|
|
- return constraint!
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
- // MARK: - Private Methods
|
|
|
+ private func _km_layout_is_y_anchor(attribute a: NSLayoutConstraint.Attribute) -> Bool {
|
|
|
+ if (a == .top || a == .bottom || a == .centerY) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+ }
|
|
|
|
|
|
- private func _km_layout_setup() {
|
|
|
- self.translatesAutoresizingMaskIntoConstraints = false
|
|
|
+ private func _km_layout_is_dimension_anchor(attribute a: NSLayoutConstraint.Attribute) -> Bool {
|
|
|
+ if (a == .width || a == .height) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
}
|