mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-29 01:34:29 +01:00
Merge main into fix/new-document-layout
This commit is contained in:
commit
d8cda92ae1
5 files changed
+45
-10
No files matched your search
@@ -253,6 +253,8 @@ pub(crate) fn item_target(s: &Session, p: &Value, cmd: &str) -> Result<ItemTarge
|
||||
/// [`item_target`] read from param `key` (e.g. `fromItem`).
|
||||
pub(crate) fn item_target_at(s: &Session, p: &Value, key: &str, cmd: &str) -> Result<ItemTarget> {
|
||||
let aligned = aligned(p, cmd)?;
|
||||
// Read `target` whatever names the objects, so that a bad one is refused with `ids` or `id` too.
|
||||
let contents = targets_contents(p)?;
|
||||
match p.get(key) {
|
||||
Some(Value::Null) => Ok(ItemTarget::Top),
|
||||
Some(v) => v
|
||||
@@ -260,7 +262,7 @@ pub(crate) fn item_target_at(s: &Session, p: &Value, key: &str, cmd: &str) -> Re
|
||||
.map(|i| ItemTarget::Item { index: index(i), explicit: true, aligned })
|
||||
.ok_or_else(|| bad(cmd, format!("`{key}` must be an appearance item index (paint order) or null"))),
|
||||
// The active item is a row of the first selected object's own stack.
|
||||
None if p.get("ids").is_some() || p.get("id").is_some() || targets_contents(p)? => Ok(ItemTarget::Top),
|
||||
None if p.get("ids").is_some() || p.get("id").is_some() || contents => Ok(ItemTarget::Top),
|
||||
// A row of a graph design's art in a series stands for nothing: the commands leave that art out.
|
||||
None if s.active().and_then(|st| st.selection.subjects().first().map(|id| super::graph::is_design_art(&st.doc, *id))) == Some(true) => {
|
||||
Ok(ItemTarget::Top)
|
||||
|
||||
@@ -945,8 +945,8 @@ fn apply_paint_opacity(s: &mut Session, p: &Value, paint: Option<Paint>, opacity
|
||||
let cmd = if fill { "paint.setFill" } else { "paint.setStroke" };
|
||||
let for_tool = tool_color_params(s, p, cmd, !fill)?;
|
||||
let p = for_tool.as_ref().unwrap_or(p);
|
||||
// A bad `target` or `aligned` is refused for every kind of target: `item_target` reads no
|
||||
// `target` once `id` or `ids` names an object, and selected characters read neither.
|
||||
// A bad `target` or `aligned` is refused for every kind of target: selected characters take
|
||||
// the paint before `item_target` reads either.
|
||||
super::appearance::aligned(p, cmd)?;
|
||||
super::appearance::targets_contents(p)?;
|
||||
let focus = switch_or(p, "focus", true, cmd)?;
|
||||
@@ -1474,8 +1474,6 @@ fn selected_part_target(s: &Session, p: &Value, cmd: &str) -> Result<Option<(Nod
|
||||
}
|
||||
let part = super::brushsym::selected_part(s)?;
|
||||
if part.is_some() {
|
||||
// Read `target` first: `item_target` stops at a null `id` or `ids` before it reads `target`.
|
||||
super::appearance::targets_contents(p)?;
|
||||
item_target(s, p, cmd)?;
|
||||
}
|
||||
Ok(part)
|
||||
|
||||
@@ -513,6 +513,23 @@ fn a_bad_target_is_refused_with_an_id_or_selected_characters() {
|
||||
}
|
||||
}
|
||||
|
||||
/// The other commands that name their appearance item the same way refuse a bad `target` with an
|
||||
/// `id` or `ids` too, and leave the document alone; a good one still edits the object.
|
||||
#[test]
|
||||
fn a_stroke_edit_refuses_a_bad_target_with_an_id() {
|
||||
let mut s = session();
|
||||
let r = rect(&mut s, 10.0);
|
||||
select(&mut s, &[r]);
|
||||
let doc = s.doc().unwrap().doc.clone();
|
||||
for p in [json!({"weight": 9, "target": "content", "id": r.0}), json!({"weight": 9, "target": "content", "ids": [r.0]})] {
|
||||
let e = s.execute("stroke.set", &p).unwrap_err();
|
||||
assert!(e.to_string().contains("`target` must be"), "{p}: {e}");
|
||||
assert_eq!(*s.doc().unwrap().doc, *doc, "{p}");
|
||||
}
|
||||
s.execute("stroke.set", &json!({"weight": 9, "target": "object", "id": r.0})).unwrap();
|
||||
assert_ne!(*s.doc().unwrap().doc, *doc);
|
||||
}
|
||||
|
||||
/// A gradient mesh point picked with the Mesh tool takes a fill opacity itself, and the proxy shows
|
||||
/// it; the object's fill item and the other points stay as they were.
|
||||
#[test]
|
||||
|
||||
@@ -120,17 +120,32 @@ fn show_hex_field_is_a_setting_of_the_panel() {
|
||||
}
|
||||
|
||||
/// An explicit null for any `ui.colorWheel` key keeps that key's value, as leaving the key out does,
|
||||
/// and the other keys of the same call still apply.
|
||||
/// and the other keys of the same call still apply. `contrastBackground` is the exception: null
|
||||
/// unpins the background.
|
||||
#[test]
|
||||
fn ui_color_wheel_keeps_a_key_given_as_null() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
let set = json!({
|
||||
"view": "box", "channel": "red", "opacity": true, "hexField": true, "sliders": "oklch",
|
||||
"gamut": true, "harmony": true, "harmonyRule": "triad", "vision": true, "documentColors": true
|
||||
"gamut": true, "harmony": true, "harmonyRule": "triad", "contrast": true, "contrastFor": "largeText",
|
||||
"contrastBackground": null, "vision": true, "documentColors": true
|
||||
});
|
||||
let all = app.run("ui.colorWheel", set.clone()).unwrap();
|
||||
assert_eq!(all, set);
|
||||
for key in ["view", "channel", "opacity", "hexField", "sliders", "gamut", "harmony", "harmonyRule", "vision", "documentColors"] {
|
||||
for key in [
|
||||
"view",
|
||||
"channel",
|
||||
"opacity",
|
||||
"hexField",
|
||||
"sliders",
|
||||
"gamut",
|
||||
"harmony",
|
||||
"harmonyRule",
|
||||
"contrast",
|
||||
"contrastFor",
|
||||
"vision",
|
||||
"documentColors",
|
||||
] {
|
||||
assert_eq!(app.run("ui.colorWheel", json!({ key: null })).unwrap(), all, "{key}: null");
|
||||
}
|
||||
let got = app.run("ui.colorWheel", json!({"view": null, "channel": "blue", "opacity": null, "hexField": false})).unwrap();
|
||||
@@ -138,7 +153,8 @@ fn ui_color_wheel_keeps_a_key_given_as_null() {
|
||||
got,
|
||||
json!({
|
||||
"view": "box", "channel": "blue", "opacity": true, "hexField": false, "sliders": "oklch",
|
||||
"gamut": true, "harmony": true, "harmonyRule": "triad", "vision": true, "documentColors": true
|
||||
"gamut": true, "harmony": true, "harmonyRule": "triad", "contrast": true, "contrastFor": "largeText",
|
||||
"contrastBackground": null, "vision": true, "documentColors": true
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -876,10 +876,12 @@ fn controls_are_drawn_at_the_size_the_script_gave_them() {
|
||||
.unwrap_or_else(|| panic!("no {role:?} {label:?}"))
|
||||
};
|
||||
let w = app.session.script_window().unwrap();
|
||||
// The field is the text input named for screen readers; the editor inside its padding is a text
|
||||
// input too, and the update lists the two in no fixed order.
|
||||
let (wide, ok, field) = (
|
||||
bounds(egui::accesskit::Role::Button, Some("Wide")),
|
||||
bounds(egui::accesskit::Role::Button, Some("OK")),
|
||||
bounds(egui::accesskit::Role::TextInput, None),
|
||||
bounds(egui::accesskit::Role::TextInput, Some("Text")),
|
||||
);
|
||||
assert!(wide.width() > ok.width() && wide.height() > ok.height(), "the wide button is larger than OK: {wide:?} {ok:?}");
|
||||
assert!((wide.width() - f64::from(w.nodes[1].rect.w)).abs() < 1.0, "the wide button is as wide as its preferred size: {wide:?}");
|
||||
|
||||
Reference in new issue
Block a user