mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Gradient: the stop popover remembers a click on the swatch it already shows
A click on the swatch shown as the stop's, when it changes no paint, was dropped, so the popover did not remember it. With two process swatches of one color, moving the other one before it then moved the selection. The click now stores the pick and leaves the paint as it is.
This commit is contained in:
1 parent
a34cb72f8b
commit
728a0b673e
1 file changed
+30
-4
@@ -376,6 +376,8 @@ struct Feed {
|
||||
struct Filed {
|
||||
fields: PopoverFields,
|
||||
swatch: Option<(String, Color)>,
|
||||
/// Whether the pending swatch pick applies paint.
|
||||
swatch_changes_paints: bool,
|
||||
eyedropper: bool,
|
||||
panels: Vec<ColorPanelOutput>,
|
||||
/// Only an actual Shift-cycle changes this; an unchanged local snapshot must not overwrite a menu command.
|
||||
@@ -575,12 +577,13 @@ fn swatches(ui: &mut Ui, feed: &Feed, filed: &mut Filed) {
|
||||
// the same colour, such as a spot ink an unlinked stop has the colour of, is not.
|
||||
let shown =
|
||||
SwatchPalette::new("Swatches", Bind::given(feed.current), &feed.tiles).selected_swatch(feed.selected_swatch).select_by_color(false).show(ui);
|
||||
// A click on the displayed swatch applies only when an edited paint differs at this stop or point.
|
||||
// Every click remembers the pick. The displayed swatch applies only when an edited paint differs at this stop or point.
|
||||
// Other swatches apply even when they have the same color.
|
||||
if let Some(swatch) =
|
||||
shown.picked_swatch.filter(|i| feed.displayed_swatch_changes_paints || Some(*i) != feed.selected_swatch).and_then(|i| feed.swatches.get(i))
|
||||
if let Some(i) = shown.picked_swatch
|
||||
&& let Some(swatch) = feed.swatches.get(i)
|
||||
{
|
||||
filed.swatch = Some(swatch.clone());
|
||||
filed.swatch_changes_paints = feed.displayed_swatch_changes_paints || Some(i) != feed.selected_swatch;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -789,7 +792,9 @@ pub(crate) fn pump(app: &mut VectorcraftApp, ctx: &egui::Context) {
|
||||
if let Some((name, color)) = filed.swatch
|
||||
&& let Some(target) = selected(app)
|
||||
{
|
||||
pick_swatch(app, &target, &name, color);
|
||||
if filed.swatch_changes_paints {
|
||||
pick_swatch(app, &target, &name, color);
|
||||
}
|
||||
// Swatches of one colour draw alike: the Swatches view shows the one picked, not the first of them.
|
||||
let picked = selected(app).and_then(|target| PickedSwatch::of(app, &target, &name));
|
||||
dialogs.with(|host| {
|
||||
@@ -1016,6 +1021,27 @@ mod tests {
|
||||
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo, "the same colour again is no edit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_swatches_view_remembers_a_pick_of_the_fallback_swatch_after_reordering() {
|
||||
let mut app = app();
|
||||
for name in ["First teal", "Second teal"] {
|
||||
app.run("swatch.new", json!({"name": name, "color": "#008080"})).unwrap();
|
||||
}
|
||||
crate::panels::gradient::recolor_selected(&mut app, Color::from_hex("#008080").unwrap(), &json!({}));
|
||||
let mut panel = swatches_view(app);
|
||||
assert_eq!(shown_swatch(&mut panel).as_deref(), Some("First teal"), "the first matching process swatch is the fallback");
|
||||
let undo = panel.app().session.active().unwrap().history.undo.len();
|
||||
panel.click("First teal");
|
||||
assert_eq!(panel.app().session.active().unwrap().history.undo.len(), undo, "the displayed swatch changes no paint");
|
||||
let first = panel.app().session.active().unwrap().doc.swatches_iter().position(|s| s.name == "First teal").unwrap();
|
||||
panel.app().run("swatch.move", json!({"name": "Second teal", "to": first})).unwrap();
|
||||
assert_eq!(
|
||||
shown_swatch(&mut panel).as_deref(),
|
||||
Some("First teal"),
|
||||
"the explicit pick stays selected after the other swatch moves before it"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_swatches_view_keeps_the_picked_process_swatch_through_a_rename() {
|
||||
let mut app = app();
|
||||
|
||||
Reference in new issue
Block a user