Merge pull request #10479 from ruchirguitar/feat/color-themes-row-menu

Color Themes: add a context menu to saved theme rows
This commit is contained in:
BFlat authored and GitHub committed 2026-12-02 11:47:30 +07:00
commit f2f7727305
2 files changed
+80 -27

No files matched your search

+79 -27
View File
@@ -10,7 +10,7 @@
// framework crates' layout (racheck-fw); none of them is imported anywhere else in the app yet.
use std::borrow::Cow;
use craft::behavior::{DisplayOrder, IconId, ItemSource, Selection, SelectionChange};
use craft::behavior::{DisplayOrder, IconId, ItemSource, Selection, SelectionChange, keyed};
use craft::color_ui::ui::{ChannelRow, ColorPanelMode, HarmonyWheel};
use craft::theme::variant::Tone;
use craft::theme::{ModelValues, Rgba, Srgba};
@@ -19,7 +19,7 @@ use craft::ui::choice::{SwatchSpacing, SwatchTable};
use craft::ui::contract::{Bind, CollectionEvent, Entry, Props as _, Scroll, Show as _, ShowCollection as _, ShowContainer as _};
use craft::ui::layout_components::{Row, Stack};
use craft::ui::list::{List, ListRow, ThumbSize};
use craft::ui::menu::PanelRow;
use craft::ui::menu::{Menu, MenuItem, PanelRow};
use craft::ui::notices::Notice;
use craft::ui::pickers::Select;
use craft::ui::primitives::IconSpec;
@@ -592,44 +592,45 @@ fn my_themes(app: &mut VectorcraftApp, ui: &mut Ui) {
} else if rows.is_empty() {
Notice::new(Tone::Neutral, tl!("No matches.")).show(ui);
} else {
let names: Vec<String> = rows.iter().map(|(n, _)| n.clone()).collect();
let mut selection = app
.ui
.color_themes_panel
.picked
.as_ref()
.and_then(|p| names.iter().position(|n| n == p))
.map_or_else(Selection::default, Selection::single);
let out = List::new(tl!("My Themes")).select(craft::ui::contract::SelectMode::Single).selection(Bind::bound(&mut selection)).show_items(
ui,
&Names(&names),
&mut |key, _| {
let colors = rows.get(*key).map(|(_, c)| c.clone()).unwrap_or_default();
let name = names.get(*key).cloned().unwrap_or_default();
ListRow::new(name).thumb(ThumbSize::Small, move |cx, rect| {
let document = app.session.active().map(|st| st.uid);
let selection = picked(app).map_or_else(Selection::default, Selection::single);
let out = List::new(tl!("My Themes"))
.id(ui.scope_id().with(("my-themes", document)))
.select(craft::ui::contract::SelectMode::Single)
.selection(Bind::given(selection))
.row_menu()
.show_items(ui, &keyed(&rows, |(name, _)| name.clone()), &mut |name, icx| {
let colors = rows[icx.at].1.clone();
ListRow::new(name.clone()).thumb(ThumbSize::Small, move |cx, rect| {
let w = rect.width() / colors.len().max(1) as f32;
cx.data_shapes(colors.iter().enumerate().map(|(i, c)| {
egui::Shape::rect_filled(Rect::from_min_size(rect.min + vec2(i as f32 * w, 0.0), vec2(w, rect.height())), 0.0, c32(c))
}));
})
},
);
});
for event in out.events {
match event {
CollectionEvent::Selection { change: SelectionChange::Set(keys), .. } => {
if let Some(name) = keys.last().and_then(|k| names.get(*k)) {
app.ui.color_themes_panel.picked = Some(name.clone());
}
app.ui.color_themes_panel.picked = keys.last().cloned();
}
CollectionEvent::ContextMenu(request) => app.ui.color_themes_panel.picked = Some(request.key),
// Enter and a double click edit the theme.
CollectionEvent::Activate(key) => {
if let Some(name) = names.get(key) {
edit_saved(app, name);
}
}
CollectionEvent::Activate(name) => edit_saved(app, &name),
_ => {}
}
}
if let Some(request) = out.menu
&& app.ui.color_themes_panel.tab == MY_THEMES
&& app.ui.color_themes_panel.picked.as_ref() == Some(&request.key)
{
Menu::context(request.key, &out.response).show(ui, |ui, _| {
for (id, label) in [(EDIT, tl!("Edit Theme")), (ADD_TO_SWATCHES, tl!("Add to Swatches")), (DELETE, tl!("Delete Theme"))] {
if MenuItem::new(label).enabled(enabled(app, id)).show(ui).ran {
run(app, id, &Value::Null);
}
}
});
}
}
let labels = vec![Label::from(tl!("Delete theme")), Label::from(tl!("Add to Swatches")), Label::from(tl!("Edit theme"))];
footer(app, ui, &[DELETE, ADD_TO_SWATCHES, EDIT], &["trash-2", "dc-folder", "pencil"], labels);
@@ -831,6 +832,57 @@ mod tests {
assert_eq!(picked(&app), None);
}
#[test]
fn the_theme_menu_follows_its_row_when_the_list_is_filtered() {
use crate::tests::panel_harness::Panel;
let mut app = three_themes("");
app.ui.color_themes_panel.picked = Some("Forest".into());
let mut panel = Panel::new(app, show);
panel.secondary_click("Harvest");
assert_eq!(picked(&panel.app()).as_deref(), Some("Harvest"));
panel.app().ui.color_themes_panel.find = "vest".into();
panel.frame();
panel.click_menu_item("Delete Theme");
assert_eq!(themes(&panel.app()).iter().map(|t| t.name.as_str()).collect::<Vec<_>>(), ["Harbor", "Forest"]);
}
#[test]
fn keyboard_theme_menu_uses_the_focused_row_without_a_document() {
use crate::tests::panel_harness::Panel;
let mut app = three_themes("");
assert!(app.session.close_document(0));
let mut panel = Panel::new(app, show);
panel.click("Forest");
panel.key(egui::Key::F10, egui::Modifiers::SHIFT);
panel.frame();
assert!(panel.menu_item_enabled("Edit Theme"));
assert!(panel.menu_item_enabled("Delete Theme"));
assert!(!panel.menu_item_enabled("Add to Swatches"));
panel.key(egui::Key::Escape, egui::Modifiers::NONE);
panel.frame();
assert!(!panel.shows_role("Edit Theme", Role::MENU_ITEM));
assert!(panel.focused("Forest"));
}
#[test]
fn the_theme_menu_closes_when_its_row_disappears_or_the_document_changes() {
use crate::tests::panel_harness::Panel;
let mut panel = Panel::new(three_themes(""), show);
panel.secondary_click("Harbor");
assert!(panel.menu_item_enabled("Edit Theme"));
panel.app().ui.color_themes_panel.find = "Forest".into();
panel.frame();
assert!(!panel.shows_role("Edit Theme", Role::MENU_ITEM));
panel.secondary_click("Forest");
assert!(panel.menu_item_enabled("Add to Swatches"));
panel.app().run("file.new", json!({"width": 300, "height": 200})).unwrap();
panel.frame();
assert!(!panel.shows_role("Add to Swatches", Role::MENU_ITEM));
}
/// 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]
+1
View File
@@ -2207,6 +2207,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
- **Coated CMYK (FOGRA51) and Uncoated CMYK (FOGRA52):** VectorCraft's own press models, computed when first used from the characterization data Fogra publishes (<https://fogra.org/en/downloads/work-tools/characterisation-data>), which ships unmodified: the measured paper, solids and overprints, a tone curve fitted to each ink's ramp, and a smoothed Lab correction lattice fitted to all 1,617 patches. The models reproduce the patches within a mean ΔE2000 of 0.04 (largest 0.37), and patches left out of the fit within 0.15 to 0.17 (largest 1.67). A PDF/X output intent made with one embeds the profile; with the condition identifier left blank it names `FOGRA51` or `FOGRA52`, in the `http://www.color.org` registry unless the settings give a registry, and an identifier the settings give is written as given. The 300% ink limit and black generation are VectorCraft's own values.
- **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`.
- **My Themes row menu:** Opening a saved theme's row menu selects it and offers Edit Theme, Add to Swatches and Delete Theme. Add to Swatches requires an active document.
- **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`.
- **Color Themes sliders:** on the Color Themes panel's Create tab, a Color Mode menu (CMYK, RGB, Lab and HSB) shows a rail and a number field for each component of the selected theme color, beside its hex field; the [help page](https://web.archive.org/web/20210601162814/https://helpx.adobe.com/pdf/illustrator_reference.pdf#page=221) describes changing the selected color's values in these color systems or as hex while making a theme. VectorCraft's own rules: the menu starts in the selected color's own model (HSB for a gray) and keeps the mode picked while the app runs; picking a mode changes no color; the ranges and whole-number steps are the Color panel's (Lab a and b from -128 to 127), a number past the range sets its end and text that is not a number changes nothing; a CMYK edit keeps the color CMYK and a Lab edit keeps it Lab, while RGB and HSB edits make it RGB, and the theme saves and goes to Swatches in those models; an edit works as a hex edit does: with a harmony rule the edited color becomes the theme's base and is selected, and in Custom only the selected color changes. Tests: `the_create_tab_offers_cmyk_rgb_lab_and_hsb_sliders`, `a_slider_edit_changes_only_the_selected_custom_color`, `the_sliders_keep_the_numbers_they_set`, `with_a_rule_a_slider_edit_rebuilds_the_theme_from_the_edited_color` and `cmyk_and_lab_slider_edits_keep_their_models` 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.