Artboards: an artboard's guide label colors its own guides

Each artboard can carry a guide label: one of the layer colors or a
custom RGB. Guides that belong to an artboard draw in its label color,
and guides without an artboard, or on an artboard without a label, keep
the guide color from the preferences. Selected guides still draw in the
selection color.

- Artboard Options has a Guide Label row (None, the layer colors with
  swatches, or Custom with a color swatch).
- artboard.new and artboard.setProps take guideLabel: null, a layer
  color's name, or #rrggbb. Any other value is an error. The inspect
  summary lists guideLabel when one is set.
- The native format saves the label and skips it when unset; a preset
  index outside the layer colors reads as no label.
- artboard.setProps no longer adds an undo step when nothing changes.

Docs: docs/mcp.md, docs/target-app-parity.md.
This commit is contained in:
dotCooCoo
2026-11-10 19:37:17 -08:00
parent 858b63082f
commit beef32b8a3
52 changed files with 557 additions and 14 deletions
+26
View File
@@ -56,4 +56,30 @@ impl LayerColor {
LayerColor::Custom(c) => c,
}
}
/// The color as text: a preset's name from [`LAYER_COLORS`], else `#rrggbb` (lowercase).
pub fn label_text(self) -> String {
let preset = match self {
LayerColor::Preset(i) => LAYER_COLORS.get(usize::from(i)),
LayerColor::Custom(_) => None,
};
preset.map_or_else(
|| {
let [r, g, b] = self.rgb();
format!("#{r:02x}{g:02x}{b:02x}")
},
|(name, _)| (*name).to_string(),
)
}
/// The color [`LayerColor::label_text`] names: a preset's name exactly as [`LAYER_COLORS`]
/// spells it, or `#rrggbb` with six hex digits. None for anything else.
pub fn from_label_text(s: &str) -> Option<Self> {
if let Some(i) = LAYER_COLORS.iter().position(|(name, _)| *name == s) {
return u8::try_from(i).ok().map(LayerColor::Preset);
}
let hex = s.strip_prefix('#').filter(|h| h.len() == 6 && h.bytes().all(|b| b.is_ascii_hexdigit()))?;
let byte = |k: usize| u8::from_str_radix(&hex[k..k + 2], 16).ok();
Some(LayerColor::Custom([byte(0)?, byte(2)?, byte(4)?]))
}
}