forked from 1b-agent/opencadstudio-upstream
Select Color: reuse helpers instead of repeated code
- book::add_or_replace adds a colour book or replaces one of the same name, for both reading the folders and loading a file. - style.rs: the Plot Style and View Background colour targets use math::color_rgb (and hex_string) instead of their own conversions. - Ribbon: one layer_color lookup for Ribbon::active_layer_color and the ribbon's ByLayer swatch. - Picker: one swatch() for the Index and Document swatches, fill_of() for "colour or gray" and divider() for the 1 px separators. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013rGmDUNr1hUf4zo1X3dak8
This commit is contained in:
6 files changed
+104
-86
No files matched your search
@@ -148,6 +148,14 @@ pub struct LayerInfo {
|
||||
pub vp_frozen: Option<(usize, bool)>,
|
||||
}
|
||||
|
||||
/// The colour of layer `name` in the ribbon's layer list.
|
||||
pub(super) fn layer_color(layers: &[LayerInfo], name: &str) -> Option<Color> {
|
||||
layers
|
||||
.iter()
|
||||
.find(|layer| layer.name == name)
|
||||
.map(|layer| layer.color)
|
||||
}
|
||||
|
||||
/// Full-screen backdrop for an open ribbon dropdown: closes the dropdown when
|
||||
/// the user clicks outside the panel. (Cursor motion leaking to the viewport
|
||||
/// beneath is blocked in `on_viewport_move`, not here — iced 0.14's mouse_area
|
||||
@@ -188,10 +196,7 @@ fn position_ribbon_dropdown<'a>(
|
||||
impl Ribbon {
|
||||
/// The current layer's colour: what ByLayer looks like for new objects.
|
||||
pub fn active_layer_color(&self) -> Option<Color> {
|
||||
self.layer_infos
|
||||
.iter()
|
||||
.find(|layer| layer.name == self.active_layer)
|
||||
.map(|layer| layer.color)
|
||||
layer_color(&self.layer_infos, &self.active_layer)
|
||||
}
|
||||
|
||||
/// The colour-book identity of the active colour, while the active colour
|
||||
|
||||
@@ -1174,11 +1174,9 @@ pub(super) fn render_large<'a>(item: &RibbonItem, ctx: &RenderCtx<'_>) -> Elemen
|
||||
};
|
||||
|
||||
// ByLayer shows the current layer's colour.
|
||||
let color_swatch = layer_infos
|
||||
.iter()
|
||||
.find(|layer| layer.name == active_layer)
|
||||
let color_swatch = super::layer_color(layer_infos, active_layer)
|
||||
.filter(|_| active_color == AcadColor::ByLayer)
|
||||
.map_or_else(|| acad_color_display(active_color).0, |layer| layer.color);
|
||||
.unwrap_or_else(|| acad_color_display(active_color).0);
|
||||
let color_row = prop_row(
|
||||
crate::ui::color_select::color_display_name(active_color),
|
||||
PROP_COLOR_ID,
|
||||
|
||||
Reference in new issue
Block a user