mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Merge pull request #10759 from dotCooCoo/fix/image-trace-draft-follows-selection
Image Trace: an unfinished slider or Divider value stays with the object it was typed for
This commit is contained in:
4 files changed
+93
-11
No files matched your search
@@ -299,9 +299,18 @@ pub(crate) fn split_row(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
let Some(split) = selected_split(app) else { return };
|
||||
// The canvas sets the divider to a ten-thousandth: a hundredth of a percent.
|
||||
let pct = (split * 10_000.0).round() / 100.0;
|
||||
// Workaround until the craft-libs pin includes craft-libs#5024: keying the field on the selection drops a value
|
||||
// typed for one object when another is selected. The pin bump replaces this with `edit_target`.
|
||||
let target = crate::panels::selection_target(app);
|
||||
let edit = Field::new(tl!("Divider"))
|
||||
.show(ui, |ui, _| {
|
||||
SliderField::new(tl!("Divider"), Bind::given(pct), 0.0..=100.0).layout(SliderFieldLayout::Inline).step(1.0).unit("%").show(ui).edit
|
||||
SliderField::new(tl!("Divider"), Bind::given(pct), 0.0..=100.0)
|
||||
.layout(SliderFieldLayout::Inline)
|
||||
.step(1.0)
|
||||
.unit("%")
|
||||
.id_salt(("divider", &target))
|
||||
.show(ui)
|
||||
.edit
|
||||
})
|
||||
.inner;
|
||||
let Some(edit) = edit else { return };
|
||||
@@ -1031,7 +1040,7 @@ fn show_settings(app: &mut VectorcraftApp, ui: &mut Ui, st: &mut TraceUi, list:
|
||||
}
|
||||
split_row(app, ui);
|
||||
|
||||
let data = RowsData::of(app);
|
||||
let data = RowsData::of_selection(app);
|
||||
let sampler = Sampler { enabled: t.is_trace || t.is_image, armed: app.ui.trace_ignore_sampler.is_some() };
|
||||
let (main, advanced) = rows::settings_group(ui, |ui| {
|
||||
let main = rows::main_rows(ui, &mut st.params, &data, RowsHost::Panel);
|
||||
|
||||
@@ -22,7 +22,7 @@ use vectorcraft_engine::cmd::swatchlib::DOCUMENT_SWATCHES;
|
||||
|
||||
use super::{MODES, PALETTES, ignore_color, palette_label};
|
||||
use crate::VectorcraftApp;
|
||||
use crate::panels::swatches;
|
||||
use crate::panels::{SelectionTarget, selection_target, swatches};
|
||||
|
||||
/// Where the rows are shown.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
@@ -40,13 +40,21 @@ pub(crate) struct RowsData {
|
||||
pub(crate) libraries: Vec<Entry<String>>,
|
||||
/// The active document's colour group names.
|
||||
pub(crate) groups: Vec<String>,
|
||||
/// The selection whose settings the rows show, for a host that follows the selection (the panel). A slider's
|
||||
/// unfinished value is dropped when it changes.
|
||||
pub(crate) target: Option<SelectionTarget>,
|
||||
}
|
||||
|
||||
impl RowsData {
|
||||
/// The lists for the active document.
|
||||
pub(crate) fn of(app: &VectorcraftApp) -> Self {
|
||||
// PLAN: assumed `swatches::library_entries(app: &VectorcraftApp) -> Vec<Entry<String>>` (color-w10).
|
||||
RowsData { libraries: swatches::library_entries(app), groups: swatch_groups(app) }
|
||||
RowsData { libraries: swatches::library_entries(app), groups: swatch_groups(app), target: None }
|
||||
}
|
||||
|
||||
/// The lists for the active document, for rows that show the selection's settings.
|
||||
pub(crate) fn of_selection(app: &VectorcraftApp) -> Self {
|
||||
RowsData { target: Some(selection_target(app)), ..Self::of(app) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,13 +159,18 @@ fn slider(key: &'static str, label: &'static str, range: RangeInclusive<f64>, un
|
||||
Slider { key, label, range, unit, default: 0.0 }
|
||||
}
|
||||
|
||||
fn slider_row(ui: &mut Ui, params: &mut Value, spec: Slider, enabled: bool, out: &mut RowsOutput) {
|
||||
fn slider_row(ui: &mut Ui, params: &mut Value, data: &RowsData, spec: Slider, enabled: bool, out: &mut RowsOutput) {
|
||||
let Slider { key, label, range, unit, default } = spec;
|
||||
let value = params[key].as_f64().unwrap_or(default);
|
||||
let events = Field::new(label)
|
||||
.enabled(enabled)
|
||||
.show(ui, |ui, _| {
|
||||
let mut field = SliderField::new(label, Bind::given(value), range.clone()).layout(SliderFieldLayout::Inline).step(1.0).enabled(enabled);
|
||||
// Workaround until the craft-libs pin includes craft-libs#5024: keying the field on the selection drops a
|
||||
// value typed for one object when another is selected. The pin bump replaces this with `edit_target`.
|
||||
if let Some(target) = &data.target {
|
||||
field = field.id_salt((key, target));
|
||||
}
|
||||
if let Some(unit) = unit {
|
||||
field = field.unit(unit);
|
||||
}
|
||||
@@ -234,14 +247,14 @@ pub(crate) fn main_rows(ui: &mut Ui, params: &mut Value, data: &RowsData, host:
|
||||
_ if matches!(palette.as_str(), "fullTone" | "automatic") => slider("colorDetail", tl!("Colors"), 0.0..=100.0, Some("%")),
|
||||
_ => slider("colors", tl!("Colors"), 2.0..=256.0, None),
|
||||
};
|
||||
slider_row(ui, params, count, true, &mut out);
|
||||
slider_row(ui, params, data, count, true, &mut out);
|
||||
out
|
||||
}
|
||||
|
||||
/// The Advanced settings: fidelity, method, Create, snapping, shapes, grouping, gradients and Ignore Color, with an
|
||||
/// eyedropper for Ignore Color when the host passes a `sampler`. `_data` and `_host` are the arguments of
|
||||
/// eyedropper for Ignore Color when the host passes a `sampler`. `data` and `_host` are the arguments of
|
||||
/// [`main_rows`], so a host passes the same set to both.
|
||||
pub(crate) fn advanced_rows(ui: &mut Ui, params: &mut Value, _data: &RowsData, _host: RowsHost, sampler: Option<Sampler>) -> RowsOutput {
|
||||
pub(crate) fn advanced_rows(ui: &mut Ui, params: &mut Value, data: &RowsData, _host: RowsHost, sampler: Option<Sampler>) -> RowsOutput {
|
||||
let mut out = RowsOutput::default();
|
||||
let mode = text(params, "mode", "blackAndWhite");
|
||||
for spec in [
|
||||
@@ -249,7 +262,7 @@ pub(crate) fn advanced_rows(ui: &mut Ui, params: &mut Value, _data: &RowsData, _
|
||||
slider("corners", tl!("Corners"), 0.0..=100.0, Some("%")),
|
||||
slider("noise", tl!("Noise"), 1.0..=100.0, Some("px")),
|
||||
] {
|
||||
slider_row(ui, params, spec, true, &mut out);
|
||||
slider_row(ui, params, data, spec, true, &mut out);
|
||||
}
|
||||
// Flat Logo always paints biggest shapes first with a hair of overlap, so there is no choice.
|
||||
if mode != "logo" {
|
||||
@@ -282,7 +295,7 @@ pub(crate) fn advanced_rows(ui: &mut Ui, params: &mut Value, _data: &RowsData, _
|
||||
params[key] = json!(!create(params, key));
|
||||
out.picked();
|
||||
}
|
||||
slider_row(ui, params, Slider { default: 10.0, ..slider("strokeWidth", tl!("Stroke"), 1.0..=100.0, Some("px")) }, strokes, &mut out);
|
||||
slider_row(ui, params, data, Slider { default: 10.0, ..slider("strokeWidth", tl!("Stroke"), 1.0..=100.0, Some("px")) }, strokes, &mut out);
|
||||
}
|
||||
// (Black and White has one colour and Flat Logo flat ones: no gradients to find.)
|
||||
let gradients = mode == "grayscale" || mode == "color";
|
||||
|
||||
@@ -599,6 +599,64 @@ fn the_divider_slider_keeps_an_exact_divider_and_a_drag_is_one_undo_step() {
|
||||
assert_eq!(undo(&panel.app()), steps + 1, "one undo step for the edit");
|
||||
}
|
||||
|
||||
/// Two traced objects with the same settings, the first one selected: the app, the first and the second object.
|
||||
fn two_traced_objects(app: VectorcraftApp) -> (VectorcraftApp, NodeId, NodeId) {
|
||||
let mut app = app;
|
||||
let a = first_selected(&app).unwrap().id;
|
||||
app.run("edit.duplicate", json!({})).unwrap();
|
||||
let b = first_selected(&app).unwrap().id;
|
||||
assert_ne!(a, b);
|
||||
app.run("select.set", json!({"ids": [a.0]})).unwrap();
|
||||
(app, a, b)
|
||||
}
|
||||
|
||||
/// Types `text` into the number box of the slider row `name` without finishing the edit.
|
||||
fn type_unfinished(panel: &mut Panel, name: &str, text: &str) {
|
||||
panel.click_role(name, craft::ui::contract::Role::SPIN_BUTTON);
|
||||
panel.key(egui::Key::A, egui::Modifiers::COMMAND);
|
||||
panel.type_text(text);
|
||||
}
|
||||
|
||||
/// A value typed into a settings slider for one Image Trace object, and not finished, is dropped when another
|
||||
/// object is selected: Enter afterwards changes neither object.
|
||||
#[test]
|
||||
fn an_unfinished_slider_value_is_dropped_when_another_object_is_selected() {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let (app, a, b) = two_traced_objects(traced_app());
|
||||
let mut panel = panel_over(app);
|
||||
panel.frame();
|
||||
let threshold = param(&panel.app(), "threshold");
|
||||
let steps = undo(&panel.app());
|
||||
type_unfinished(&mut panel, "Threshold", "3");
|
||||
select(&mut panel, b);
|
||||
panel.key(egui::Key::Enter, egui::Modifiers::NONE);
|
||||
assert_eq!(param(&panel.app(), "threshold"), threshold, "B keeps its threshold");
|
||||
assert_eq!(undo(&panel.app()), steps, "nothing was traced");
|
||||
select(&mut panel, a);
|
||||
assert_eq!(param(&panel.app(), "threshold"), threshold, "A keeps its threshold");
|
||||
}
|
||||
|
||||
/// A value typed into the Divider for one Image Trace object, and not finished, is dropped when another object is
|
||||
/// selected: Enter afterwards moves neither divider.
|
||||
#[test]
|
||||
fn an_unfinished_divider_value_is_dropped_when_another_object_is_selected() {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
let mut app = traced_app();
|
||||
app.run("imageTrace.setView", json!({"view": "split", "split": 0.4})).unwrap();
|
||||
let (app, a, b) = two_traced_objects(app);
|
||||
let mut panel = panel_over(app);
|
||||
panel.frame();
|
||||
let steps = undo(&panel.app());
|
||||
type_unfinished(&mut panel, "Divider", "8");
|
||||
select(&mut panel, b);
|
||||
assert_eq!(first_selected(&panel.app()).unwrap().trace_split(), 0.4, "B has the same divider");
|
||||
panel.key(egui::Key::Enter, egui::Modifiers::NONE);
|
||||
assert_eq!(first_selected(&panel.app()).unwrap().trace_split(), 0.4, "B keeps its divider");
|
||||
assert_eq!(undo(&panel.app()), steps, "no undo step");
|
||||
select(&mut panel, a);
|
||||
assert_eq!(first_selected(&panel.app()).unwrap().trace_split(), 0.4, "A keeps its divider");
|
||||
}
|
||||
|
||||
/// Properties shows the Divider slider of the selected Image Trace object in the Split view only,
|
||||
/// with its name and value for screen readers.
|
||||
#[test]
|
||||
|
||||
@@ -1155,7 +1155,9 @@ fn review_596866_owned_release_then_press(coalesced: bool) {
|
||||
let history = (app.session.active().unwrap().history.undo.len(), app.session.active().unwrap().history.redo.len());
|
||||
if coalesced {
|
||||
frame_at(&mut app, &ctx, start + step, vec![review_596866_button(at, false), review_596866_button(at, true)]);
|
||||
assert!(frame_input(&ctx, |i| i.pointer.primary_released() && i.pointer.primary_pressed() && i.pointer.primary_down()));
|
||||
// The press's Down comes in a second pass of this frame when another part of the UI asks for a rerun, and in the
|
||||
// next frame otherwise. The coalesced release and press are read from the frame whose first pass took them.
|
||||
assert!(frame_event(&ctx, |i| i.pointer.primary_released() && i.pointer.primary_pressed() && i.pointer.primary_down()));
|
||||
} else {
|
||||
review_gesture_release(&mut app, &ctx, at, start + step);
|
||||
assert_eq!(app.session.active().unwrap().selection.objects, Vec::<NodeId>::new(), "CONTROL: the owned Up remains consumed");
|
||||
|
||||
Reference in new issue
Block a user