fix: center emoji artwork in launcher icon slot

This commit is contained in:
Valdemar Lorenzen
2026-10-15 15:35:20 +02:00
parent da1493a3c8
commit 0ba61153d4
3 changed files with 37 additions and 4 deletions
@@ -1,5 +1,6 @@
import AppKit
import ConjureKit
import CoreText
@MainActor
final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSearchFieldDelegate, NSTableViewDataSource, NSTableViewDelegate {
@@ -40,9 +41,13 @@ final class LauncherWindowController: NSWindowController, NSWindowDelegate, NSSe
private var pendingPresentation: (() -> Void)?
private static let emojiIcon: NSImage = {
let text = NSAttributedString(string: "🤔", attributes: [.font: NSFont.systemFont(ofSize: 28)])
let size = text.size()
return NSImage(size: size, flipped: false) { _ in
text.draw(at: .zero)
let line = CTLineCreateWithAttributedString(text)
return NSImage(size: NSSize(width: 32, height: 32), flipped: false) { rect in
guard let context = NSGraphicsContext.current?.cgContext else { return false }
context.textPosition = .zero
let bounds = CTLineGetImageBounds(line, context)
context.textPosition = CGPoint(x: rect.midX - bounds.midX, y: rect.midY - bounds.midY)
CTLineDraw(line, context)
return true
}
}()