mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-08-02 14:57:31 +03:00
fix: vertically center toolbar title more accurately
Signed-off-by: Aaron Ruan <i@ar212.com>
This commit is contained in:

committed by
Mitchell Hashimoto

parent
429c8ab277
commit
830a117555
@ -95,6 +95,23 @@ fileprivate class CenteredDynamicLabel: NSTextField {
|
||||
setContentHuggingPriority(.defaultLow, for: .horizontal)
|
||||
setContentCompressionResistancePriority(.defaultHigh, for: .horizontal)
|
||||
}
|
||||
|
||||
// Vertically center the text
|
||||
override func draw(_ dirtyRect: NSRect) {
|
||||
guard let attributedString = self.attributedStringValue.mutableCopy() as? NSMutableAttributedString else {
|
||||
super.draw(dirtyRect)
|
||||
return
|
||||
}
|
||||
|
||||
let textSize = attributedString.size()
|
||||
|
||||
let yOffset = (self.bounds.height - textSize.height) / 2 - 1 // -1 to center it better
|
||||
|
||||
let centeredRect = NSRect(x: self.bounds.origin.x, y: self.bounds.origin.y + yOffset,
|
||||
width: self.bounds.width, height: textSize.height)
|
||||
|
||||
attributedString.draw(in: centeredRect)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSToolbarItem.Identifier {
|
||||
|
Reference in New Issue
Block a user