Color Picker: the screen sampler works in a picker opened over a dialog

A Color Picker opened from a dialog's color (an effect's color, a
command form's color or a Document Setup grid color) now carries the
number that ui.sampleScreenColor uses to find the open picker. Its
eyedropper sends the sampled color to that picker instead of failing
with "the Color Picker is not open".
This commit is contained in:
dotCooCoo
2026-11-17 14:40:08 -08:00
parent b4fda766b6
commit 30ec117960
2 changed files with 22 additions and 0 deletions
@@ -282,6 +282,7 @@ pub(super) fn over_effect(parent: &Dialog, field: &str, colour: Color) -> Dialog
);
d.fields.insert(super::PARENT.into(), serde_json::to_value(parent).unwrap_or_default());
store(&mut d, &Picked::of(colour));
d.fields.insert(crate::screen_color::PICKER_ID.into(), json!(crate::screen_color::picker_id()));
d
}
@@ -799,6 +799,27 @@ mod tests {
assert_eq!((d.kind.as_str(), dialog_grid(d)), (super::KIND, ["#ffffff", "#00ff00"].map(hex).to_vec()));
}
/// The screen color sampler works in the Color Picker of a grid color: the color sampled goes
/// to that picker, and its OK sets the grid color.
#[test]
fn the_grid_color_picker_takes_a_screen_sampled_color() {
let (mut app, ctx) = transparency_tab();
let (tx, rx) = std::sync::mpsc::channel::<crate::screen_color::Answer>();
let mut rx = Some(rx);
app.services.screen_color = Some(Box::new(move || rx.take().ok_or_else(|| "shown twice".to_string())));
click_grid_box(&mut app, &ctx, 0);
assert_picker_over_setup(&app, LIGHT[0], "before sampling");
app.run("ui.sampleScreenColor", json!({"picker": true})).unwrap();
tx.send(Ok(Some([0.0, 0.5, 1.0]))).unwrap();
crate::screen_color::poll(&mut app, &ctx);
let sampled = app.ui.dialog.as_ref().unwrap().fields.get("color").and_then(vectorcraft_engine::cmd::color_value).unwrap();
assert_ne!(sampled.to_hex(), LIGHT[0]);
crate::dialogs::confirm(&mut app).unwrap();
let d = app.ui.dialog.as_ref().unwrap();
let grid: Vec<String> = dialog_grid(d).iter().map(Color::to_hex).collect();
assert_eq!((d.kind.as_str(), grid), (super::KIND, vec![sampled.to_hex(), LIGHT[1].to_string()]));
}
/// Clicks the hex field that shows `digits` and types `typed` over its text, leaving the edit
/// pending; returns the field's id.
fn type_into_hex_field(app: &mut VectorcraftApp, ctx: &egui::Context, digits: &str, typed: &str) -> egui::Id {