fix: optically center shortcut glyphs and tighten badge gaps
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import AppKit
|
||||
import ConjureKit
|
||||
import CoreText
|
||||
|
||||
@MainActor
|
||||
final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSearchFieldDelegate, NSTableViewDataSource, NSTableViewDelegate {
|
||||
@@ -321,7 +322,7 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
|
||||
actionsButton.leadingAnchor.constraint(equalTo: returnKey.trailingAnchor, constant: 14),
|
||||
commandKey.leadingAnchor.constraint(equalTo: actionsButton.trailingAnchor, constant: 8),
|
||||
commandKey.centerYAnchor.constraint(equalTo: actionPill.centerYAnchor),
|
||||
kKey.leadingAnchor.constraint(equalTo: commandKey.trailingAnchor, constant: 8),
|
||||
kKey.leadingAnchor.constraint(equalTo: commandKey.trailingAnchor, constant: 4),
|
||||
kKey.centerYAnchor.constraint(equalTo: actionPill.centerYAnchor),
|
||||
kKey.trailingAnchor.constraint(equalTo: actionPill.trailingAnchor, constant: -12),
|
||||
actionsButton.centerYAnchor.constraint(equalTo: actionPill.centerYAnchor),
|
||||
@@ -724,22 +725,20 @@ func shortcutBadge(_ title: String) -> NSTextField {
|
||||
|
||||
@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
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
guard let context = NSGraphicsContext.current?.cgContext else { return }
|
||||
let line = CTLineCreateWithAttributedString(attributedStringValue)
|
||||
let ink = CTLineGetBoundsWithOptions(line, .useGlyphPathBounds)
|
||||
context.saveGState()
|
||||
context.textMatrix = .identity
|
||||
// Center visible ink, not the font's asymmetric ascender/descender line box.
|
||||
context.translateBy(x: bounds.midX - ink.midX, y: bounds.midY + ink.midY)
|
||||
context.scaleBy(x: 1, y: -1)
|
||||
context.textPosition = .zero
|
||||
CTLineDraw(line, context)
|
||||
context.restoreGState()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ final class UninstallReviewController: NSViewController, NSSearchFieldDelegate,
|
||||
remove.centerYAnchor.constraint(equalTo: pill.centerYAnchor),
|
||||
commandKey.leadingAnchor.constraint(equalTo: remove.trailingAnchor, constant: 8),
|
||||
commandKey.centerYAnchor.constraint(equalTo: pill.centerYAnchor),
|
||||
returnKey.leadingAnchor.constraint(equalTo: commandKey.trailingAnchor, constant: 8),
|
||||
returnKey.leadingAnchor.constraint(equalTo: commandKey.trailingAnchor, constant: 4),
|
||||
returnKey.centerYAnchor.constraint(equalTo: pill.centerYAnchor),
|
||||
returnKey.trailingAnchor.constraint(equalTo: pill.trailingAnchor, constant: -12)
|
||||
])
|
||||
|
||||
Reference in New Issue
Block a user