forked from 1b-agent/opencadstudio-upstream
Select Color: built-in RAL CLASSIC and CSS COLORS color books
Two AutoCAD .acb books ship with the panel and are read the first time it opens in a session; a loaded book of the same name replaces them. RAL values are approximate (CC BY-SA 4.0, Wikipedia); sources and licences are in each file's header and assets/color_books/README.md. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_013rGmDUNr1hUf4zo1X3dak8
This commit is contained in:
5 files changed
+543
-8
No files matched your search
+16
-8
@@ -11731,21 +11731,29 @@ impl OpenCADStudio {
|
||||
(newest, true, name_of(newest_handle))
|
||||
}
|
||||
|
||||
/// Read the colour books remembered in the settings, once per session.
|
||||
/// 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.
|
||||
fn read_color_books(&mut self) {
|
||||
if std::mem::replace(&mut self.color_books_read, true) {
|
||||
return;
|
||||
}
|
||||
use crate::ui::color_select::book;
|
||||
#[cfg_attr(target_arch = "wasm32", allow(unused_mut))]
|
||||
let mut books: Vec<_> = book::builtin().collect();
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
for loaded in self
|
||||
.color_book_paths
|
||||
.iter()
|
||||
.filter_map(|path| std::fs::read_to_string(path).ok())
|
||||
.filter_map(|text| book::parse(&text).ok())
|
||||
{
|
||||
let books: Vec<_> = self
|
||||
.color_book_paths
|
||||
.iter()
|
||||
.filter_map(|path| std::fs::read_to_string(path).ok())
|
||||
.filter_map(|text| crate::ui::color_select::book::parse(&text).ok())
|
||||
.collect();
|
||||
self.color_books = std::sync::Arc::new(books);
|
||||
match books.iter_mut().find(|b| b.name == loaded.name) {
|
||||
Some(same) => *same = loaded,
|
||||
None => books.push(loaded),
|
||||
}
|
||||
}
|
||||
self.color_books = std::sync::Arc::new(books);
|
||||
}
|
||||
|
||||
/// Colour the selected objects (or set the current colour when nothing
|
||||
|
||||
@@ -57,6 +57,17 @@ impl ColorBook {
|
||||
}
|
||||
}
|
||||
|
||||
/// The colour books that ship with the program; their licences are in the
|
||||
/// files' header comments.
|
||||
pub fn builtin() -> impl Iterator<Item = ColorBook> {
|
||||
[
|
||||
include_str!("../../../assets/color_books/ral-classic.acb"),
|
||||
include_str!("../../../assets/color_books/css-colors.acb"),
|
||||
]
|
||||
.into_iter()
|
||||
.filter_map(|text| parse(text).ok())
|
||||
}
|
||||
|
||||
/// Read an `.acb` file's text.
|
||||
pub fn parse(text: &str) -> Result<ColorBook, String> {
|
||||
let doc = roxmltree::Document::parse(text.trim_start_matches('\u{feff}'))
|
||||
|
||||
Reference in new issue
Block a user