mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
Merge 20dd337493 into 9e10b2d3d1
This commit is contained in:
commit
23b7ebb019
@ -21,16 +21,20 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
self.longTapClosure = callbackLong
|
self.longTapClosure = callbackLong
|
||||||
|
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
|
button = CustomHeightButton(title: title, target: nil, action: nil)
|
||||||
|
|
||||||
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
||||||
longClick.allowedTouchTypes = .direct
|
longClick.allowedTouchTypes = .direct
|
||||||
longClick.delegate = self
|
longClick.delegate = self
|
||||||
|
self.view.addGestureRecognizer(longClick)
|
||||||
|
|
||||||
singleClick = NSClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
|
singleClick = NSClickGestureRecognizer(target: self, action: #selector(handleGestureSingle))
|
||||||
singleClick.allowedTouchTypes = .direct
|
singleClick.allowedTouchTypes = .direct
|
||||||
singleClick.delegate = self
|
singleClick.delegate = self
|
||||||
|
self.view.addGestureRecognizer(singleClick)
|
||||||
|
|
||||||
installButton(titled: title, bordered: true, backgroundColor: nil)
|
reinstallButton()
|
||||||
|
button.title = title
|
||||||
}
|
}
|
||||||
|
|
||||||
required init?(coder: NSCoder) {
|
required init?(coder: NSCoder) {
|
||||||
@ -39,18 +43,19 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
|
|
||||||
var isBordered: Bool = true {
|
var isBordered: Bool = true {
|
||||||
didSet {
|
didSet {
|
||||||
installButton(titled: self.button.title, bordered: isBordered, backgroundColor: backgroundColor)
|
reinstallButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var backgroundColor: NSColor? {
|
var backgroundColor: NSColor? {
|
||||||
didSet {
|
didSet {
|
||||||
installButton(titled: self.button.title, bordered: isBordered, backgroundColor: backgroundColor)
|
reinstallButton()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func installButton(titled title: String, bordered: Bool, backgroundColor: NSColor?) {
|
private func reinstallButton() {
|
||||||
button = CustomHeightButton(title: title, target: nil, action: nil)
|
let title = button.attributedTitle
|
||||||
|
let image = button.image
|
||||||
let cell = CustomButtonCell()
|
let cell = CustomButtonCell()
|
||||||
button.cell = cell
|
button.cell = cell
|
||||||
if let color = backgroundColor {
|
if let color = backgroundColor {
|
||||||
@ -58,14 +63,12 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
button.bezelColor = color
|
button.bezelColor = color
|
||||||
cell.backgroundColor = color
|
cell.backgroundColor = color
|
||||||
} else {
|
} else {
|
||||||
button.isBordered = bordered
|
button.isBordered = isBordered
|
||||||
button.bezelStyle = bordered ? .rounded : .inline
|
button.bezelStyle = isBordered ? .rounded : .inline
|
||||||
}
|
}
|
||||||
button.title = title
|
button.attributedTitle = title
|
||||||
|
button.image = image
|
||||||
self.view = button
|
self.view = button
|
||||||
|
|
||||||
self.view.addGestureRecognizer(longClick)
|
|
||||||
self.view.addGestureRecognizer(singleClick)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user