接入有界趋势、平滑滚动、菜单式外侧详情、底部操作与三语文案,装配独立外观设置和 Dock 生命周期。 合并跟随系统外观刷新、自选颜色入口与色块绘制修复,保留用户确认的配色联动、重启保存及滚动验收。 多场景视觉与长期资源验证边界仍记录于 docs。
69 lines
4.2 KiB
Swift
69 lines
4.2 KiB
Swift
import Foundation
|
|
import AppKit
|
|
import CoreGraphics
|
|
|
|
@main struct PresentationChecks {
|
|
@MainActor static func main() {
|
|
let screen = CGRect(x: 0, y: 0, width: 1440, height: 900)
|
|
let parent = CGRect(x: 400, y: 400, width: 320, height: 240)
|
|
let anchor = CGRect(x: 410, y: 600, width: 300, height: 40)
|
|
let size = CGSize(width: 280, height: 180)
|
|
let right = DetailPlacement.frame(anchor: anchor, parent: parent, content: size, visible: screen)
|
|
precondition(right.minX == parent.maxX + 4 && right.maxY == anchor.maxY)
|
|
let edgeParent = CGRect(x: 1100, y: 400, width: 320, height: 240)
|
|
let left = DetailPlacement.frame(anchor: anchor, parent: edgeParent, content: size, visible: screen)
|
|
precondition(left.maxX == edgeParent.minX - 4)
|
|
for visible in [screen, CGRect(x: -1440, y: -200, width: 1440, height: 900), CGRect(x: 0, y: 0, width: 200, height: 100)] {
|
|
let result = DetailPlacement.frame(anchor: anchor, parent: parent, content: size, visible: visible)
|
|
precondition(visible.contains(result))
|
|
}
|
|
let highAnchor = CGRect(x: 400, y: 1100, width: 300, height: 40)
|
|
precondition(DetailPlacement.frame(anchor: highAnchor, parent: parent, content: size, visible: screen).maxY == screen.maxY)
|
|
let lowAnchor = CGRect(x: 400, y: -200, width: 300, height: 40)
|
|
precondition(DetailPlacement.frame(anchor: lowAnchor, parent: parent, content: size, visible: screen).minY == screen.minY)
|
|
precondition(AppAppearance.system.resolved(systemIsDark: true) == .dark)
|
|
precondition(AppAppearance.system.resolved(systemIsDark: false) == .light)
|
|
precondition(AppAppearance.light.resolved(systemIsDark: true) == .light)
|
|
precondition(AppAppearance.dark.resolved(systemIsDark: false) == .dark)
|
|
precondition(SystemAppearanceObserver.isDark(globalDomain: ["AppleInterfaceStyle": "Dark"]))
|
|
precondition(!SystemAppearanceObserver.isDark(globalDomain: [:]))
|
|
_ = NSApplication.shared
|
|
let swatch = CustomColorWell.SwatchButton(frame: CGRect(x: 0, y: 0, width: 44, height: 26))
|
|
var clicked = false
|
|
swatch.open = { clicked = true }
|
|
precondition(swatch.acceptsFirstMouse(for: nil))
|
|
swatch.performClick(nil)
|
|
precondition(clicked)
|
|
swatch.swatchColor = NSColor(srgbRed: 0.2, green: 0.5, blue: 0.9, alpha: 1)
|
|
let bitmap = NSBitmapImageRep(bitmapDataPlanes: nil, pixelsWide: 44, pixelsHigh: 26,
|
|
bitsPerSample: 8, samplesPerPixel: 4, hasAlpha: true,
|
|
isPlanar: false, colorSpaceName: .deviceRGB, bytesPerRow: 0, bitsPerPixel: 0)!
|
|
NSGraphicsContext.saveGraphicsState()
|
|
NSGraphicsContext.current = NSGraphicsContext(bitmapImageRep: bitmap)
|
|
NSColor.clear.setFill()
|
|
swatch.bounds.fill(using: .copy)
|
|
swatch.draw(swatch.bounds)
|
|
NSGraphicsContext.restoreGraphicsState()
|
|
let center = bitmap.colorAt(x: 22, y: 13)!.usingColorSpace(.sRGB)!
|
|
precondition(abs(center.redComponent - 0.2) < 0.02)
|
|
precondition(abs(center.greenComponent - 0.5) < 0.02)
|
|
precondition(abs(center.blueComponent - 0.9) < 0.02)
|
|
precondition(bitmap.colorAt(x: 0, y: 0)!.alphaComponent == 0)
|
|
let global = NSApp.appearance
|
|
let window = NSWindow(contentRect: .zero, styleMask: .borderless, backing: .buffered, defer: true)
|
|
window.isReleasedWhenClosed = false
|
|
for choice in [AppAppearance.light, .system, .dark, .system] {
|
|
WindowAppearance.apply(choice, to: window)
|
|
if choice == .system {
|
|
precondition(window.appearance == nil)
|
|
precondition(window.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]) == NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]))
|
|
} else {
|
|
precondition(window.appearance?.name == choice.windowAppearance?.name)
|
|
}
|
|
precondition(NSApp.appearance === global)
|
|
}
|
|
window.close()
|
|
print("PASS: outward placement, edge fallback, negative screen origins, vertical limits, explicit/system window appearance reset, independent system resolution, native swatch target/action")
|
|
}
|
|
}
|