mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 09:28:38 +00:00
introduce bordered parameter, restore 0.13 borders
This commit is contained in:
parent
d37d9607d3
commit
fbec803d47
@ -14,6 +14,7 @@ class AppleScriptTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
self.script = script
|
self.script = script
|
||||||
|
button.bezelColor = .clear
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
var error: NSDictionary?
|
var error: NSDictionary?
|
||||||
guard script.compileAndReturnError(&error) else {
|
guard script.compileAndReturnError(&error) else {
|
||||||
|
|||||||
@ -22,13 +22,7 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
|
|
||||||
super.init(identifier: identifier)
|
super.init(identifier: identifier)
|
||||||
button = NSButton(title: title, target: self, action: nil)
|
button = NSButton(title: title, target: self, action: nil)
|
||||||
|
|
||||||
button.cell = CustomButtonCell(backgroundColor: bezelColor!)
|
|
||||||
button.cell?.title = title
|
|
||||||
button.title = title
|
button.title = title
|
||||||
|
|
||||||
button.bezelStyle = .rounded
|
|
||||||
button.bezelColor = bezelColor
|
|
||||||
self.view = button
|
self.view = button
|
||||||
|
|
||||||
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
||||||
@ -87,31 +81,6 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CustomButtonCell: NSButtonCell {
|
|
||||||
init(backgroundColor: NSColor) {
|
|
||||||
super.init(textCell: "")
|
|
||||||
if backgroundColor != .clear {
|
|
||||||
self.isBordered = true
|
|
||||||
self.backgroundColor = backgroundColor
|
|
||||||
} else {
|
|
||||||
self.isBordered = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override func highlight(_ flag: Bool, withFrame cellFrame: NSRect, in controlView: NSView) {
|
|
||||||
if flag {
|
|
||||||
self.isBordered = true
|
|
||||||
} else {
|
|
||||||
self.isBordered = false
|
|
||||||
}
|
|
||||||
super.highlight(flag, withFrame: cellFrame, in: controlView)
|
|
||||||
}
|
|
||||||
|
|
||||||
required init(coder: NSCoder) {
|
|
||||||
fatalError("init(coder:) has not been implemented")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
extension NSButton {
|
extension NSButton {
|
||||||
var title: String {
|
var title: String {
|
||||||
get {
|
get {
|
||||||
|
|||||||
@ -388,6 +388,7 @@ enum GeneralParameter {
|
|||||||
case width(_: CGFloat)
|
case width(_: CGFloat)
|
||||||
case image(source: SourceProtocol)
|
case image(source: SourceProtocol)
|
||||||
case align(_: Align)
|
case align(_: Align)
|
||||||
|
case bordered(_: Bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GeneralParameters: Decodable {
|
struct GeneralParameters: Decodable {
|
||||||
@ -397,6 +398,7 @@ struct GeneralParameters: Decodable {
|
|||||||
case width
|
case width
|
||||||
case image
|
case image
|
||||||
case align
|
case align
|
||||||
|
case bordered
|
||||||
}
|
}
|
||||||
init(from decoder: Decoder) throws {
|
init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
@ -409,6 +411,9 @@ struct GeneralParameters: Decodable {
|
|||||||
}
|
}
|
||||||
let align = try container.decodeIfPresent(Align.self, forKey: .align) ?? .center
|
let align = try container.decodeIfPresent(Align.self, forKey: .align) ?? .center
|
||||||
result[.align] = .align(align)
|
result[.align] = .align(align)
|
||||||
|
if let borderedFlag = try container.decodeIfPresent(Bool.self, forKey: .bordered) {
|
||||||
|
result[.bordered] = .bordered(borderedFlag)
|
||||||
|
}
|
||||||
parameters = result
|
parameters = result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -219,6 +219,10 @@ class TouchBarController: NSObject, NSTouchBarDelegate {
|
|||||||
button.cell?.image = source.image
|
button.cell?.image = source.image
|
||||||
button.bezelColor = .clear
|
button.bezelColor = .clear
|
||||||
}
|
}
|
||||||
|
if case .bordered(let bordered)? = item.additionalParameters[.bordered], let item = barItem as? CustomButtonTouchBarItem {
|
||||||
|
item.button.isBordered = bordered
|
||||||
|
item.button.bezelStyle = bordered ? .rounded : .inline
|
||||||
|
}
|
||||||
return barItem
|
return barItem
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -10,6 +10,7 @@ class TimeTouchBarItem: CustomButtonTouchBarItem {
|
|||||||
super.init(identifier: identifier, title: " ", onTap: onTap, onLongTap: onLongTap)
|
super.init(identifier: identifier, title: " ", onTap: onTap, onLongTap: onLongTap)
|
||||||
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
|
timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(updateTime), userInfo: nil, repeats: true)
|
||||||
self.view = button
|
self.view = button
|
||||||
|
button.bezelColor = .clear
|
||||||
updateTime()
|
updateTime()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user