mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-24 22:34:09 +00:00
Merge pull request #8696 from dotCooCoo/fix/live-paint-bucket-gradient-aspect
Gradient: an aspect with no object to edit is an error, not a silent no-op
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -3331,6 +3331,68 @@ fn live_paint_bucket_paint_and_stroke_commands_leave_the_selection_unpainted() {
|
||||
assert!(failed.is_empty(), "{failed:#?}");
|
||||
}
|
||||
|
||||
/// `paint.editGradient` with an `aspect` and no object to edit (the Live Paint Bucket's gradient,
|
||||
/// nothing selected, or a fill edit of a Live Paint group without faces) is an error that leaves the default gradient as it was, since a gradient
|
||||
/// fitted to each object has no aspect of its own. Named objects still take the aspect.
|
||||
#[test]
|
||||
fn edit_gradient_aspect_without_objects_is_an_error() {
|
||||
let aspect = |n: &Node| match n.appearance.fill_paint() {
|
||||
Paint::Gradient(g) => g.geom.map(|x| x.aspect),
|
||||
_ => None,
|
||||
};
|
||||
let mut s = session();
|
||||
let g = live(&mut s);
|
||||
let rect = rect(&mut s, 300.0, 300.0, 40.0, 40.0);
|
||||
s.execute("select.set", &json!({"ids": [g.0, rect.0]})).unwrap();
|
||||
s.select_tool("livePaintBucket", ViewInfo::default()).unwrap();
|
||||
s.execute("gradient.presets.apply", &json!({"name": "vignette"})).unwrap();
|
||||
let (group, art, fill) = (node(&s, g), node(&s, rect), s.paint.fill.clone());
|
||||
let steps = s.doc().unwrap().history.undo.len();
|
||||
assert!(!s.gradient_edit_has_objects(false), "the bucket edits its own gradient");
|
||||
for params in [json!({"stroke": false, "aspect": 50}), json!({"stroke": false, "aspect": 50, "reverse": true})] {
|
||||
assert!(s.execute("paint.editGradient", ¶ms).is_err(), "{params}");
|
||||
assert_eq!(s.paint.fill, fill, "{params}: the bucket's gradient stays");
|
||||
}
|
||||
assert_eq!((node(&s, g), node(&s, rect)), (group, art), "the selection keeps its paint");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "no undo step");
|
||||
// Named objects take it.
|
||||
s.execute("paint.editGradient", &json!({"stroke": false, "kind": "radial", "aspect": 50, "ids": [rect.0]})).unwrap();
|
||||
assert_eq!(aspect(&node(&s, rect)), Some(0.5));
|
||||
// Without the bucket and with nothing selected, the default gradient has no aspect either.
|
||||
s.select_tool("selection", ViewInfo::default()).unwrap();
|
||||
s.execute("select.set", &json!({"ids": []})).unwrap();
|
||||
let fill = s.paint.fill.clone();
|
||||
assert!(!s.gradient_edit_has_objects(false));
|
||||
assert!(s.execute("paint.editGradient", &json!({"stroke": false, "aspect": 50})).is_err());
|
||||
assert_eq!(s.paint.fill, fill, "the default gradient stays");
|
||||
// An empty group has nothing to paint.
|
||||
let empty = s
|
||||
.edit("Group", |d, _| {
|
||||
let id = d.alloc_id();
|
||||
d.insert(d.default_layer(), 0, Node::group(id, vec![]))?;
|
||||
Ok(id)
|
||||
})
|
||||
.unwrap();
|
||||
s.execute("select.set", &json!({"ids": [empty.0]})).unwrap();
|
||||
assert!(!s.gradient_edit_has_objects(false), "an empty group");
|
||||
assert!(s.execute("paint.editGradient", &json!({"stroke": false, "aspect": 50})).is_err());
|
||||
// A fill edit of a Live Paint group with edges and no faces edits no object; a stroke edit edits its edges.
|
||||
let line = NodeId(s.execute("shape.line", &json!({"x1": 0, "y1": 0, "x2": 100, "y2": 0})).unwrap()["id"].as_u64().unwrap());
|
||||
let edges_only = NodeId(s.execute("livePaint.make", &json!({"ids": [line.0]})).unwrap()["id"].as_u64().unwrap());
|
||||
s.execute("select.set", &json!({"ids": [edges_only.0]})).unwrap();
|
||||
let (fill, group, steps) = (s.paint.fill.clone(), node(&s, edges_only), s.doc().unwrap().history.undo.len());
|
||||
assert!(!s.gradient_edit_has_objects(false), "a Live Paint group without faces");
|
||||
assert!(s.gradient_edit_has_objects(true), "its edges take a stroke edit");
|
||||
assert!(s.execute("paint.editGradient", &json!({"stroke": false, "aspect": 50})).is_err());
|
||||
assert_eq!((&s.paint.fill, node(&s, edges_only)), (&fill, group), "the default and the group stay");
|
||||
assert_eq!(s.doc().unwrap().history.undo.len(), steps, "no undo step");
|
||||
// A selected object takes it.
|
||||
s.execute("select.set", &json!({"ids": [rect.0]})).unwrap();
|
||||
assert!(s.gradient_edit_has_objects(false) && s.gradient_edit_has_objects(true));
|
||||
s.execute("paint.editGradient", &json!({"stroke": false, "aspect": 25})).unwrap();
|
||||
assert_eq!(aspect(&node(&s, rect)), Some(0.25));
|
||||
}
|
||||
|
||||
/// With the Live Paint Bucket active, objects named with `ids` still take a stroke, and a brush
|
||||
/// still goes to the selection.
|
||||
#[test]
|
||||
|
||||
@@ -347,7 +347,8 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
edit(app, json!({"reverse": true}), Live::Released);
|
||||
}
|
||||
});
|
||||
let radial = kind.is_centered() && placed;
|
||||
// The default gradient (with nothing selected, or the Live Paint Bucket's) fits each object and has no aspect.
|
||||
let radial = kind.is_centered() && placed && app.session.gradient_edit_has_objects(!app.session.fill_active);
|
||||
ui.horizontal(|ui| {
|
||||
icons::icon(ui, "scaling", 15.0, if radial { t.icon } else { t.text_disabled }).on_hover_text(tl!("Aspect Ratio"));
|
||||
// A mirrored conic's negative aspect shows as its size; an edit keeps the mirror.
|
||||
|
||||
@@ -433,6 +433,37 @@ fn the_aspect_field_keeps_a_mirrored_conic_mirrored() {
|
||||
assert!((geom.aspect + 0.8).abs() < 1e-9 && geom.is_mirrored(), "{geom:?}");
|
||||
}
|
||||
|
||||
/// With nothing selected, and while the Live Paint Bucket is active, the Aspect Ratio field is
|
||||
/// dimmed: the default gradient fits each object and has no aspect, so typing in it changes
|
||||
/// nothing and reports no error.
|
||||
#[test]
|
||||
fn the_aspect_field_is_dimmed_for_the_default_gradient() {
|
||||
for bucket in [false, true] {
|
||||
let mut app = app(json!({"gradient": {"kind": "radial"}}));
|
||||
if bucket {
|
||||
app.select_tool("livePaintBucket");
|
||||
} else {
|
||||
app.run("select.set", json!({"ids": []})).unwrap();
|
||||
}
|
||||
let default = app.session.paint.fill.clone();
|
||||
let mut p = Panel::new();
|
||||
let texts = p.frame(&mut app, vec![], Modifiers::NONE);
|
||||
// The aspect field is the first 100% (above Opacity's).
|
||||
let field = texts
|
||||
.iter()
|
||||
.filter(|(t, _)| t == "100%")
|
||||
.map(|(_, at)| *at)
|
||||
.min_by(|a, b| a.y.total_cmp(&b.y))
|
||||
.unwrap_or_else(|| panic!("the aspect field: {texts:?}"));
|
||||
p.click(&mut app, field);
|
||||
let key = |k, modifiers| Event::Key { key: k, physical_key: None, pressed: true, repeat: false, modifiers };
|
||||
p.frame(&mut app, vec![key(egui::Key::A, Modifiers::COMMAND), Event::Text("80".into())], Modifiers::NONE);
|
||||
p.frame(&mut app, vec![key(egui::Key::Enter, Modifiers::NONE)], Modifiers::NONE);
|
||||
assert_eq!(app.session.paint.fill, default, "bucket {bucket}: the default gradient");
|
||||
assert!(app.ui.status.is_empty(), "bucket {bucket}: {}", app.ui.status);
|
||||
}
|
||||
}
|
||||
|
||||
/// The Type row's Diamond button (the fourth of five) makes the gradient a diamond, and the
|
||||
/// Aspect Ratio field then edits its aspect.
|
||||
#[test]
|
||||
|
||||
+3
-1
@@ -1673,7 +1673,9 @@ A conic gradient (`kind: "conic"`, also accepted as `angle` or `conical`) sweeps
|
||||
draws the extent ellipse, aspect dot and center ring of a radial gradient, without a focal point; a `focal` given
|
||||
for a conic gradient is an error. A negative `aspect` mirrors the sweep (counterclockwise), as reflecting the object
|
||||
does; for the other kinds a negative `aspect` is an error. The Gradient panel's Aspect Ratio field and the aspect dot
|
||||
keep a mirrored sweep mirrored. Dither and Method apply as they do to a linear gradient. PDF export writes it as a
|
||||
keep a mirrored sweep mirrored. The default gradient for new art, and the Live Paint Bucket's, fits each object it
|
||||
paints and keeps no aspect, so `paint.editGradient` with an `aspect` is an error when it edits no object (nothing
|
||||
selected, the bucket's gradient without `ids`, or a fill edit of a Live Paint group without faces) and leaves the default as it was. Dither and Method apply as they do to a linear gradient. PDF export writes it as a
|
||||
function-based shading (type 1) whose calculator function turns the angle into the ramp, and PDF import reads a
|
||||
function-based shading whose color turns around the origin of its space back as a conic gradient, with its stops'
|
||||
opacity, also when the origin lies outside the painted area; in a PDF/A file, or with more than 97 stops on its
|
||||
|
||||
Reference in New Issue
Block a user