fix warnings

This commit is contained in:
Ian Gulliver
2026-10-18 00:31:46 -07:00
parent e8599a7fce
commit bd66538383
11 changed files with 169 additions and 209 deletions
+8 -15
View File
@@ -309,10 +309,10 @@ private final class SpinnerView: NSView {
override func layout() {
super.layout()
guard let font, let color, let window, bounds.width > 0, bounds.height > 0 else {
guard let font, let color, bounds.width > 0, bounds.height > 0 else {
return
}
let key = Key(size: bounds.size, scale: window.backingScaleFactor, font: font, color: color)
let key = Key(size: bounds.size, scale: convertToBacking(NSSize(width: 1, height: 1)).width, font: font, color: color)
if key == drawn {
return
}
@@ -335,19 +335,12 @@ private final class SpinnerView: NSView {
}
private func render(_ s: String, _ key: Key) -> CGImage {
let ctx = CGContext(data: nil, width: Int(ceil(key.size.width * key.scale)), height: Int(ceil(key.size.height * key.scale)), bitsPerComponent: 8, bytesPerRow: 0, space: CGColorSpace(name: CGColorSpace.sRGB)!, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!
ctx.scaleBy(x: key.scale, y: key.scale)
let attrs: [NSAttributedString.Key: Any] = [
NSAttributedString.Key(kCTFontAttributeName as String): key.font,
NSAttributedString.Key(kCTForegroundColorAttributeName as String): key.color,
]
let line = CTLineCreateWithAttributedString(NSAttributedString(string: s, attributes: attrs))
var ascent: CGFloat = 0
var descent: CGFloat = 0
let width = CTLineGetTypographicBounds(line, &ascent, &descent, nil)
ctx.textPosition = CGPoint(x: (key.size.width - width) / 2, y: (key.size.height - ascent - descent) / 2 + descent)
CTLineDraw(line, ctx)
return ctx.makeImage()!
let r = ImageRenderer(content: Text(s)
.font(Font(key.font))
.foregroundStyle(Color(cgColor: key.color))
.frame(width: key.size.width, height: key.size.height))
r.scale = key.scale
return r.cgImage!
}
}