Color Themes: Show Find Field lists My Themes by theme name

On the My Themes tab, the panel menu has a checked Show Find Field item
that shows a Find field above the list. The list then shows only the
saved themes whose names hold the field's text, anywhere and in any
letter case, in their saved order; colors are not searched, and a
search with no result shows "No matches.". A picked theme the field
hides stays picked, but Edit Theme, Add to Swatches and Delete Theme
are off until the list shows it again. The field is off in a new
session and does not change the saved themes or colorTheme.list.

The help page describes searching saved themes by name this way:
https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=255
This commit is contained in:
dotCooCoo
2026-11-17 15:58:21 -08:00
parent 8cc5f194c8
commit 9ed14dd264
2 changed files with 210 additions and 4 deletions
+209 -4
View File
@@ -1,6 +1,7 @@
//! Color Themes panel (local only): the Create tab makes a five-colour theme on a harmony wheel (a
//! harmony rule from the selected colour, or Custom: each colour moves on its own; with a rule the
//! colours move together), the My Themes tab lists the themes saved in the preferences. Themes are
//! colours move together), the My Themes tab lists the themes saved in the preferences (the panel
//! menu's Show Find Field adds a field that lists only the themes whose names hold its text). Themes are
//! saved, edited, deleted and added to Swatches as colour groups through `colorTheme.*`; the theme
//! being made is panel state.
@@ -90,9 +91,35 @@ fn set_draft(ctx: &egui::Context, d: Draft) {
set_pstate(ctx, "ct-draft", Some(d));
}
/// The saved theme picked on the My Themes tab.
/// The saved theme picked on the My Themes tab, while the list shows it: a theme that the find
/// field hides stays picked, but nothing acts on it until the list shows it again.
fn picked(app: &VectorcraftApp, ctx: &egui::Context) -> Option<String> {
pstate::<Option<String>>(ctx, "ct-picked").filter(|n| app.session.prefs.color_themes.iter().any(|t| t.name == *n))
let q = query(ctx);
pstate::<Option<String>>(ctx, "ct-picked").filter(|n| app.session.prefs.color_themes.iter().any(|t| t.name == *n && matches(&t.name, &q)))
}
/// The My Themes find field's text, kept while the panel menu hides the field.
fn find_id() -> egui::Id {
egui::Id::unique("ct-find")
}
/// Whether the panel menu's Show Find Field shows the find field (off in a new session).
fn show_find(ctx: &egui::Context) -> bool {
pstate(ctx, "ct-show-find")
}
/// The find field's text, trimmed and lowercased; empty while the field is hidden.
fn query(ctx: &egui::Context) -> String {
if !show_find(ctx) {
return String::new();
}
ctx.data(|d| d.get_temp::<String>(find_id())).unwrap_or_default().trim().to_lowercase()
}
/// Whether the find field lists theme `name` for `query` (trimmed and lowercased): its name holds
/// the text anywhere, in any letter case. An empty query lists every theme.
fn matches(name: &str, query: &str) -> bool {
query.is_empty() || name.to_lowercase().contains(query)
}
/// The tab shown: 0 Create, 1 My Themes.
@@ -257,6 +284,12 @@ enum Action {
fn my_themes(app: &mut VectorcraftApp, ui: &mut Ui) {
let t = Tokens::get(ui.ctx());
let ctx = ui.ctx().clone();
// The find field lists the saved themes whose names hold its text, in their saved order.
if show_find(&ctx) {
widgets::search_field(ui, find_id(), tl!("Find"));
ui.add_space(4.0);
}
let q = query(&ctx);
let pick = picked(app, &ctx);
let mut action = None;
if app.session.prefs.color_themes.is_empty() {
@@ -264,7 +297,11 @@ fn my_themes(app: &mut VectorcraftApp, ui: &mut Ui) {
} else {
widgets::list_box(ui, |ui| {
egui::ScrollArea::vertical().id_salt("ct-list").max_height(300.0).auto_shrink([false, true]).show(ui, |ui| {
for th in &app.session.prefs.color_themes {
let mut shown = app.session.prefs.color_themes.iter().filter(|th| matches(&th.name, &q)).peekable();
if shown.peek().is_none() {
widgets::dim_label(ui, tl!("No matches."));
}
for th in shown {
let (r, _) = ui.allocate_exact_size(vec2(ui.available_width(), 44.0), Sense::hover());
let resp = ui.interact(r, ui.scope_id().with(("ct-theme", &th.name)), Sense::click());
let selected = pick.as_deref() == Some(th.name.as_str());
@@ -356,6 +393,11 @@ pub fn menu(app: &mut VectorcraftApp, ui: &mut Ui) {
{
delete(app, &ctx, n);
}
ui.separator();
let find = show_find(&ctx);
if menu_item(ui, tl!("Show Find Field"), true, find) {
set_pstate(&ctx, "ct-show-find", !find);
}
} else {
if menu_item(ui, tl!("Save Theme"), true, false) {
save(app, &ctx);
@@ -470,6 +512,169 @@ mod tests {
frame(&mut app, &ctx);
}
/// The texts one frame draws: the panel, or with `menu_only` its panel menu, with `events`.
fn drawn(app: &mut VectorcraftApp, ctx: &egui::Context, menu_only: bool, events: Vec<egui::Event>) -> Vec<(String, Rect)> {
crate::i18n::set_current(crate::i18n::Lang::EN);
let screen = Rect::from_min_size(egui::Pos2::ZERO, vec2(320.0, 700.0));
let input = egui::RawInput { events, screen_rect: Some(screen), ..Default::default() };
let mut out = ctx.run_ui(input, |ui| if menu_only { menu(app, ui) } else { show(app, ui) });
out.textures_delta.clear();
fn texts(s: &egui::Shape, out: &mut Vec<(String, Rect)>) {
match s {
egui::Shape::Text(t) => out.push((t.galley.text().to_string(), t.visual_bounding_rect())),
egui::Shape::Vec(v) => v.iter().for_each(|s| texts(s, out)),
_ => {}
}
}
let mut found = vec![];
out.shapes.iter().for_each(|s| texts(&s.shape, &mut found));
found
}
/// The saved themes the My Themes list draws, in order.
fn listed(app: &mut VectorcraftApp, ctx: &egui::Context) -> Vec<String> {
drawn(app, ctx, false, vec![]);
let names: Vec<String> = themes(app).iter().map(|t| t.name.clone()).collect();
drawn(app, ctx, false, vec![]).into_iter().map(|(t, _)| t).filter(|t| names.contains(t)).collect()
}
/// Click panel menu item `label` (with its check mark, or three spaces when unchecked).
fn click_menu(app: &mut VectorcraftApp, ctx: &egui::Context, label: &str) {
let texts = drawn(app, ctx, true, vec![]);
let at = texts.iter().find(|(t, _)| t == label).unwrap_or_else(|| panic!("no {label:?} in {texts:?}")).1.center();
let button =
|pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE };
drawn(app, ctx, true, vec![egui::Event::PointerMoved(at), button(true), button(false)]);
}
/// My Themes with three saved themes and the find field holding `text`.
fn three_themes(text: &str) -> (VectorcraftApp, egui::Context) {
let mut app = app();
for (name, color) in [("Harbor", "#2266aa"), ("Harvest", "#cc8822"), ("Forest", "#227744")] {
app.run("colorTheme.save", json!({"color": color, "rule": "complementary", "name": name})).unwrap();
}
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
set_pstate(&ctx, "ct-tab", 1usize);
set_pstate(&ctx, "ct-show-find", true);
ctx.data_mut(|d| d.insert_temp(find_id(), text.to_string()));
(app, ctx)
}
/// Show Find Field is a checked item of the My Themes menu only, off in a new session; each
/// choice turns the field on or off.
#[test]
fn show_find_field_toggles_the_find_field_on_my_themes() {
let mut app = app();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
let has = |texts: &[(String, Rect)], label: &str| texts.iter().any(|(t, _)| t == label);
let texts = drawn(&mut app, &ctx, true, vec![]);
assert!(!has(&texts, " Show Find Field") && !has(&texts, "✓ Show Find Field"), "the Create tab has no find field");
set_pstate(&ctx, "ct-tab", 1usize);
assert!(has(&drawn(&mut app, &ctx, true, vec![]), " Show Find Field"), "off in a new session");
assert!(!has(&drawn(&mut app, &ctx, false, vec![]), "Find"), "no field while it is off");
click_menu(&mut app, &ctx, " Show Find Field");
assert!(show_find(&ctx));
assert!(has(&drawn(&mut app, &ctx, true, vec![]), "✓ Show Find Field"));
assert!(has(&drawn(&mut app, &ctx, false, vec![]), "Find"), "the field shows its hint");
click_menu(&mut app, &ctx, "✓ Show Find Field");
assert!(!show_find(&ctx));
}
/// The find field lists the themes whose names hold its text, in any letter case, anywhere in
/// the name, in their saved order; it reads names only, and its text is plain text.
#[test]
fn the_find_field_lists_themes_whose_names_hold_its_text() {
let (mut app, ctx) = three_themes(" HAR ");
assert_eq!(listed(&mut app, &ctx), ["Harbor", "Harvest"]);
ctx.data_mut(|d| d.insert_temp(find_id(), "vest".to_string()));
assert_eq!(listed(&mut app, &ctx), ["Harvest"], "a match in the middle of a name");
// Colours are not searched: no name holds "2266aa".
ctx.data_mut(|d| d.insert_temp(find_id(), "2266aa".to_string()));
assert!(listed(&mut app, &ctx).is_empty());
assert!(drawn(&mut app, &ctx, false, vec![]).iter().any(|(t, _)| t == "No matches."));
assert_eq!(themes(&app).len(), 3, "the saved themes stay");
// Pattern characters are plain text, and letters outside ASCII match in either case.
app.run("colorTheme.save", json!({"color": "#aa2266", "rule": "complementary", "name": "Été a.b*"})).unwrap();
ctx.data_mut(|d| d.insert_temp(find_id(), "ÉTÉ A.B*".to_string()));
assert_eq!(listed(&mut app, &ctx), ["Été a.b*"]);
ctx.data_mut(|d| d.insert_temp(find_id(), ".*".to_string()));
assert!(listed(&mut app, &ctx).is_empty());
// Blank text, or the field turned off, lists every theme; turned on again the text applies.
ctx.data_mut(|d| d.insert_temp(find_id(), " ".to_string()));
assert_eq!(listed(&mut app, &ctx).len(), 4);
ctx.data_mut(|d| d.insert_temp(find_id(), "har".to_string()));
set_pstate(&ctx, "ct-show-find", false);
assert_eq!(listed(&mut app, &ctx).len(), 4);
set_pstate(&ctx, "ct-show-find", true);
assert_eq!(listed(&mut app, &ctx), ["Harbor", "Harvest"]);
}
/// With no saved themes the panel says so, whatever the find field holds.
#[test]
fn no_saved_themes_is_not_no_matches() {
let mut app = app();
let ctx = egui::Context::default();
crate::theme::install_fonts(&ctx);
set_pstate(&ctx, "ct-tab", 1usize);
set_pstate(&ctx, "ct-show-find", true);
ctx.data_mut(|d| d.insert_temp(find_id(), "har".to_string()));
drawn(&mut app, &ctx, false, vec![]);
let texts: Vec<String> = drawn(&mut app, &ctx, false, vec![]).into_iter().map(|(t, _)| t).collect();
assert!(texts.iter().any(|t| t == "No saved themes"), "{texts:?}");
assert!(!texts.iter().any(|t| t == "No matches."));
}
/// A picked theme that the find field hides stays picked, but neither the menu nor the footer
/// acts on it until the list shows it again.
#[test]
fn a_theme_the_find_field_hides_is_not_acted_on() {
let (mut app, ctx) = three_themes("har");
set_pstate(&ctx, "ct-picked", Some("Forest".to_string()));
assert_eq!(picked(&app, &ctx), None);
drawn(&mut app, &ctx, true, vec![]);
click_menu(&mut app, &ctx, " Delete Theme");
assert_eq!(themes(&app).len(), 3, "Delete Theme is off");
click_menu(&mut app, &ctx, " Edit Theme");
assert_eq!(tab(&ctx), 1, "Edit Theme is off");
let undo = undo_len(&app);
click_menu(&mut app, &ctx, " Add to Swatches");
assert_eq!(undo_len(&app), undo, "Add to Swatches is off");
// Cleared, the field lists Forest again and it is picked as before.
ctx.data_mut(|d| d.insert_temp(find_id(), String::new()));
assert_eq!(picked(&app, &ctx).as_deref(), Some("Forest"));
ctx.data_mut(|d| d.insert_temp(find_id(), "har".to_string()));
set_pstate(&ctx, "ct-show-find", false);
assert_eq!(picked(&app, &ctx).as_deref(), Some("Forest"), "the field turned off lists it too");
set_pstate(&ctx, "ct-show-find", true);
// A theme the field shows is acted on.
set_pstate(&ctx, "ct-picked", Some("Harvest".to_string()));
click_menu(&mut app, &ctx, " Delete Theme");
assert_eq!(themes(&app).iter().map(|t| t.name.as_str()).collect::<Vec<_>>(), ["Harbor", "Forest"]);
}
/// The footer buttons are off for a picked theme that the find field hides.
#[test]
fn footer_buttons_are_off_for_a_hidden_pick() {
use crate::widgets::accessibility_tests::{named, tree};
let mut app = app();
app.run("colorTheme.save", json!({"color": "#227744", "rule": "complementary", "name": "Forest"})).unwrap();
for (text, off) in [("har", true), ("for", false)] {
let shown = tree(|ui| {
let ctx = ui.ctx().clone();
set_pstate(&ctx, "ct-tab", 1usize);
set_pstate(&ctx, "ct-show-find", true);
set_pstate(&ctx, "ct-picked", Some("Forest".to_string()));
ctx.data_mut(|d| d.insert_temp(find_id(), text.to_string()));
show(&mut app, ui);
});
for label in ["Edit theme", "Add to Swatches", "Delete theme"] {
assert_eq!(named(&shown, label).is_disabled(), off, "{label} with {text:?}");
}
}
}
const SET_ACTIVE: &str = "Set the current fill or stroke to the selected color";
/// A click on the panel button that screen readers name `label`. egui finds what the pointer is
+1
View File
@@ -1777,6 +1777,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Generic CMYK (SWOP-like):** each ink's 40% and 50% tints gain as [CGATS TR 001](https://registry.color.org/cmyk-registry/cgats_tr_001) gives for SWOP printing, and separations stay within SWOP's [300% total ink limit](https://en.wikipedia.org/wiki/Specifications_for_Web_Offset_Publications). The paper, solid and overprint colors, the black-generation curve and the black point are VectorCraft's own values: RGB black separates to 90% black under neutral cyan, magenta and yellow that fill the ink limit (C75 M68 Y67 K90).
- **Swatches made from a shown color in a CMYK document:** the Color panel menu's Create New Swatch, an Alt-click on the Swatches panel's New Swatch button, the New Swatch dialog for a gradient, a Fill or Stroke proxy or the Gradient panel's thumbnail dropped on the Swatches panel (or Alt-dropped on a swatch of its kind), and the Gradient panel's Add to Swatches and Save to Swatches keep each color's model, as the Color Guide's and Color Themes' saved colors do: an RGB object's color gives an RGB swatch, and a gradient's RGB stops stay RGB.
- **Color Themes Set Active Color:** a button on the Color Themes panel's Create tab makes the selected theme color the current color, the action the [help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=222) describes for creating a color theme. VectorCraft's own rules: the color goes to the proxy in front (Fill or Stroke), on the selection and the default for new art, in its own color model, through `paint.setFill` or `paint.setStroke`; with characters selected with the Type tool, only those characters take it and the default for new art stays as it was, as with a swatch click; a click is one undo step, a click that changes no art adds none, and the button is off without a document. Tests: `set_active_color_*` in `crates/ui-egui/src/panels/color_themes.rs`.
- **Color Themes find field:** on the Color Themes panel's My Themes tab, Show Find Field in the panel menu shows a Find field that lists only the saved themes whose names hold its text; the [help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=255) describes looking up a saved theme by its name this way (printed page 249). VectorCraft's own rules: the menu item is checked while the field shows and is off in a new session; a name matches when it holds the text anywhere, in any letter case, with spaces at either end of the text ignored; colors are not searched; the list keeps its saved order and shows No matches. when nothing matches; a picked theme the field hides stays picked, but Edit Theme, Add to Swatches and Delete Theme are off until the list shows it again; turning the field off lists every theme, and turning it on again in the same session restores its text. The field does not change the saved themes or `colorTheme.list`. Tests: `show_find_field_toggles_the_find_field_on_my_themes`, `the_find_field_lists_themes_whose_names_hold_its_text`, `no_saved_themes_is_not_no_matches`, `a_theme_the_find_field_hides_is_not_acted_on` and `footer_buttons_are_off_for_a_hidden_pick` in `crates/ui-egui/src/panels/color_themes.rs`.
- **Sample Color from Screen:** an eyedropper button in the Color Picker and `ui.sampleScreenColor` (which can be given a key in Keyboard Shortcuts) pick a color anywhere on the screen with the system's sampler: `NSColorSampler` on macOS, the XDG desktop portal's [PickColor](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Screenshot.html) on Linux, a still copy of every monitor under a crosshair on Windows, and the EyeDropper API in browsers that have it. The color becomes the fill or the stroke as one undo step, or the Color Picker's color, converted from display sRGB into the working RGB space. On Linux, a session without a portal that has PickColor, a portal that does not return from the call within 25 seconds (VectorCraft's own limit) or leaves the bus before it answers, and a portal that ends the request another way each show a status message and end the wait. On Windows, the copy is read as sRGB, so the colors of HDR and wide-gamut displays are not converted; Escape, a click of another mouse button or switching to another window cancels (VectorCraft's own rules). The BSDs and other browsers have no sampler yet; the button is gray there.
- **Color Guide color groups:** with variation cells selected, the Color Guide's Save Color Group to Swatches button saves those cells as one swatch group, and with none selected it saves the harmony colors, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes saving several selected variations together (printed page 135). The group takes the cells in grid order (row by row, left to right, each cell once), is named after the harmony rule and is one undo step; these are VectorCraft's own rules. A selection lasts until the base, the Color Guide Options, the variation mode, the harmony rule, the library limit or the colors the grid shows (for example after a new swatch while the guide is limited to the document's swatches) change.
- **Color Guide colors dragged to Swatches:** a variation cell dragged from the Color Guide onto the Swatches panel's list becomes a swatch of that color, as the [help page](https://help.adobe.com/archive/en_US/illustrator/cs5/illustrator_cs5_help.pdf) describes for saving variations as individual swatches (printed page 135). In VectorCraft a harmony strip color drags the same way, a drag carries only the grabbed color (the selected cells stay selected and the selection is not saved), it carries the color the cell shows (snapped to the Limit to Library colors), keeps the color's model and does not paint the selected art; the swatch follows the panel's rules for a dropped color (`swatch.new`, one undo step, a color that is already a swatch is added again under another name, a drop on a color group joins it). These are VectorCraft's own rules. Tests: `a_dragged_guide_color_carries_its_color_and_applies_nothing` and `a_guide_color_dragged_onto_the_swatches_panel_becomes_a_swatch` in `crates/ui-egui/src/panels/color_guide.rs`.