fix: center emoji artwork in launcher icon slot
This commit is contained in:
@@ -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
|
||||
}
|
||||
}()
|
||||
|
||||
Reference in New Issue
Block a user