Graphic Styles: built-in library styles show in the UI language

List rows, tooltips and Find in a built-in graphic style library use
the translated style name, as brush libraries do. User Defined and
loaded libraries keep their style names, and clicks and commands still
use the stored name.
This commit is contained in:
dotCooCoo
2026-11-18 14:06:35 -08:00
parent b1b843a7fb
commit 324931ed04
2 changed files with 31 additions and 2 deletions
+8 -2
View File
@@ -920,10 +920,16 @@ impl LibraryKind for GraphicStyleLibraries {
fn path(app: &VectorcraftApp, id: &str) -> Option<String> {
app.session.style_libraries.path(id).map(str::to_string)
}
fn rows<'a>(lib: &'a Self::Lib, _: &str, query: &str) -> Vec<Row<'a, LibStyle>> {
let found = |n: &str| query.is_empty() || n.to_lowercase().contains(query);
/// Find matches a style's name as shown and as stored.
fn rows<'a>(lib: &'a Self::Lib, id: &str, query: &str) -> Vec<Row<'a, LibStyle>> {
let found = |n: &str| query.is_empty() || n.to_lowercase().contains(query) || Self::label(id, n).to_lowercase().contains(query);
lib.iter().filter(|s| found(&s.style().name)).map(|s| Row { name: &s.style().name, item: Some(s) }).collect()
}
/// A built-in library's style in the UI language; a User Defined or loaded library's style as
/// it is named.
fn label<'a>(id: &str, name: &'a str) -> &'a str {
super::label_or_name(name, STYLE_LIBRARIES.iter().any(|b| b.id == id))
}
/// The style on the Graphic Styles panel's preview shape.
fn draw(app: &VectorcraftApp, ui: &Ui, r: Rect, s: &LibStyle, selected: bool, hovered: bool) {
let paints = Paints { patterns: &s.lib.patterns, brushes: None };
@@ -143,6 +143,29 @@ fn paper_cutouts_opens_from_the_window_menu_and_applies_a_layered_style() {
assert_eq!(appearance.effects[0].id, "stylize.dropShadow");
}
/// A built-in library's list rows and Find field use the UI language; a user library's styles keep
/// their names, and clicks still name the stored style.
#[test]
fn built_in_style_names_show_in_the_ui_language() {
let mut app = app();
let ctx = context();
app.run("window.graphicStyleLibrary", json!({"library": "paper-cutouts"})).unwrap();
app.run("ui.libraryPanel", json!({"panel": "library:graphicStyles:paper-cutouts", "view": "largeList"})).unwrap();
crate::i18n::set_current(crate::i18n::Lang::from_code("fr").unwrap());
let mut texts = vec![];
for t in [0.0, 0.25] {
texts = frame(&ctx, vec![], Modifiers::NONE, t, |ui| library_panel::show_window(&mut app, ui.ctx()));
}
let (_, lib) = GraphicStyleLibraries::get(&app, "paper-cutouts").unwrap();
let found: Vec<&str> = GraphicStyleLibraries::rows(&lib, "paper-cutouts", "corail").iter().map(|r| r.name).collect();
let user = GraphicStyleLibraries::label("user/Mine", "Coral Layers").to_string();
crate::i18n::set_current(crate::i18n::Lang::EN);
assert!(texts.iter().any(|t| t == "Couches corail"), "{texts:?}");
assert!(!texts.iter().any(|t| t == "Coral Layers"), "{texts:?}");
assert_eq!(found, ["Coral Layers"]);
assert_eq!(user, "Coral Layers");
}
#[test]
fn the_window_menu_and_the_panel_open_every_library() {
let mut app = app();