diff --git a/crates/ui-egui/src/panels/color.rs b/crates/ui-egui/src/panels/color.rs index 0db7310e92..80f1be75a8 100644 --- a/crates/ui-egui/src/panels/color.rs +++ b/crates/ui-egui/src/panels/color.rs @@ -32,6 +32,7 @@ use vectorcraft_color::{Color, GradientKind, Paint}; use super::{Live, active_paint, color_json, live_run, proxy_events}; use crate::VectorcraftApp; use crate::edits::{EditPath, apply_event}; +use crate::paint_preview::well_paint; /// The layout the app's panel and its menu use. const LAYOUT: ColorPanelLayout = ColorPanelLayout::FillStroke; @@ -532,11 +533,11 @@ fn switch_rgb_units(app: &mut VectorcraftApp) -> bool { app.ui.color_panel.rgb_percent } -/// The proxy's paint as one well: the colour of a solid paint or a gradient's first stop. +/// The proxy's paint as one well, drawn as the Tools panel's proxy draws it (a gradient, None or a +/// pattern as itself), and the color the panel is given for it: a solid paint's color, black for any other paint. fn well(label: &'static str, paint: &Paint, mixed: bool) -> (PairWell, Srgba) { let color = srgba(&paint.color().unwrap_or(Color::BLACK)); - // PLAN: PairWell::paint (wg.W48) would also show gradients and None as they are. - (PairWell::new(label, if mixed { Mixed::Mixed } else { Mixed::Same(color) }), color) + (PairWell::paint(label, if mixed { Mixed::Mixed } else { Mixed::Same(well_paint(paint, &|_| None)) }), color) } /// Draw numeric paint controls and run what they report. diff --git a/crates/ui-egui/src/panels/color/tests.rs b/crates/ui-egui/src/panels/color/tests.rs index 102bf09995..e63fc09e7a 100644 --- a/crates/ui-egui/src/panels/color/tests.rs +++ b/crates/ui-egui/src/panels/color/tests.rs @@ -381,3 +381,26 @@ fn picked_mesh_points_are_the_color_the_panel_shows_and_edits() { assert_eq!(picked(&app), vec![0, middle], "the Shift-click adds the top middle point"); assert_eq!(crate::panels::mixed_paints(&app, &ctx), (true, false), "picking recomputes it"); } + +/// The panel's Fill and Stroke wells show a gradient and None as the Tools panel's proxy does, +/// not as black. +#[test] +fn the_wells_show_a_gradient_and_none_as_the_tools_proxy_does() { + use crate::tests::panel_harness::Panel; + let painted = || { + let mut app = app(); + let stops = json!([{"offset": 0, "color": "#ff0000"}, {"offset": 1, "color": "#0000ff"}]); + app.run("paint.setFill", json!({"gradient": {"stops": stops}})).unwrap(); + app.run("paint.setStroke", json!({"none": true})).unwrap(); + app + }; + let color = Panel::new(painted(), show); + let tools = Panel::new(painted(), crate::panels::proxy); + // The wells are unnamed parts of the pair, so they are found by the value each one reads as. + let wells = tools.values(); + assert_eq!(wells.len(), 2, "the Tools proxy's two wells read as {wells:?}"); + assert_ne!(wells[0], wells[1], "a gradient and None read differently"); + for well in &wells { + assert!(color.shows_value(well), "the Color panel shows a well that reads as {well:?}"); + } +} diff --git a/crates/ui-egui/src/tests/panel_harness.rs b/crates/ui-egui/src/tests/panel_harness.rs index 0949ef8c80..574da463f5 100644 --- a/crates/ui-egui/src/tests/panel_harness.rs +++ b/crates/ui-egui/src/tests/panel_harness.rs @@ -306,6 +306,12 @@ impl Panel { self.fixture.tree().description_of(self.look(name).node).map(str::to_owned) } + /// The value texts of the latest frame's controls, in tree order. + pub(crate) fn values(&self) -> Vec { + let tree = self.fixture.tree(); + tree.keys().into_iter().filter_map(|key| tree.value_of(key)).map(str::to_owned).collect() + } + /// Whether a control in the latest frame holds the value text `value`. pub(crate) fn shows_value(&self, value: &str) -> bool { self.shows_value_with(|shown| shown == value)