fix: center shortcut symbols in square badges
This commit is contained in:
@@ -705,7 +705,7 @@ func roundMaterialCorners(_ view: NSVisualEffectView, radius: CGFloat) {
|
||||
|
||||
@MainActor
|
||||
func shortcutBadge(_ title: String) -> NSTextField {
|
||||
let badge = NSTextField(labelWithString: title)
|
||||
let badge = ShortcutBadge(labelWithString: title)
|
||||
badge.font = .systemFont(ofSize: 14)
|
||||
badge.textColor = SunsetPalette.secondaryText
|
||||
badge.alignment = .center
|
||||
@@ -721,3 +721,25 @@ func shortcutBadge(_ title: String) -> NSTextField {
|
||||
])
|
||||
return badge
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private final class ShortcutBadge: NSTextField {
|
||||
override class var cellClass: AnyClass? {
|
||||
get { ShortcutBadgeCell.self }
|
||||
set { super.cellClass = newValue }
|
||||
}
|
||||
|
||||
// NSTextField's horizontal alignment insets otherwise make an 18-point badge 22 points wide.
|
||||
override var alignmentRectInsets: NSEdgeInsets { NSEdgeInsets(top: 0, left: 0, bottom: 0, right: 0) }
|
||||
}
|
||||
|
||||
@MainActor
|
||||
private final class ShortcutBadgeCell: NSTextFieldCell {
|
||||
override func drawingRect(forBounds rect: NSRect) -> NSRect {
|
||||
var textRect = super.drawingRect(forBounds: rect)
|
||||
let textHeight = cellSize(forBounds: rect).height
|
||||
textRect.origin.y += (textRect.height - textHeight) / 2
|
||||
textRect.size.height = textHeight
|
||||
return textRect
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user