|
@@ -21,7 +21,6 @@ extension KMToolbarItemView {
|
|
|
}
|
|
|
|
|
|
@objcMembers class KMToolbarItemView: NSView {
|
|
|
-
|
|
|
var menuFormRepresentation: NSMenuItem?
|
|
|
|
|
|
private var _itemIdentifier: String?
|
|
@@ -32,25 +31,18 @@ extension KMToolbarItemView {
|
|
|
}
|
|
|
|
|
|
lazy var clickButton: KMToolbarClickButton = {
|
|
|
- let _clickButton = KMToolbarClickButton()
|
|
|
- _clickButton.bezelStyle = .regularSquare
|
|
|
- _clickButton.isBordered = false
|
|
|
- _clickButton.imagePosition = .imageOnly
|
|
|
- _clickButton.clickObject = self
|
|
|
- return _clickButton
|
|
|
+ let view = KMToolbarClickButton()
|
|
|
+ view.bezelStyle = .regularSquare
|
|
|
+ view.isBordered = false
|
|
|
+ view.imagePosition = .imageOnly
|
|
|
+ view.clickObject = self
|
|
|
+ return view
|
|
|
}()
|
|
|
|
|
|
var isSelected = false {
|
|
|
didSet {
|
|
|
if self.itemIdentifier != KMToolbarDividerItemIdentifier {
|
|
|
if (isSelected) {
|
|
|
- if (isMainTool) {
|
|
|
-// self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
|
|
|
- self.imageViewBox.fillColor = self.normalBackgroundColor
|
|
|
- self.nameBtn.setTitleColor(color: KMAppearance.titleColor(), font: .SFProTextSemiboldFont(14))
|
|
|
- self.linView.isHidden = false
|
|
|
- return
|
|
|
- }
|
|
|
// self.layer?.backgroundColor = self.selectedBackgroundColor.cgColor
|
|
|
self.imageViewBox.fillColor = self.selectedBackgroundColor
|
|
|
if(self.image != nil && self.alternateImage != nil) {
|
|
@@ -67,13 +59,6 @@ extension KMToolbarItemView {
|
|
|
self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownSel")
|
|
|
}
|
|
|
} else {
|
|
|
- if (isMainTool) {
|
|
|
-// self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
|
|
|
- self.imageViewBox.fillColor = self.normalBackgroundColor
|
|
|
- self.nameBtn.setTitleColor(color: NSColor(red: 97.0/255.0, green: 100.0/255.0, blue: 105.0/255.0, alpha: 1.0),font: .SFProTextRegularFont(14))
|
|
|
- self.linView.isHidden = true
|
|
|
- return
|
|
|
- }
|
|
|
// self.layer?.backgroundColor = self.normalBackgroundColor.cgColor
|
|
|
self.imageViewBox.fillColor = self.normalBackgroundColor
|
|
|
if (self.needExpandAction) {
|
|
@@ -148,58 +133,42 @@ extension KMToolbarItemView {
|
|
|
self._layoutView()
|
|
|
}
|
|
|
}
|
|
|
- var isMainTool = false {
|
|
|
- didSet {
|
|
|
- if (isMainTool) {
|
|
|
- self.nameBtn.setTitleColor(color: NSColor(red: 97.0/255.0, green: 100.0/255.0, blue: 105.0/255.0, alpha: 1), font: .SFProTextRegularFont(14))
|
|
|
- } else {
|
|
|
- self.nameBtn.setTitleColor(color: KMAppearance.titleColor())
|
|
|
- }
|
|
|
- self._layoutView()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- var linView: NSView = {
|
|
|
- let _linView = NSView()
|
|
|
- _linView.wantsLayer = true
|
|
|
- _linView.layer?.backgroundColor = NSColor(red: 23/255.0, green: 112/255.0, blue: 244/255.0, alpha: 1).cgColor
|
|
|
- _linView.layer?.cornerRadius = 2
|
|
|
- return _linView
|
|
|
- }()
|
|
|
|
|
|
var normalBackgroundColor: NSColor = .clear
|
|
|
var selectedBackgroundColor: NSColor = KMAppearance.Status.selColor()
|
|
|
|
|
|
- var imageViewBox: NSBox = {
|
|
|
- let _imageViewBox = NSBox()
|
|
|
- _imageViewBox.borderWidth = 0
|
|
|
- _imageViewBox.contentViewMargins = NSZeroSize
|
|
|
- _imageViewBox.boxType = .custom
|
|
|
- return _imageViewBox
|
|
|
+ lazy var imageViewBox: NSBox = {
|
|
|
+ let view = NSBox()
|
|
|
+ view.borderWidth = 0
|
|
|
+ view.contentViewMargins = NSSize.zero
|
|
|
+ view.boxType = .custom
|
|
|
+ view.borderColor = .clear
|
|
|
+ view.cornerRadius = 7.0
|
|
|
+ return view
|
|
|
}()
|
|
|
private lazy var imageViewBtn: NSButton = {
|
|
|
- let _imageViewBtn = NSButton()
|
|
|
- _imageViewBtn.bezelStyle = .regularSquare
|
|
|
- _imageViewBtn.isBordered = false
|
|
|
- _imageViewBtn.imagePosition = .imageOnly
|
|
|
- return _imageViewBtn
|
|
|
+ let view = NSButton()
|
|
|
+ view.bezelStyle = .regularSquare
|
|
|
+ view.isBordered = false
|
|
|
+ view.imagePosition = .imageOnly
|
|
|
+ return view
|
|
|
}()
|
|
|
private var nameBtn: NSButton = {
|
|
|
- let _nameBtn = NSButton()
|
|
|
- _nameBtn.bezelStyle = .regularSquare
|
|
|
- _nameBtn.isBordered = false
|
|
|
- _nameBtn.imagePosition = .imageOnly
|
|
|
- _nameBtn.font = .systemFont(ofSize: 12)
|
|
|
- _nameBtn.title = ""
|
|
|
- return _nameBtn
|
|
|
+ let view = NSButton()
|
|
|
+ view.bezelStyle = .regularSquare
|
|
|
+ view.isBordered = false
|
|
|
+ view.imagePosition = .imageOnly
|
|
|
+ view.font = .systemFont(ofSize: 12)
|
|
|
+ view.title = ""
|
|
|
+ return view
|
|
|
}()
|
|
|
private var needExpandButton: NSButton = {
|
|
|
- let _needExpandButton = NSButton()
|
|
|
- _needExpandButton.bezelStyle = .regularSquare
|
|
|
- _needExpandButton.isBordered = false
|
|
|
- _needExpandButton.imagePosition = .imageOnly
|
|
|
- _needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
|
|
|
- return _needExpandButton
|
|
|
+ let view = NSButton()
|
|
|
+ view.bezelStyle = .regularSquare
|
|
|
+ view.isBordered = false
|
|
|
+ view.imagePosition = .imageOnly
|
|
|
+ view.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
|
|
|
+ return view
|
|
|
}()
|
|
|
private var _popOver: NSPopover?
|
|
|
var popOver: NSPopover? {
|
|
@@ -240,9 +209,6 @@ extension KMToolbarItemView {
|
|
|
self.layer?.cornerRadius = 5
|
|
|
self.layer?.masksToBounds = true
|
|
|
|
|
|
-// self.normalBackgroundColor = .clear
|
|
|
-// self.selectedBackgroundColor = NSColor(red: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1)
|
|
|
-
|
|
|
self._addTrackingArea()
|
|
|
NotificationCenter.default.addObserver(self, selector: #selector(_windowClosedPop), name: KMToolbarItemView.popOverClosedNotificationName, object: nil)
|
|
|
}
|
|
@@ -257,9 +223,6 @@ extension KMToolbarItemView {
|
|
|
self.layer?.cornerRadius = 4
|
|
|
self.layer?.masksToBounds = true
|
|
|
|
|
|
-// self.normalBackgroundColor = .clear
|
|
|
-// self.selectedBackgroundColor = NSColor(red: 223.0/255.0, green: 225.0/255.0, blue: 229.0/255.0, alpha: 1)
|
|
|
-
|
|
|
self._addTrackingArea()
|
|
|
self._layoutView()
|
|
|
if (popMenuViewController != nil) {
|
|
@@ -293,13 +256,6 @@ extension KMToolbarItemView {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // MARK: - Private Methods
|
|
|
-
|
|
|
- private func _addTrackingArea() {
|
|
|
- let trackingArea = NSTrackingArea(rect: self.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeInKeyWindow], owner: self)
|
|
|
- self.addTrackingArea(trackingArea)
|
|
|
- }
|
|
|
-
|
|
|
override func mouseEntered(with event: NSEvent) {
|
|
|
super.mouseEntered(with: event)
|
|
|
|
|
@@ -325,7 +281,8 @@ extension KMToolbarItemView {
|
|
|
}
|
|
|
}
|
|
|
if (self.needExpandAction) {
|
|
|
- self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownSel")
|
|
|
+ // KMImageNameUXIconBtnTriDownSel
|
|
|
+ self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
|
|
|
self._showPop(self)
|
|
|
}else if (self.isShowCustomToolTip) {
|
|
|
self.perform(#selector(_showHUDHint), with: nil, afterDelay: 0.1)
|
|
@@ -359,7 +316,7 @@ extension KMToolbarItemView {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if(self.nameBtn.superview != nil && !self.isSelected && !self.isMainTool) {
|
|
|
+ if(self.nameBtn.superview != nil && !self.isSelected) {
|
|
|
self.nameBtn.setTitleColor(color: KMAppearance.titleColor())
|
|
|
}
|
|
|
|
|
@@ -368,27 +325,20 @@ extension KMToolbarItemView {
|
|
|
self._closePop()
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @objc private func _showHUDHint() {
|
|
|
- // KMToolbarItemPopViewController *popViewController = [[[KMToolbarItemPopViewController alloc] init] autorelease];
|
|
|
- // self.popOver = [[[NSPopover alloc] init] autorelease];
|
|
|
- // self.popOver.contentViewController = popViewController;
|
|
|
- // self.popOver.animates = NO;
|
|
|
- // self.popOver.behavior = NSPopoverBehaviorSemitransient;
|
|
|
- // self.popOver.backgroundColor = [KMAppearance KMBluegrey01Color];
|
|
|
- //
|
|
|
- // self.popOver.contentSize = popViewController.view.frame.size;
|
|
|
- // [popViewController updateWithHelpTip:self.originalHelpTip];
|
|
|
- // [self.popOver showRelativeToRect:self.bounds ofView:self preferredEdge:NSRectEdgeMinY];
|
|
|
- }
|
|
|
-
|
|
|
- @objc private func _windowClosedPop(sender: Notification) {
|
|
|
- if let data = self._popOver?.isEqual(to: sender.object), data {
|
|
|
- self.popOver = nil
|
|
|
- }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - Private Methods
|
|
|
+
|
|
|
+extension KMToolbarItemView {
|
|
|
+ private func _addTrackingArea() {
|
|
|
+ let trackingArea = NSTrackingArea(rect: self.bounds, options: [.mouseEnteredAndExited, .inVisibleRect, .activeInKeyWindow], owner: self)
|
|
|
+ self.addTrackingArea(trackingArea)
|
|
|
}
|
|
|
|
|
|
private func _showPop(_ sender: NSView) {
|
|
|
+ if (self._popOver != nil) {
|
|
|
+ return
|
|
|
+ }
|
|
|
let menuViewController = KMCustomButtonPopMenuViewController()
|
|
|
menuViewController.delegate = self
|
|
|
menuViewController.dataSources = self
|
|
@@ -400,13 +350,14 @@ extension KMToolbarItemView {
|
|
|
self.popOver?.contentSize = menuViewController.view.frame.size
|
|
|
|
|
|
var sourcesRect = sender.bounds
|
|
|
- sourcesRect.size = sender.convert(sourcesRect.size, to: nil)
|
|
|
- sourcesRect.origin.y -= 20
|
|
|
+ sourcesRect = sender.convert(sourcesRect, to: nil)
|
|
|
+// sourcesRect.size = sender.convert(sourcesRect.size, to: nil)
|
|
|
+ sourcesRect.origin.y += 20
|
|
|
sourcesRect.size.height += 20
|
|
|
self.window?.popover = self.popOver
|
|
|
self.window?.sourcesRect = sourcesRect
|
|
|
|
|
|
- self.popOver?.show(relativeTo: CGRectInset(self.bounds, 0, 5), of: self, preferredEdge: .maxY)
|
|
|
+ self.popOver?.show(relativeTo: CGRectInset(self.bounds, 0, 5), of: self, preferredEdge: .minY)
|
|
|
}
|
|
|
|
|
|
private func _closePop() {
|
|
@@ -414,17 +365,29 @@ extension KMToolbarItemView {
|
|
|
self.popOver = nil
|
|
|
}
|
|
|
|
|
|
+ @objc private func _showHUDHint() {
|
|
|
+ // KMToolbarItemPopViewController *popViewController = [[[KMToolbarItemPopViewController alloc] init] autorelease];
|
|
|
+ // self.popOver = [[[NSPopover alloc] init] autorelease];
|
|
|
+ // self.popOver.contentViewController = popViewController;
|
|
|
+ // self.popOver.animates = NO;
|
|
|
+ // self.popOver.behavior = NSPopoverBehaviorSemitransient;
|
|
|
+ // self.popOver.backgroundColor = [KMAppearance KMBluegrey01Color];
|
|
|
+ //
|
|
|
+ // self.popOver.contentSize = popViewController.view.frame.size;
|
|
|
+ // [popViewController updateWithHelpTip:self.originalHelpTip];
|
|
|
+ // [self.popOver showRelativeToRect:self.bounds ofView:self preferredEdge:NSRectEdgeMinY];
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func _windowClosedPop(sender: Notification) {
|
|
|
+ if let data = self._popOver?.isEqual(to: sender.object), data {
|
|
|
+ self.popOver = nil
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private func _layoutView() {
|
|
|
- let offset = 4.0
|
|
|
- let offsetY = 2.0
|
|
|
- let offsetX = 4.0
|
|
|
if self.nameBtn.superview != nil {
|
|
|
self.nameBtn.removeFromSuperview()
|
|
|
}
|
|
|
- if self.linView.superview != nil {
|
|
|
- self.linView.removeFromSuperview()
|
|
|
- }
|
|
|
-
|
|
|
if self.imageViewBox.superview != nil {
|
|
|
self.imageViewBox.removeFromSuperview()
|
|
|
}
|
|
@@ -432,97 +395,79 @@ extension KMToolbarItemView {
|
|
|
self.imageViewBtn.removeFromSuperview()
|
|
|
}
|
|
|
|
|
|
- if self.customizeView != nil {
|
|
|
- if self.customizeView?.superview != nil {
|
|
|
- self.customizeView?.removeFromSuperview()
|
|
|
+ if let view = self.customizeView {
|
|
|
+ if view.superview != nil {
|
|
|
+ view.removeFromSuperview()
|
|
|
}
|
|
|
- self.addSubview(self.customizeView!)
|
|
|
-
|
|
|
- self.customizeView?.mas_makeConstraints({ make in
|
|
|
- make?.left.right().equalTo()(0)
|
|
|
- make?.centerY.equalTo()(0)
|
|
|
- make?.width.offset()(self.customizeView!.frame.size.width)
|
|
|
- make?.height.offset()(self.customizeView!.frame.size.height)
|
|
|
- })
|
|
|
+ self.addSubview(view)
|
|
|
+ view.km_add_leading_constraint()
|
|
|
+ view.km_add_trailing_constraint()
|
|
|
+ view.km_add_centerY_constraint()
|
|
|
+ view.km_add_width_constraint(constant: NSWidth(view.bounds))
|
|
|
+ view.km_add_height_constraint(constant: NSHeight(view.bounds))
|
|
|
+ return
|
|
|
+ } else if (self.itemIdentifier == KMToolbarDividerItemIdentifier) {
|
|
|
+ self.addSubview(self.imageViewBox)
|
|
|
+ self.imageViewBox.km_add_inset_constraint(inset: NSEdgeInsetsZero)
|
|
|
+ self.imageViewBox.km_add_width_constraint(constant: 8)
|
|
|
return
|
|
|
}
|
|
|
- if self.boxImagePosition == .imageOnly && self.itemIdentifier != KMToolbarDividerItemIdentifier {
|
|
|
+
|
|
|
+ let offset = 4.0
|
|
|
+ let offsetY = 2.0
|
|
|
+ let offsetX = 4.0
|
|
|
+ if self.boxImagePosition == .imageOnly {
|
|
|
self.addSubview(self.imageViewBox)
|
|
|
- self.imageViewBox.mas_makeConstraints { make in
|
|
|
- make?.left.right().top().bottom().equalTo()(0)
|
|
|
- }
|
|
|
+ self.imageViewBox.km_add_inset_constraint()
|
|
|
|
|
|
self.imageViewBox.contentView?.addSubview(self.imageViewBtn)
|
|
|
- self.imageViewBtn.mas_makeConstraints { make in
|
|
|
- make?.left.equalTo()(self.imageViewBox.mas_left)?.offset()(offsetX)
|
|
|
- make?.top.equalTo()(self.imageViewBox.mas_top)?.offset()(offsetY)
|
|
|
- make?.bottom.equalTo()(self.imageViewBox.mas_bottom)?.offset()(-offsetY)
|
|
|
- make?.right.equalTo()(self.imageViewBox.mas_right)?.offset()(-offsetX)
|
|
|
- }
|
|
|
+ self.imageViewBtn.km_add_inset_constraint(equalTo: self.imageViewBox, inset: NSEdgeInsets(top: offsetY, left: offsetX, bottom: offsetY, right: offsetX))
|
|
|
} else if (self.boxImagePosition == .imageLeft) {
|
|
|
self.addSubview(self.imageViewBox)
|
|
|
- self.imageViewBox.mas_makeConstraints { make in
|
|
|
- make?.left.top().bottom().equalTo()(0)
|
|
|
- }
|
|
|
+ self.imageViewBox.km_add_leading_constraint()
|
|
|
+ self.imageViewBox.km_add_top_constraint()
|
|
|
+ self.imageViewBox.km_add_bottom_constraint()
|
|
|
|
|
|
self.imageViewBox.contentView?.addSubview(self.imageViewBtn)
|
|
|
- self.imageViewBtn.mas_makeConstraints { make in
|
|
|
- make?.left.equalTo()(self.imageViewBox.mas_left)?.offset()(2 * offsetX)
|
|
|
- make?.top.equalTo()(self.imageViewBox.mas_top)?.offset()(offsetY)
|
|
|
- make?.bottom.equalTo()(self.imageViewBox.mas_bottom)?.offset()(-offsetY)
|
|
|
- make?.right.equalTo()(0)
|
|
|
- }
|
|
|
+ self.imageViewBtn.km_add_inset_constraint(equalTo: self.imageViewBox, inset: NSEdgeInsets(top: offsetY, left: 2*offsetX, bottom: offsetY, right: 0))
|
|
|
|
|
|
self.addSubview(self.nameBtn)
|
|
|
- self.nameBtn.mas_makeConstraints { make in
|
|
|
- make?.centerY.equalTo()(0)
|
|
|
- make?.left.equalTo()(self.imageViewBox.mas_right)?.offset()(0)
|
|
|
- if (self.needExpandAction) {
|
|
|
- make?.right.equalTo()(self.mas_right)?.offset()(-2*offsetX-8)
|
|
|
- } else {
|
|
|
- make?.right.equalTo()(self.mas_right)?.offset()(-2*offsetX)
|
|
|
- }
|
|
|
+ self.nameBtn.km_add_centerY_constraint()
|
|
|
+ self.nameBtn.km_add_leading_constraint(equalTo: self.imageViewBox, attribute: .trailing)
|
|
|
+ if (self.needExpandAction) {
|
|
|
+ self.nameBtn.km_add_right_constraint(constant: -2*offsetX-8)
|
|
|
+ } else {
|
|
|
+ self.nameBtn.km_add_right_constraint(constant: -2*offsetX)
|
|
|
}
|
|
|
|
|
|
if(self.needExpandAction) {
|
|
|
self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
|
|
|
self.addSubview(self.needExpandButton)
|
|
|
- self.needExpandButton.mas_makeConstraints { make in
|
|
|
- make?.centerY.equalTo()(0)
|
|
|
- make?.width.height().equalTo()(8)
|
|
|
- make?.right.equalTo()(self.mas_right)?.offset()(-offset)
|
|
|
- }
|
|
|
+ self.needExpandButton.km_add_centerY_constraint()
|
|
|
+ self.needExpandButton.km_add_width_constraint(constant: 8)
|
|
|
+ self.needExpandButton.km_add_right_constraint(constant: -offset)
|
|
|
}
|
|
|
|
|
|
self.layer?.cornerRadius = 6
|
|
|
} else if (self.boxImagePosition == .imageExpandLeft) {
|
|
|
self.addSubview(self.imageViewBox)
|
|
|
- self.imageViewBox.mas_makeConstraints { make in
|
|
|
- make?.left.top().bottom().equalTo()(0)
|
|
|
- }
|
|
|
+ self.imageViewBox.km_add_leading_constraint()
|
|
|
+ self.imageViewBox.km_add_top_constraint()
|
|
|
+ self.imageViewBox.km_add_bottom_constraint()
|
|
|
|
|
|
self.imageViewBox.contentView?.addSubview(self.imageViewBtn)
|
|
|
- self.imageViewBtn.mas_makeConstraints { make in
|
|
|
- make?.left.equalTo()(self.imageViewBox.mas_left)?.offset()(offsetX)
|
|
|
- make?.top.equalTo()(self.imageViewBox.mas_top)?.offset()(offsetY)
|
|
|
- make?.bottom.equalTo()(self.imageViewBox.mas_bottom)?.offset()(-offsetY)
|
|
|
- make?.right.equalTo()(0)
|
|
|
- }
|
|
|
+ self.imageViewBtn.km_add_inset_constraint(equalTo: self.imageViewBox, inset: NSEdgeInsets(top: offsetY, left: offsetX, bottom: offsetY, right: 0))
|
|
|
|
|
|
self.needExpandButton.image = NSImage(named: "KMImageNameUXIconBtnTriDownNor")
|
|
|
self.addSubview(self.needExpandButton)
|
|
|
- self.needExpandButton.mas_makeConstraints { make in
|
|
|
- make?.centerY.equalTo()(0)
|
|
|
- make?.width.height().equalTo()(8)
|
|
|
- make?.right.equalTo()(self.mas_right)?.offset()(-offset)
|
|
|
- }
|
|
|
+ self.needExpandButton.km_add_centerY_constraint()
|
|
|
+ self.needExpandButton.km_add_width_constraint(constant: 8)
|
|
|
+ self.needExpandButton.km_add_right_constraint(constant: -offset)
|
|
|
|
|
|
self.addSubview(self.nameBtn)
|
|
|
- self.nameBtn.mas_makeConstraints { make in
|
|
|
- make?.centerY.equalTo()(0)
|
|
|
- make?.left.equalTo()(self.imageViewBox.mas_right)?.offset()(0)
|
|
|
- make?.right.equalTo()(self.needExpandButton.mas_left)?.offset()(0)
|
|
|
- }
|
|
|
+ self.nameBtn.km_add_centerY_constraint()
|
|
|
+ self.nameBtn.km_add_leading_constraint(equalTo: self.imageViewBox, attribute: .trailing)
|
|
|
+ self.nameBtn.km_add_trailing_constraint(equalTo: self.needExpandButton, attribute: .leading)
|
|
|
} else if (self.boxImagePosition == .imageAbove) {
|
|
|
self.addSubview(self.nameBtn)
|
|
|
self.nameBtn.alignment = .center
|
|
@@ -531,66 +476,32 @@ extension KMToolbarItemView {
|
|
|
make?.width.greaterThanOrEqualTo()(32)
|
|
|
make?.bottom.equalTo()(self.mas_bottom)?.offset()(0)
|
|
|
}
|
|
|
+// self.nameBtn.km_add_leading_constraint()
|
|
|
+// self.nameBtn.km_add_trailing_constraint()
|
|
|
+// self.nameBtn.km_add_bottom_constraint()
|
|
|
|
|
|
self.addSubview(self.imageViewBox)
|
|
|
- self.imageViewBox.mas_makeConstraints { make in
|
|
|
- make?.top.equalTo()(0)
|
|
|
- make?.width.equalTo()(32)
|
|
|
- make?.centerX.equalTo()(0)
|
|
|
- make?.bottom.equalTo()(nameBtn.mas_top)?.offset()(0)
|
|
|
- }
|
|
|
+ self.imageViewBox.km_add_top_constraint()
|
|
|
+ self.imageViewBox.km_add_width_constraint(constant: 32)
|
|
|
+ self.imageViewBox.km_add_centerX_constraint()
|
|
|
+ self.imageViewBox.km_add_bottom_constraint(equalTo: self.nameBtn, attribute: .top, constant: 0)
|
|
|
|
|
|
self.imageViewBox.contentView?.addSubview(self.imageViewBtn)
|
|
|
- self.imageViewBtn.mas_makeConstraints { make in
|
|
|
- make?.left.equalTo()(offset)
|
|
|
- make?.right.equalTo()(-offset)
|
|
|
- make?.top.equalTo()(0)
|
|
|
- make?.bottom.equalTo()(0)
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (self.itemIdentifier == KMToolbarDividerItemIdentifier) {
|
|
|
- self.addSubview(self.imageViewBox)
|
|
|
- self.imageViewBox.mas_makeConstraints { make in
|
|
|
- make?.top.equalTo()(0)
|
|
|
- make?.width.equalTo()(8)
|
|
|
- make?.left.equalTo()(0)
|
|
|
- make?.right.equalTo()(0)
|
|
|
- make?.bottom.equalTo()(self.mas_bottom)?.offset()(0)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ self.imageViewBtn.km_add_inset_constraint(inset: .init(top: 0, left: offset, bottom: 0, right: offset))
|
|
|
}
|
|
|
-
|
|
|
- if self.nameBtn.superview != nil && self.isMainTool {
|
|
|
- self.addSubview(self.linView)
|
|
|
- self.linView.mas_makeConstraints { make in
|
|
|
- make?.width.offset()(32)
|
|
|
- make?.height.offset()(3)
|
|
|
- make?.centerX.equalTo()(self.mas_centerX)
|
|
|
- make?.bottom.equalTo()(self.mas_bottom)?.offset()(0)
|
|
|
- }
|
|
|
-
|
|
|
- self.nameBtn.font = .systemFont(ofSize: 14)
|
|
|
- self.linView.isHidden = true
|
|
|
- } else {
|
|
|
- self.nameBtn.font = .systemFont(ofSize: 12)
|
|
|
- }
|
|
|
-
|
|
|
- if self.itemIdentifier != KMToolbarDividerItemIdentifier {
|
|
|
- self.imageViewBox.borderColor = .clear
|
|
|
- self.imageViewBox.borderWidth = 1.0
|
|
|
- self.imageViewBox.cornerRadius = 7.0
|
|
|
|
|
|
- self.addSubview(self.clickButton)
|
|
|
- self.clickButton.mas_makeConstraints { make in
|
|
|
- make?.left.right().top().bottom().equalTo()(0)
|
|
|
- }
|
|
|
- }
|
|
|
+ self.imageViewBox.borderWidth = 1.0
|
|
|
+ self.addSubview(self.clickButton)
|
|
|
+ self.clickButton.km_add_inset_constraint()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
extension KMToolbarItemView: NSPopoverDelegate {
|
|
|
-
|
|
|
+ func popoverDidClose(_ notification: Notification) {
|
|
|
+ if let data = self.popOver?.isEqual(to: notification.object), data {
|
|
|
+ self._closePop()
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
extension KMToolbarItemView: KMCustomButtonPopMenuViewControllerDelegate, KMCustomButtonPopMenuViewControllerDataSources {
|