Select Color and ribbon: ByLayer shows the layer's colour

ByLayer swatches were always gray. The Select Color panel's Current/New
band and info line now show the colour of the layer the colour is for
(the newest selected object's layer, or the current layer for new
objects); the ribbon's colour control and the ByLayer row of its colour
dropdown show the current layer's colour.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013rGmDUNr1hUf4zo1X3dak8
This commit is contained in:
Claude committed 2026-10-14 14:50:58 +00:00
1 parent 652aa61b22
commit 5a296ad48c
5 files changed
+79 -12

No files matched your search

+25
View File
@@ -11563,12 +11563,14 @@ impl OpenCADStudio {
let mut picker = crate::ui::color_select::ColorPicker::new(target, current, varies);
if !matches!(picker.target, crate::app::ColorPickTarget::Interface(_)) {
self.read_color_books();
let by_layer = self.color_picker_layer_color(&picker.target);
let tab = &self.tabs[self.active_tab];
picker = picker.with_drawing(
crate::ui::color_select::document::collect(&tab.scene.document),
&tab.recent_colors,
std::sync::Arc::clone(&self.color_books),
name,
by_layer,
);
}
self.color_picker = Some(picker);
@@ -11734,6 +11736,29 @@ impl OpenCADStudio {
(newest, true, name_of(newest_handle))
}
/// The colour ByLayer stands for in the Select Color panel: the layer of
/// the newest selected object, or the current layer for new objects.
fn color_picker_layer_color(
&self,
target: &crate::app::ColorPickTarget,
) -> Option<codec::types::Color> {
let i = self.active_tab;
let document = &self.tabs[i].scene.document;
let layer = match target {
crate::app::ColorPickTarget::Properties => self
.property_target_handles(i)
.into_iter()
.max()
.and_then(|handle| document.get_entity(handle))
.map_or(self.tabs[i].active_layer.as_str(), |entity| {
entity.as_entity().layer()
}),
crate::app::ColorPickTarget::Ribbon => self.tabs[i].active_layer.as_str(),
_ => return None,
};
document.layers.get(layer).map(|layer| layer.color)
}
/// Read the built-in colour books and the ones remembered in the
/// settings, once per session. A loaded book replaces a built-in one of
/// the same name.