diff --git a/crates/ui-egui/src/dialogs/recolor.rs b/crates/ui-egui/src/dialogs/recolor.rs index ffb251c3e9..08656f9913 100644 --- a/crates/ui-egui/src/dialogs/recolor.rs +++ b/crates/ui-egui/src/dialogs/recolor.rs @@ -412,13 +412,13 @@ fn group_colors<'a>(app: &VectorcraftApp, d: &Dialog, rs: impl Iterator = match which { "prominent" => prominent_parts(d, &rs).into_iter().map(|p| p.0).collect(), - _ => (0..rs.len()).filter(|&i| !excluded(&rs[i])).collect(), + _ => (0..rs.len()).filter(|&i| !excluded(&rs[i]) && to_color(&rs[i]).is_some()).collect(), }; let colors = group_colors(app, d, order.iter().filter_map(|&i| rs.get(i))); if colors.is_empty() { @@ -823,7 +823,7 @@ fn confirm(app: &mut VectorcraftApp, d: &Dialog) -> Result { sync_theme(app, &mut d); sync_weights(app, &mut d); if d.bool("__newGroup") { - let colors = group_colors(app, &d, rows(&d).iter().filter(|r| !excluded(r))); + let colors = group_colors(app, &d, rows(&d).iter().filter(|r| !excluded(r) && to_color(r).is_some())); return form::commit_preview(app, "swatch.newGroup", json!({"name": d.str("groupName"), "colors": colors, "keepModel": true})); } let r = form::commit_preview(app, CMD, apply_params(&d))?; @@ -1756,7 +1756,7 @@ fn edit_tab(app: &VectorcraftApp, ui: &mut Ui, d: &mut Dialog, rows: &mut Vec Vec { + let doc = &app.session.doc().unwrap().doc; + doc.swatch_groups.last().unwrap().swatches.iter().map(|w| w.paint.color().unwrap().to_hex()).collect() + }; + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert("rows".into(), json!([{"from": [BLUE], "to": null}, {"from": [RED, PURPLE], "to": "rgb 0 255 0"}])); + d.fields.insert(SAVE_GROUP.into(), json!("all")); + frame(&mut app, &ctx, 0.1, vec![], 0); + frame(&mut app, &ctx, 0.11, vec![], 0); + assert_eq!(last(&app), ["#00ff00"], "Save All Colors"); + + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + app.run("ui.recolorDialog", json!({"colors": ["#ff0000", "#0000ff"]})).unwrap(); + let d = app.ui.dialog.as_mut().unwrap(); + d.fields.insert("rows".into(), json!([{"from": ["rgb 255 0 0"], "to": "rgb 255 0 0"}, {"from": ["rgb 0 0 255"], "to": null}])); + let d = d.clone(); + confirm(&mut app, &d).unwrap(); + assert_eq!(last(&app), ["#ff0000"], "OK on colors opened alone"); + } + /// One frame with `modifiers` held. fn frame_with(app: &mut VectorcraftApp, ctx: &egui::Context, time: f64, events: Vec, modifiers: egui::Modifiers) { let events = std::iter::once(egui::Event::ModifiersChanged(modifiers)).chain(events).collect(); diff --git a/docs/mcp.md b/docs/mcp.md index 2098f154e5..aae49de740 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -4582,7 +4582,7 @@ bar sits under the Edit tab's wheel: each row with a share is a part as wide as the largest first. Dragging the edge between two parts moves width between them, and when the drag ends the widths become the `weights` field, which moves the rows' current colors and previews the result. The New Color Group menu beside the link button runs `swatch.newGroup` right away, as its own undo step: Save All Colors saves the new colors -of the rows that are not excluded, in row order, and Save Prominent Colors saves the bar's colors in the bar's order. +of the rows that are not excluded and still have one, in row order, and Save Prominent Colors saves the bar's colors in the bar's order. ```json {"name":"run_command","arguments":{"command":"recolor.weigh","params":{"map":[{"from":["rgb 255 0 0","rgb 128 0 204"],"to":"#00ff00"},{"from":["rgb 0 0 255"],"to":"#ffff00"}],"weights":[1,1]}}}