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 <[email protected]> Claude-Session: https://claude.ai/code/session_013rGmDUNr1hUf4zo1X3dak8
This commit is contained in:
6 files changed
+104
-86
No files matched your search
+5
-15
@@ -12004,17 +12004,10 @@ impl OpenCADStudio {
|
||||
}
|
||||
Message::ColorBookLoaded(Ok(book)) => {
|
||||
// A book loaded again replaces the earlier copy.
|
||||
let books = std::sync::Arc::make_mut(&mut self.color_books);
|
||||
let index = match books.iter().position(|b| b.name == book.name) {
|
||||
Some(index) => {
|
||||
books[index] = book;
|
||||
index
|
||||
}
|
||||
None => {
|
||||
books.push(book);
|
||||
books.len() - 1
|
||||
}
|
||||
};
|
||||
let index = crate::ui::color_select::book::add_or_replace(
|
||||
std::sync::Arc::make_mut(&mut self.color_books),
|
||||
book,
|
||||
);
|
||||
if let Some(picker) = self.color_picker.as_mut() {
|
||||
picker.show_book(std::sync::Arc::clone(&self.color_books), index);
|
||||
}
|
||||
@@ -12162,10 +12155,7 @@ impl OpenCADStudio {
|
||||
.filter_map(|path| std::fs::read_to_string(path).ok())
|
||||
.filter_map(|text| book::parse(&text).ok())
|
||||
{
|
||||
match books.iter_mut().find(|b| b.name == loaded.name) {
|
||||
Some(same) => *same = loaded,
|
||||
None => books.push(loaded),
|
||||
}
|
||||
book::add_or_replace(&mut books, loaded);
|
||||
}
|
||||
self.color_books = std::sync::Arc::new(books);
|
||||
}
|
||||
|
||||
+7
-17
@@ -1171,14 +1171,8 @@ impl OpenCADStudio {
|
||||
) {
|
||||
self.color_picker = None;
|
||||
|
||||
let rgb = match color {
|
||||
codec::types::Color::Rgb { r, g, b } => Some((r, g, b)),
|
||||
codec::types::Color::Index(index) => codec::types::aci_table::aci_to_rgb(index),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some((r, g, b)) = rgb {
|
||||
self.ps_color_buf = format!("#{r:02X}{g:02X}{b:02X}");
|
||||
if let Some((r, g, b)) = crate::ui::color_select::math::color_rgb(color) {
|
||||
self.ps_color_buf = crate::ui::color_select::math::hex_string(r, g, b);
|
||||
}
|
||||
|
||||
return self.on_plot_style_panel_apply();
|
||||
@@ -1191,15 +1185,11 @@ impl OpenCADStudio {
|
||||
)))
|
||||
}
|
||||
Some(crate::app::ColorPickTarget::ViewBackground(slot)) => {
|
||||
let rgb = match color {
|
||||
codec::types::Color::Rgb { r, g, b } => Some([r, g, b]),
|
||||
codec::types::Color::Index(index) => {
|
||||
codec::types::aci_table::aci_to_rgb(index).map(|(r, g, b)| [r, g, b])
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
rgb.map(|rgb| {
|
||||
Message::PdfDialog(crate::ui::window::pdf_dialogs::PdfDialogMsg::BgColor(slot, rgb))
|
||||
crate::ui::color_select::math::color_rgb(color).map(|(r, g, b)| {
|
||||
Message::PdfDialog(crate::ui::window::pdf_dialogs::PdfDialogMsg::BgColor(
|
||||
slot,
|
||||
[r, g, b],
|
||||
))
|
||||
})
|
||||
}
|
||||
Some(crate::app::ColorPickTarget::GraphicAttributesLine) => Some(
|
||||
|
||||
Reference in new issue
Block a user