mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-25 22:39:07 +00:00
Merge pull request #9252 from dotCooCoo/fix/color-well-gradients
Color panel: the Fill and Stroke wells show gradients, None and patterns as the Tools proxy does
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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:?}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<String> {
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user