mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
fix that borderless buttons in scrollable area were not centered, fix wrong text color for borderless colored buttons
This commit is contained in:
parent
02baef80db
commit
20ed827750
@ -21,12 +21,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
self.longTapClosure = callbackLong
|
self.longTapClosure = callbackLong
|
||||||
|
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
button = NSButton(title: title, target: nil, action: nil)
|
installButton(titled: title, bordered: true, backgroundColor: nil)
|
||||||
button.cell = CustomButtonCell()
|
|
||||||
button.isBordered = true
|
|
||||||
button.bezelStyle = .rounded
|
|
||||||
button.title = title
|
|
||||||
self.view = button
|
|
||||||
|
|
||||||
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
||||||
longClick.allowedTouchTypes = .direct
|
longClick.allowedTouchTypes = .direct
|
||||||
@ -44,6 +39,33 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
fatalError("init(coder:) has not been implemented")
|
fatalError("init(coder:) has not been implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isBordered: Bool = true {
|
||||||
|
didSet {
|
||||||
|
installButton(titled: self.button.title, bordered: isBordered, backgroundColor: backgroundColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var backgroundColor: NSColor? {
|
||||||
|
didSet {
|
||||||
|
installButton(titled: self.button.title, bordered: isBordered, backgroundColor: backgroundColor)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private func installButton(titled title: String, bordered: Bool, backgroundColor: NSColor?) {
|
||||||
|
button = CustomHeightButton(title: title, target: nil, action: nil)
|
||||||
|
let cell = CustomButtonCell()
|
||||||
|
button.cell = cell
|
||||||
|
if let color = backgroundColor {
|
||||||
|
cell.isBordered = true
|
||||||
|
button.bezelColor = color
|
||||||
|
cell.backgroundColor = color
|
||||||
|
} else {
|
||||||
|
button.isBordered = bordered
|
||||||
|
button.bezelStyle = bordered ? .rounded : .inline
|
||||||
|
}
|
||||||
|
button.title = title
|
||||||
|
self.view = button
|
||||||
|
}
|
||||||
|
|
||||||
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
func gestureRecognizer(_ gestureRecognizer: NSGestureRecognizer, shouldRequireFailureOf otherGestureRecognizer: NSGestureRecognizer) -> Bool {
|
||||||
if gestureRecognizer == singleClick && otherGestureRecognizer == longClick {
|
if gestureRecognizer == singleClick && otherGestureRecognizer == longClick {
|
||||||
@ -84,6 +106,16 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CustomHeightButton : NSButton {
|
||||||
|
|
||||||
|
override var intrinsicContentSize: NSSize {
|
||||||
|
var size = super.intrinsicContentSize
|
||||||
|
size.height = 30
|
||||||
|
return size
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
class CustomButtonCell: NSButtonCell {
|
class CustomButtonCell: NSButtonCell {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
@ -117,5 +149,6 @@ class CustomButtonCell: NSButtonCell {
|
|||||||
|
|
||||||
self.attributedTitle = attrTitle
|
self.attributedTitle = attrTitle
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -212,18 +212,10 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
widthBarItem.setWidth(value: value)
|
widthBarItem.setWidth(value: value)
|
||||||
}
|
}
|
||||||
if case .bordered(let bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
if case .bordered(let bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
item.button.isBordered = bordered
|
item.isBordered = bordered
|
||||||
item.button.bezelStyle = bordered ? .rounded : .inline
|
|
||||||
}
|
}
|
||||||
if case .background(let color)? = item.additionalParameters[.background], let item = barItem as? CustomButtonTouchBarItem {
|
if case .background(let color)? = item.additionalParameters[.background], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
if item.button.cell?.isBordered == false {
|
item.backgroundColor = color
|
||||||
let newCell = NSButtonCell()
|
|
||||||
newCell.title = item.button.title
|
|
||||||
item.button.cell = newCell
|
|
||||||
item.button.cell?.isBordered = true
|
|
||||||
}
|
|
||||||
item.button.bezelColor = color
|
|
||||||
(item.button.cell as? NSButtonCell)?.backgroundColor = color
|
|
||||||
}
|
}
|
||||||
if case .image(let source)? = item.additionalParameters[.image], let item = barItem as? CustomButtonTouchBarItem {
|
if case .image(let source)? = item.additionalParameters[.image], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
let button = item.button!
|
let button = item.button!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user