mirror of
https://github.com/Toxblh/MTMR.git
synced 2026-01-11 17:38:38 +00:00
* NSButtonCell
This commit is contained in:
parent
9c1e5f5032
commit
e1268d0d65
@ -22,8 +22,11 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
||||
|
||||
super.init(identifier: identifier)
|
||||
button = NSButton(title: title, target: self, action: nil)
|
||||
|
||||
button.cell = CustomButtonCell(backgroundColor: bezelColor!)
|
||||
button.cell?.title = title
|
||||
|
||||
button.bezelColor = bezelColor
|
||||
button.title = title
|
||||
self.view = button
|
||||
|
||||
longClick = NSPressGestureRecognizer(target: self, action: #selector(handleGestureLong))
|
||||
@ -82,3 +85,23 @@ class CustomButtonTouchBarItem: NSCustomTouchBarItem, NSGestureRecognizerDelegat
|
||||
}
|
||||
}
|
||||
|
||||
class CustomButtonCell: NSButtonCell {
|
||||
init(backgroundColor: NSColor) {
|
||||
super.init(textCell: "")
|
||||
if backgroundColor != .clear {
|
||||
self.isBordered = true
|
||||
self.bezelStyle = .rounded
|
||||
self.backgroundColor = backgroundColor
|
||||
} else {
|
||||
self.isBordered = false
|
||||
}
|
||||
|
||||
self.font = NSFont.systemFont(ofSize: 15, weight: .regular )
|
||||
|
||||
}
|
||||
|
||||
required init(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -49,19 +49,19 @@ class CustomSliderCell: NSSliderCell {
|
||||
override func drawBar(inside aRect: NSRect, flipped: Bool) {
|
||||
_barRect = aRect
|
||||
|
||||
var rect = aRect
|
||||
rect.size.height = CGFloat(4)
|
||||
let barRadius = CGFloat(2)
|
||||
let value = CGFloat((self.doubleValue - self.minValue) / (self.maxValue - self.minValue))
|
||||
let finalWidth = CGFloat(value * (self.controlView!.frame.size.width - 12))
|
||||
|
||||
var leftRect = rect
|
||||
leftRect.size.width = finalWidth
|
||||
let bg = NSBezierPath(roundedRect: rect, xRadius: barRadius, yRadius: barRadius)
|
||||
var bgRect = aRect
|
||||
bgRect.size.height = CGFloat(4)
|
||||
|
||||
let bg = NSBezierPath(roundedRect: bgRect, xRadius: barRadius, yRadius: barRadius)
|
||||
NSColor.lightGray.setFill()
|
||||
bg.fill()
|
||||
|
||||
let active = NSBezierPath(roundedRect: leftRect, xRadius: barRadius, yRadius: barRadius)
|
||||
var activeRect = bgRect
|
||||
|
||||
activeRect.size.width = CGFloat((Double(bgRect.size.width) / (self.maxValue - self.minValue)) * self.doubleValue)
|
||||
let active = NSBezierPath(roundedRect: activeRect, xRadius: barRadius, yRadius: barRadius)
|
||||
NSColor.darkGray.setFill()
|
||||
active.fill()
|
||||
}
|
||||
|
||||
@ -42,7 +42,8 @@ class InputSourceBarItem: CustomButtonTouchBarItem {
|
||||
}
|
||||
|
||||
if (iconImage != nil) {
|
||||
self.button.image = iconImage
|
||||
self.button.imageScaling = .scaleProportionallyUpOrDown
|
||||
self.button.cell?.image = iconImage
|
||||
} else {
|
||||
self.button.title = currentSource.name
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user