Color Well 颜色井(Color Well) macos

Fill
Show Colors…

标本可交互 —— 点点看。Specimen is live — try it.

Anatomy — every part, named解剖 —— 每个部件的名字

  1. 1 Color swatch色样(Color swatch) NSColorWell.color

    “The colored area itself” is the swatch — it always displays the well's current color and is the click target for the quick picker.

    “那块有颜色的区域本身”就是色样 —— 它始终显示颜色井的当前颜色,也是打开快速取色器的点击目标。

    Prompt fragmentPrompt 片段

    the swatch area of an NSColorWell showing its current color (NSColorWell.color)

    NSColorWell 上显示当前颜色的色样区域(NSColorWell.color)

  2. 2 Color-panel button颜色面板按钮(Color-panel button) NSColorWell.Style.expanded

    “The little arrow segment next to the swatch” is the dedicated button the expanded style adds — it opens the full color panel.

    “色样旁边的小箭头段”就是 expanded 样式加上的专用按钮 —— 它打开完整颜色面板。

    Prompt fragmentPrompt 片段

    the caret button attached to an expanded-style NSColorWell (colorWellStyle = .expanded) that opens NSColorPanel

    附着在 expanded 样式 NSColorWell 上的尖角按钮(colorWellStyle = .expanded),用于打开 NSColorPanel

  3. 3 Quick color popover快速取色弹层(Quick color popover) NSColorWell.colorWellStyle

    “The grid of color squares that pops up” is the expanded style's quick picker — swatches for fast choices, without the full panel.

    “弹出来的那板彩色方格”就是 expanded 样式的快速取色器 —— 色样便于快速选择,不用开完整面板。

    Prompt fragmentPrompt 片段

    the quick swatch-grid popover an expanded NSColorWell shows when the swatch is clicked

    expanded NSColorWell 在色块被点击时显示的快速色板弹层

  4. 4 Eyedropper (color sampler)吸管(Eyedropper/color sampler) NSColorSampler

    “The eyedropper that picks a color from anywhere on screen” is the system color sampler — one call: NSColorSampler().show { color in … }.

    “能从屏幕任何地方取色的吸管”就是系统颜色采样器 —— 一次调用:NSColorSampler().show { color in … }。

    Prompt fragmentPrompt 片段

    the system eyedropper for sampling a color from the screen (NSColorSampler().show { color in … })

    从屏幕取色的系统吸管(NSColorSampler().show { color in … })

Prompt — paste into your agentPrompt —— 直接粘贴给你的代理

Add a native macOS color well — NSColorWell (SwiftUI: ColorPicker). Use colorWellStyle = .expanded for the modern two-part control: clicking the swatch opens the quick color-grid popover with an eyedropper, and the caret button opens the full NSColorPanel. For a standalone screen-color eyedropper use NSColorSampler().show { color in … }.

添加原生 macOS 颜色井 —— NSColorWell(SwiftUI:ColorPicker)。现代的两段式控件用 colorWellStyle = .expanded:点击色块打开带吸管的快速色板弹层,点击尖角按钮打开完整的 NSColorPanel。要独立的屏幕取色吸管,用 NSColorSampler().show { color in … }。

Debug prompt — when it misbehaves调试 Prompt —— 当它不听话时

Debug my macOS color well (NSColorWell, SwiftUI ColorPicker). Rule out: the shared NSColorPanel serving every well in the app so two wells fight over it; continuous updates flooding your target action instead of committing on close; the eyedropper failing without Screen Recording permission; colors shifting because sRGB and Display P3 color spaces are being mixed. The symptom:

调试我的 macOS 颜色井(NSColorWell、SwiftUI ColorPicker)。逐项排除:共享的 NSColorPanel 服务全 App 所有颜色井,两个井互相抢;连续更新狂发 target action,而不是关闭时才提交;没有“屏幕录制”权限,吸管失效;sRGB 和 Display P3 色彩空间混用导致颜色偏移。症状是:

In code代码里叫什么

Framework框架Symbol符号Note说明
AppKit NSColorWell
SwiftUI ColorPicker
AppKit NSColorWell.colorWellStyle .minimal / .default / .expanded (macOS 13+).minimal / .default / .expanded(macOS 13+)
AppKit NSColorWell.color
AppKit NSColorSampler the standalone eyedropper独立的吸管工具
AppKit NSColorWell.supportsAlpha

See also相关词条