From a744816c7fbce2f780118d7847f609521b568769 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 21 Nov 2026 22:36:50 -0800 Subject: [PATCH 1/3] Plug-ins: a number parameter can show a slider beside its field A `number` or `int` parameter may now declare `"widget": "slider"`, with an optional `step` counted from `min`. The filter, live-effect and exporter dialogs and the Appearance panel's effect editor then show a slider over the parameter's range before its number field. The slider is named by the row's label for screen readers and moves by the step with the arrow keys. A value off the slider's steps, typed in the field or set by a script, is kept until the slider is moved. Install refuses the keys on any other parameter, on a range with no room, or with a step that cannot apply, and the refusals have rows in every complete catalog. Hosts from before these keys ignore them, as they do the other display keys. While a slider is dragged, the preview runs the plug-in at most about ten times a second, on the latest value, and the value the drag ends on always previews. In the Appearance panel a drag is one undo step. --- crates/plugins/src/dialog.rs | 114 +++++++++- crates/ui-egui/src/dialogs.rs | 5 +- crates/ui-egui/src/dialogs/effect.rs | 6 +- crates/ui-egui/src/dialogs/form.rs | 201 +++++++++++++++++- crates/ui-egui/src/dialogs/plugin.rs | 12 +- .../src/dialogs/tests_plugin_fields.rs | 196 ++++++++++++++++- crates/ui-egui/src/i18n/ca.tsv | 5 + crates/ui-egui/src/i18n/cs.tsv | 5 + crates/ui-egui/src/i18n/da.tsv | 5 + crates/ui-egui/src/i18n/de.tsv | 5 + crates/ui-egui/src/i18n/el.tsv | 5 + crates/ui-egui/src/i18n/es.tsv | 5 + crates/ui-egui/src/i18n/fi.tsv | 5 + crates/ui-egui/src/i18n/fr.tsv | 5 + crates/ui-egui/src/i18n/hi.tsv | 5 + crates/ui-egui/src/i18n/hu.tsv | 5 + crates/ui-egui/src/i18n/id.tsv | 5 + crates/ui-egui/src/i18n/it.tsv | 5 + crates/ui-egui/src/i18n/ja.tsv | 5 + crates/ui-egui/src/i18n/ka.tsv | 5 + crates/ui-egui/src/i18n/ko.tsv | 5 + crates/ui-egui/src/i18n/nl.tsv | 5 + crates/ui-egui/src/i18n/pl.tsv | 5 + crates/ui-egui/src/i18n/pt-br.tsv | 5 + crates/ui-egui/src/i18n/ru.tsv | 5 + crates/ui-egui/src/i18n/sv.tsv | 5 + crates/ui-egui/src/i18n/tr.tsv | 5 + crates/ui-egui/src/i18n/uk.tsv | 5 + crates/ui-egui/src/i18n/vi.tsv | 5 + crates/ui-egui/src/i18n/zh-hans.tsv | 5 + crates/ui-egui/src/i18n/zh-hant.tsv | 5 + crates/ui-egui/src/panels/appearance.rs | 81 ++++++- crates/ui-egui/src/panels/appearance/tests.rs | 92 ++++++++ docs/plugins.md | 10 +- docs/target-app-parity.md | 1 + 35 files changed, 824 insertions(+), 19 deletions(-) diff --git a/crates/plugins/src/dialog.rs b/crates/plugins/src/dialog.rs index 3777dab2e0..76c08cce02 100644 --- a/crates/plugins/src/dialog.rs +++ b/crates/plugins/src/dialog.rs @@ -1,5 +1,6 @@ //! How the host's generated dialogs show a plug-in's parameters: the optional `label`, `unit`, -//! `group`, `help`, `helpUrl` and `visibleWhen` keys of each one (docs/plugins.md › Parameters). +//! `group`, `help`, `helpUrl`, `visibleWhen`, `widget` and `step` keys of each one +//! (docs/plugins.md › Parameters). //! //! These keys are presentation only. A host from before them ignores them, so a plug-in that //! declares them still installs there, and a plug-in is given every parameter whether its dialog @@ -58,6 +59,66 @@ pub struct ParamUi { /// Shown only while each parameter named here has one of the values listed for it. #[serde(default, skip_serializing_if = "BTreeMap::is_empty")] pub visible_when: BTreeMap>, + /// The control that shows a number: [`Widget::Slider`] adds a slider beside its field. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub widget: Option, + /// How far the slider moves the value at a time, counted from `min` (a whole number for an + /// `int`); without it, a slider moves a `number` to two decimal places (more when `max` minus + /// `min` is under 1) and an `int` by 1. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub step: Option, +} + +/// The control a `number` or `int` parameter's row shows besides its number field (`widget`). +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum Widget { + /// A slider over `min..max`, beside the number field. + Slider, +} + +/// The largest whole number an `f64` holds exactly, which bounds an `int` slider's range. +const EXACT_INT: i64 = 1 << 53; + +impl ParamUi { + /// The range a slider shows `spec`'s value over, when the parameter asks for one + /// ([`Widget::Slider`]) and `spec` is a `number` or `int` the manifest checks allow it on. + pub fn slider_range(&self, spec: &ParamSpec) -> Option> { + if self.widget != Some(Widget::Slider) { + return None; + } + match spec { + ParamSpec::Number { min, max, .. } if min < max => Some(*min..=*max), + ParamSpec::Int { min, max, .. } if min < max && -EXACT_INT <= *min && *max <= EXACT_INT => Some(*min as f64..=*max as f64), + _ => None, + } + } + + /// Checks `widget` and `step` against parameter `spec`; `bad` builds the error. + fn validate_slider(&self, spec: &ParamSpec, bad: impl Fn(&str) -> Result<()>) -> Result<()> { + if self.widget.is_none() { + return match self.step { + Some(_) => bad("`step` is only for a parameter with a slider"), + None => Ok(()), + }; + } + let Some(range) = self.slider_range(spec) else { + return match spec { + ParamSpec::Number { .. } | ParamSpec::Int { .. } => { + bad(&format!("a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT}")) + } + _ => bad("a slider is only for `number` and `int` parameters"), + }; + }; + let Some(step) = self.step else { return Ok(()) }; + if !step.is_finite() || step <= 0.0 || step > range.end() - range.start() { + return bad("`step` must be a number above 0 and at most `max` minus `min`"); + } + if matches!(spec, ParamSpec::Int { .. }) && step.fract() != 0.0 { + return bad("an `int` parameter's `step` must be a whole number"); + } + Ok(()) + } } /// Is `s` 1 to `max` characters, not all spaces, without control characters (`\n` too, unless @@ -86,6 +147,9 @@ impl ParamUi { return bad(&format!("`helpUrl` must be an https:// address of at most {MAX_HELP_URL} bytes")); } } + if let Some((_, p)) = m.params.get(index) { + self.validate_slider(&p.spec, bad)?; + } if self.visible_when.len() > MAX_CONDITIONS { return bad(&format!("`visibleWhen` names at most {MAX_CONDITIONS} parameters")); } @@ -304,4 +368,52 @@ mod tests { let fine = with("help", r#""Two\nlines.""#); assert!(Manifest::parse(fine.as_bytes()).is_ok()); } + + /// A `number` or `int` parameter with a range may ask for a slider, with a step from `min`; + /// the keys read back as written, and a parameter without them shows no slider. + #[test] + fn slider_keys_parse_and_round_trip() { + let m = Manifest::parse( + br#"{"id":"a","name":"x","kind":"filter","params":{ + "area":{"type":"number","min":0,"max":100,"default":10,"widget":"slider"}, + "count":{"type":"int","min":1,"max":20,"default":4,"widget":"slider","step":2}, + "plain":{"type":"number","min":0,"max":100,"default":10}}}"#, + ) + .unwrap(); + let (area, count, plain) = (m.param("area").unwrap(), m.param("count").unwrap(), m.param("plain").unwrap()); + assert_eq!(area.ui.slider_range(&area.spec), Some(0.0..=100.0)); + assert_eq!((count.ui.slider_range(&count.spec), count.ui.step), (Some(1.0..=20.0), Some(2.0))); + assert_eq!(plain.ui.slider_range(&plain.spec), None); + assert_eq!(Manifest::parse(&serde_json::to_vec(&m).unwrap()).unwrap(), m); + assert_eq!(serde_json::to_value(&m).unwrap()["params"]["count"]["widget"], json!("slider")); + } + + #[test] + fn slider_keys_that_cannot_apply_are_refused() { + let param = |p: &str| format!(r#"{{"id":"a","name":"x","kind":"filter","params":{{"p":{p}}}}}"#); + for bad in [ + // Only numbers have a slider, over a range that has room to move. + r#"{"type":"bool","widget":"slider"}"#, + r#"{"type":"choice","options":["a","b"],"widget":"slider"}"#, + r#"{"type":"numberList","min":0,"max":1,"widget":"slider"}"#, + r#"{"type":"number","min":5,"max":5,"default":5,"widget":"slider"}"#, + r#"{"type":"int","min":0,"max":9007199254740993,"widget":"slider"}"#, + // A control the host doesn't have, and a step without a slider. + r#"{"type":"number","min":0,"max":1,"default":0,"widget":"knob"}"#, + r#"{"type":"number","min":0,"max":1,"default":0,"step":0.1}"#, + // Steps that go nowhere, past the range, or between whole numbers. + r#"{"type":"number","min":0,"max":1,"default":0,"widget":"slider","step":0}"#, + r#"{"type":"number","min":0,"max":1,"default":0,"widget":"slider","step":-0.5}"#, + r#"{"type":"number","min":0,"max":1,"default":0,"widget":"slider","step":2}"#, + r#"{"type":"int","min":0,"max":10,"widget":"slider","step":2.5}"#, + ] { + assert!(Manifest::parse(param(bad).as_bytes()).is_err(), "{bad}"); + } + // A command's parameters are checked the same way. + let command = |p: &str| format!(r#"{{"id":"a","name":"x","kind":"filter","commands":[{{"id":"go","label":"Go","params":{{"p":{p}}}}}]}}"#); + assert!(Manifest::parse(command(r#"{"type":"number","min":0,"max":1,"default":0,"widget":"slider"}"#).as_bytes()).is_ok()); + assert!(Manifest::parse(command(r#"{"type":"bool","widget":"slider"}"#).as_bytes()).is_err()); + let fine = param(r#"{"type":"int","min":0,"max":10,"widget":"slider","step":10}"#); + assert!(Manifest::parse(fine.as_bytes()).is_ok()); + } } diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index a24755ab12..73efcceb5d 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -179,7 +179,10 @@ pub(crate) use export_for_screens::{ open_assets as open_export_for_screens_assets, preset_list as screen_preset_list, saved_options as screen_saved_options, saved_rows as screen_saved_rows, settings_format as screen_settings_format, }; -pub(crate) use form::{humanize, number_list_text, plugin_color_button, ppi_suffix, read_number_list, unit_suffix}; +pub(crate) use form::{ + PARAM_SLIDER_WIDTH, SlidePreview, field_places, humanize, number_list_text, plugin_color_button, plugin_slider, ppi_suffix, read_number_list, + unit_suffix, +}; pub use new_document::{create_without_dialog as new_document_without_dialog, open as open_new_document, preset_card}; pub(crate) use new_document::{popup_open as new_document_popup_open, preset_name}; pub use png_options::open as open_raster_options; diff --git a/crates/ui-egui/src/dialogs/effect.rs b/crates/ui-egui/src/dialogs/effect.rs index df5789e649..811cc2da46 100644 --- a/crates/ui-egui/src/dialogs/effect.rs +++ b/crates/ui-egui/src/dialogs/effect.rs @@ -269,7 +269,11 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { } // Plug-in effects get fields from their parameter schema; colour adjustments their sliders. let changed = match vectorcraft_plugins::effect::installed(&id) { - Some(plugin) => form::schema_fields(app, ui, d, plugin.manifest()), + // While a slider is dragged, the preview catches up with it a few times a second. + Some(plugin) => { + let changed = form::schema_fields(app, ui, d, plugin.manifest()); + form::slide_preview(ui, d, changed).unwrap_or(false) + } // The Color Effects add-on's take the plain form of their parameters. None if vectorcraft_effects::is_adjustment(&id) && !vectorcraft_effects::addons::color::is_color_effect(&id) => adjust_fields(ui, d), None if id == vectorcraft_effects::addons::halftone::HALFTONE => { diff --git a/crates/ui-egui/src/dialogs/form.rs b/crates/ui-egui/src/dialogs/form.rs index f19cd18cda..2c8b6cf7aa 100644 --- a/crates/ui-egui/src/dialogs/form.rs +++ b/crates/ui-egui/src/dialogs/form.rs @@ -610,7 +610,8 @@ fn typed_number(x: f64) -> Value { /// Editor for a plug-in's parameters from its manifest (the filter, live effect and exporter /// dialogs): numbers within their range, whole numbers, checkboxes, dropdowns, text and lists of -/// numbers, a row each. A row is labelled as the manifest says (else from the parameter's name), +/// numbers, a row each, with a slider before the number of a parameter that asks for one +/// ([`plugin_slider`]). A row is labelled as the manifest says (else from the parameter's name), /// with its unit after the value and its help on the label and on a help button that opens its /// page. Parameters outside any group come first, then each group as a section that folds /// ([`Manifest::sections`]); a parameter whose `visibleWhen` the values don't meet is left out @@ -634,6 +635,7 @@ pub(super) fn schema_fields(app: &mut crate::VectorcraftApp, ui: &mut egui::Ui, pub(super) fn schema_rows(ui: &mut egui::Ui, d: &mut Dialog, m: &Manifest) -> (bool, Option) { let mut changed = false; let mut help = None; + let mut sliding = false; let visible = m.visible(&d.fields); let sections = m.sections(); // Every section's label column is as wide as the longest label shown, so the fields line up @@ -653,8 +655,9 @@ pub(super) fn schema_rows(ui: &mut egui::Ui, d: &mut Dialog, m: &Manifest) -> (b let grid = egui::Grid::new(("plugin-grid", section)).num_columns(2).spacing([12.0, 8.0]).min_col_width(label_width); grid.show(ui, |ui| { for (k, p) in shown { - let (row_changed, opened) = param_row(ui, d, k, p); + let (row_changed, opened, row_sliding) = param_row(ui, d, k, p); changed |= row_changed; + sliding |= row_sliding; help = help.take().or(opened); ui.end_row(); } @@ -668,17 +671,97 @@ pub(super) fn schema_rows(ui: &mut egui::Ui, d: &mut Dialog, m: &Manifest) -> (b } } }); + if sliding { + d.fields.insert(SLIDING.into(), json!(true)); + } else { + d.fields.remove(SLIDING); + } (changed, help) } +/// The field set while one of a plug-in dialog's sliders is being dragged ([`schema_rows`]). +const SLIDING: &str = "__sliding"; +/// The fields holding the dialog's [`SlidePreview`]: its `at` and its `held`. +const SLID_AT: &str = "__slidAt"; +const HELD: &str = "__held"; + +/// How often, at most, dragging the slider of a plug-in's parameter runs the plug-in again for +/// its preview (seconds). +pub(crate) const SLIDE_PREVIEW_EVERY: f64 = 0.1; + +/// When a drag on a plug-in parameter's slider last previewed, and whether a value it reached +/// has not previewed yet ([`SlidePreview::due`]). +#[derive(Clone, Copy, Debug, Default, PartialEq)] +pub(crate) struct SlidePreview { + /// The time of the drag's last preview (seconds of the UI's clock). + pub at: Option, + /// A value changed since that preview. + pub held: bool, +} + +impl SlidePreview { + /// Whether to preview on this frame at time `now`, given whether a value `changed` on it and + /// whether a slider is `sliding`: `Err(wait)` to wait `wait` seconds, else whether there is a + /// change to preview. While a slider is dragged, a change previews at once when the drag's + /// last preview is at least [`SLIDE_PREVIEW_EVERY`] old, and otherwise waits for that time, + /// so a plug-in runs about ten times a second during a drag, on the latest value, rather than + /// on every frame. A change still waiting when the drag ends previews then. + pub(crate) fn due(&mut self, now: f64, sliding: bool, changed: bool) -> Result { + let pending = std::mem::take(&mut self.held) || changed; + if !sliding { + self.at = None; + return Ok(pending); + } + if !pending { + return Ok(false); + } + match self.at.map(|at| now - at) { + Some(since) if (0.0..SLIDE_PREVIEW_EVERY).contains(&since) => { + self.held = true; + Err(SLIDE_PREVIEW_EVERY - since) + } + _ => { + self.at = Some(now); + Ok(true) + } + } + } + + /// [`SlidePreview::due`] at `ui`'s time, asking for a frame when a wait ends: `None` to wait. + pub(crate) fn due_now(&mut self, ui: &egui::Ui, sliding: bool, changed: bool) -> Option { + let due = self.due(ui.input(|i| i.time), sliding, changed); + if let Err(wait) = due { + ui.ctx().request_repaint_after(std::time::Duration::from_secs_f64(wait)); + } + due.ok() + } +} + +/// Whether the plug-in dialog `d` previews its values on this frame, given whether one `changed` +/// on it ([`schema_rows`]): `None` to wait while one of its sliders is dragged, else whether there +/// is a change to preview ([`SlidePreview::due`]). +pub(super) fn slide_preview(ui: &egui::Ui, d: &mut Dialog, changed: bool) -> Option { + let mut slide = SlidePreview { at: d.fields.get(SLID_AT).and_then(Value::as_f64), held: d.bool(HELD) }; + let due = slide.due_now(ui, d.bool(SLIDING), changed); + match slide.at { + Some(at) => d.fields.insert(SLID_AT.into(), json!(at)), + None => d.fields.remove(SLID_AT), + }; + match slide.held { + true => d.fields.insert(HELD.into(), json!(true)), + false => d.fields.remove(HELD), + }; + due +} + /// The label of parameter `k`'s row: its manifest `label`, else its name spaced out. fn param_label(k: &str, p: &Param) -> String { p.ui.label.as_ref().map_or_else(|| humanize(k), |l| format!("{l}:")) } /// One row of [`schema_fields`]: parameter `k`'s label and value field → whether the value changed, -/// and the help page asked for. -fn param_row(ui: &mut egui::Ui, d: &mut Dialog, k: &str, p: &Param) -> (bool, Option) { +/// the help page asked for, and whether its slider is being dragged. +fn param_row(ui: &mut egui::Ui, d: &mut Dialog, k: &str, p: &Param) -> (bool, Option, bool) { let t = Tokens::get(ui.ctx()); let label = param_label(k, p); let shown_label = ui.label(egui::RichText::new(&label).color(t.text)); @@ -687,11 +770,17 @@ fn param_row(ui: &mut egui::Ui, d: &mut Dialog, k: &str, p: &Param) -> (bool, Op let unit = p.ui.unit.as_deref().unwrap_or_default(); let suffix = unit_suffix(unit); let mut opened = None; + let mut sliding = false; let new = ui .horizontal(|ui| { // The row's painted label names every input in its value column (egui 0.37's strict // accessibility gate), not only the first one. - let (new, in_field) = ui.label_inputs_by(shown_label.id, |ui| value_field(ui, k, &label, &p.spec, &cur, &suffix)); + let (new, in_field) = ui.label_inputs_by(shown_label.id, |ui| { + let slid = p.ui.slider_range(&p.spec).map(|range| plugin_slider(ui, k, &p.spec, &cur, range, p.ui.step, PARAM_SLIDER_WIDTH)); + sliding = slid.as_ref().is_some_and(|(_, resp)| resp.dragged()); + let (typed, in_field) = value_field(ui, k, &label, &p.spec, &cur, &suffix, field_places(p)); + (slid.and_then(|(v, _)| v).or(typed), in_field) + }); if !in_field && !unit.is_empty() { ui.label(egui::RichText::new(unit).color(t.text_dim)); } @@ -704,17 +793,111 @@ fn param_row(ui: &mut egui::Ui, d: &mut Dialog, k: &str, p: &Param) -> (bool, Op }) .inner; let changed = new.map(|v| d.fields.insert(k.to_string(), v)).is_some(); - (changed, opened) + (changed, opened, sliding) +} + +/// Width of the slider a plug-in parameter asks for (`"widget": "slider"`) in its dialog, and the +/// most it takes in the Appearance panel. +pub(crate) const PARAM_SLIDER_WIDTH: f32 = 140.0; + +/// The slider of a `number` or `int` parameter that asks for one, `width` wide, over `range` (its +/// `min..max`), showing its value `cur`: dragging it or stepping it with the keys moves the value +/// by `step` from `min` (an `int` without one by 1, a `number` without one to two decimal places, +/// more when the range is under 1) → the value it moved to, and the slider's response. A value +/// off the slider's grid is kept until the slider is used. Screen readers get it as a slider with +/// the row's label as its name and the value as its number. +pub(crate) fn plugin_slider( + ui: &mut egui::Ui, + id: impl std::hash::Hash + std::fmt::Debug, + spec: &ParamSpec, + cur: &Value, + range: std::ops::RangeInclusive, + step: Option, + width: f32, +) -> (Option, egui::Response) { + let int = matches!(spec, ParamSpec::Int { .. }); + let (lo, hi) = (*range.start(), *range.end()); + let before = cur.as_f64().unwrap_or(lo).clamp(lo, hi); + let mut v = before; + // `Edits` clamps and rounds only what the pointer, the keys or a screen reader set, so drawing + // the slider leaves a value off its grid as it is. + let slider = egui::Slider::new(&mut v, range).show_value(false).clamping(egui::SliderClamping::Edits); + let places = if int { None } else { slider_places(lo, hi, step) }; + let slider = match step { + Some(step) => slider.step_by(step), + None if int => slider.integer(), + None => slider.fixed_decimals(places.unwrap_or(2)), + }; + let resp = ui + .push_id(("plugin-slider", id), |ui| { + ui.spacing_mut().slider_width = width; + crate::widgets::slider(ui, slider) + }) + .inner; + if v == before { + return (None, resp); + } + // Rounding onto the step's grid can pass `max`, which the plug-in would refuse, and a step + // such as 0.1 leaves binary noise (0.30000000000000004) that the plug-in would be given. + let v = match (step, places) { + (Some(_), Some(places)) => round_to(v, lo, places), + _ => v, + } + .clamp(lo, hi); + let new = (v != before).then(|| if int { json!(v.round() as i64) } else { json!(v) }); + (new, resp) +} + +/// The decimal places a `number` slider over `lo..=hi` moves its value to: with a `step`, the +/// step's and `lo`'s own (`None` when either has more than 17); without one, two, and more when +/// the range is under 1. +fn slider_places(lo: f64, hi: f64, step: Option) -> Option { + match step { + Some(step) => Some(decimal_places(step)?.max(decimal_places(lo)?)), + None => Some(2 + (-(hi - lo).log10()).ceil().clamp(0.0, 330.0) as usize), + } +} + +/// The decimal places the number field of plug-in parameter `p` shows and reads: those its slider +/// moves to, from 2 to the field's limit of 6, when it has one, else 2. +pub(crate) fn field_places(p: &Param) -> usize { + match (&p.spec, p.ui.slider_range(&p.spec)) { + (ParamSpec::Number { .. }, Some(range)) => slider_places(*range.start(), *range.end(), p.ui.step).unwrap_or(6).clamp(2, 6), + _ => 2, + } +} + +/// How many decimal places `x` is written with, when that is at most 17. +fn decimal_places(x: f64) -> Option { + (0..=17).find(|&d| { + let scaled = x * 10f64.powi(d as i32); + (scaled - scaled.round()).abs() <= ulp(scaled) + }) +} + +/// The gap between `x` and the next larger `f64` in magnitude. +fn ulp(x: f64) -> f64 { + let x = x.abs(); + f64::from_bits(x.to_bits() + 1) - x +} + +/// `v`, a value on a slider's grid counted from `lo`, rounded to `places` decimal places when that +/// moves it by no more than the binary noise of that count (four units in the last place of the +/// larger of `v` and `lo`, as in 0.30000000000000004), else `v`. +fn round_to(v: f64, lo: f64, places: usize) -> f64 { + let scale = 10f64.powi(places as i32); + let rounded = (v * scale).round() / scale; + if rounded.is_finite() && (rounded - v).abs() <= 4.0 * ulp(v.abs().max(lo.abs())) { rounded } else { v } } /// The field of parameter `k`'s value `cur` (a checkbox is called by the row's `label`) → the new /// value when it changed, and whether the field shows `suffix` (numbers do; the other fields leave -/// the unit to a label after them). -fn value_field(ui: &mut egui::Ui, k: &str, label: &str, spec: &ParamSpec, cur: &Value, suffix: &str) -> (Option, bool) { +/// the unit to a label after them). A number shows `places` decimal places ([`field_places`]). +fn value_field(ui: &mut egui::Ui, k: &str, label: &str, spec: &ParamSpec, cur: &Value, suffix: &str, places: usize) -> (Option, bool) { match spec { ParamSpec::Number { min, max, .. } => { let x = cur.as_f64().unwrap_or(*min); - (crate::widgets::range_field_named(ui, ("plugin-num", k), Some(label), x, *min..=*max, suffix, 2, 100.0).map(|x| json!(x)), true) + (crate::widgets::range_field_named(ui, ("plugin-num", k), Some(label), x, *min..=*max, suffix, places, 100.0).map(|x| json!(x)), true) } ParamSpec::Int { min, max, .. } => { let x = cur.as_i64().unwrap_or(*min).clamp(*min, *max); diff --git a/crates/ui-egui/src/dialogs/plugin.rs b/crates/ui-egui/src/dialogs/plugin.rs index 706188f6da..f1722650bb 100644 --- a/crates/ui-egui/src/dialogs/plugin.rs +++ b/crates/ui-egui/src/dialogs/plugin.rs @@ -230,8 +230,18 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { if run_with.is_none() && !d.str("__command").is_empty() { return true; } - form::schema_fields(app, ui, d, run_with.as_ref().unwrap_or(plugin.manifest())); + let changed = form::schema_fields(app, ui, d, run_with.as_ref().unwrap_or(plugin.manifest())); match plugin.manifest().budget { + // While a slider is dragged, the preview catches up with it a few times a second. Turning + // Preview off during the drag still rolls the preview back at once. + Budget::Light if form::slide_preview(ui, d, changed).is_none() => { + ui.add_space(8.0); + form::preview_check(ui, d); + if !d.bool("preview") { + let (label, p) = (d.str("__label"), params(d)); + form::preview_without_check(app, d, &label, &command(d), p); + } + } Budget::Light => { let (label, p) = (d.str("__label"), params(d)); form::preview(app, ui, d, &label, &command(d), p); diff --git a/crates/ui-egui/src/dialogs/tests_plugin_fields.rs b/crates/ui-egui/src/dialogs/tests_plugin_fields.rs index f5f4e719a0..8d2eaeab8a 100644 --- a/crates/ui-egui/src/dialogs/tests_plugin_fields.rs +++ b/crates/ui-egui/src/dialogs/tests_plugin_fields.rs @@ -1,7 +1,7 @@ //! A plug-in's parameters in its dialog as its manifest presents them (docs/plugins.md › //! Parameters): labels, units after the values, help on the labels and a button to its page, -//! sections by group, text and lists of numbers, and parameters shown only while their -//! `visibleWhen` holds. The plug-in is removed after each test: plug-ins are process-wide. +//! sections by group, text and lists of numbers, parameters shown only while their +//! `visibleWhen` holds, and sliders. The plug-in is removed after each test: plug-ins are process-wide. use std::sync::{Arc, Mutex}; @@ -130,6 +130,198 @@ fn the_help_button_opens_the_parameter_s_page() { remove(&mut h, id); } +/// A plug-in's dialog draws a slider for a number that asks for one, named by its row's label, +/// and none for one that doesn't. Screen readers' steps move it by the parameter's `step`, counted +/// from `min`; a value they set lands on the step's grid. Drawing a slider leaves a value off its +/// grid as it is, a fractional step gives the plug-in the step's own decimals, a range under 1 +/// without a step still moves, and a drag reports itself to the dialog's preview while it lasts. +#[test] +fn a_plug_in_number_that_asks_for_a_slider_gets_one_that_steps_by_its_step() { + use egui::accesskit::{Action, ActionData, ActionRequest, Role}; + use egui_kittest::kittest::NodeT; + type Rows = egui_kittest::Harness<'static, (Dialog, vectorcraft_plugins::Manifest)>; + let m = vectorcraft_plugins::Manifest::parse( + br#"{"id":"test.area","name":"Area","kind":"filter","params":{ + "area":{"type":"number","min":0,"max":100,"default":10,"label":"Area","widget":"slider","step":5}, + "plain":{"type":"number","min":0,"max":100,"default":10,"label":"Plain"}, + "third":{"type":"int","min":1,"max":20,"default":1,"label":"Third","widget":"slider","step":3}, + "odd":{"type":"number","min":0,"max":100,"default":12,"label":"Odd","widget":"slider","step":5}, + "tenth":{"type":"number","min":0,"max":1,"default":0,"label":"Tenth","widget":"slider","step":0.1}, + "tiny":{"type":"number","min":0,"max":0.004,"default":0.001,"label":"Tiny","widget":"slider"}, + "milli":{"type":"number","min":0,"max":1,"default":0.004,"label":"Milli","widget":"slider","step":0.001}}}"#, + ) + .unwrap(); + let fields = json!({ "area": 10, "plain": 10, "third": 1, "odd": 12, "tenth": 0, "tiny": 0.001, "milli": 0.004 }); + let dialog = Dialog::new(plugin::KIND, fields); + let mut h: Rows = egui_kittest::Harness::builder().with_size(vec2(520.0, 480.0)).build_ui_state( + |ui, (d, m): &mut (Dialog, vectorcraft_plugins::Manifest)| { + form::schema_rows(ui, d, m); + }, + (dialog, m), + ); + h.run(); + let value = |h: &Rows, key: &str| h.state().0.fields[key].as_f64().unwrap(); + let act = |h: &mut Rows, label: &str, action: Action, data: Option| { + let (target_node, target_tree) = h.get_by_role_and_label(Role::Slider, label).accesskit_node().locate(); + h.event(egui::Event::AccessKitActionRequest(ActionRequest { target_node, target_tree, action, data })); + h.run(); + }; + assert_eq!(h.query_all_by_role(Role::Slider).count(), 6, "only the parameters that ask for one have a slider"); + // A number field shows the places its slider moves to. + assert!(h.query_all_by_value("0.004").next().is_some(), "Milli's field shows 0.004"); + assert_eq!((value(&h, "odd"), value(&h, "tiny")), (12.0, 0.001), "values off the sliders' grids are kept"); + h.state_mut().0.fields.extend([("odd".into(), json!(13)), ("tenth".into(), json!(0.15))]); + h.run(); + assert_eq!((value(&h, "odd"), value(&h, "tenth")), (13.0, 0.15), "typed values are kept"); + h.state_mut().0.fields.insert("tenth".into(), json!(0)); + let node = h.get_by_role_and_label(Role::Slider, "Area:").accesskit_node(); + assert_eq!((node.numeric_value(), node.min_numeric_value(), node.max_numeric_value()), (Some(10.0), Some(0.0), Some(100.0))); + act(&mut h, "Area:", Action::Increment, None); + assert_eq!(value(&h, "area"), 15.0, "one step up"); + act(&mut h, "Area:", Action::SetValue, Some(ActionData::NumericValue(47.0))); + let set = value(&h, "area"); + assert!((set / 5.0).fract() == 0.0 && (set - 47.0).abs() <= 2.5, "47 lands on the nearest step: {set}"); + // The grid is counted from `min`: 1, 4, 7. + act(&mut h, "Third:", Action::Increment, None); + act(&mut h, "Third:", Action::Increment, None); + assert_eq!(h.state().0.fields["third"], json!(7)); + for _ in 0..3 { + act(&mut h, "Tenth:", Action::Increment, None); + } + assert_eq!(h.state().0.fields["tenth"], json!(0.3)); + act(&mut h, "Tiny:", Action::SetValue, Some(ActionData::NumericValue(0.0025))); + let tiny = value(&h, "tiny"); + assert!((tiny - 0.0025).abs() < 0.0001, "a small range still moves: {tiny}"); + // Dragging along the rail moves the value and marks the drag for the preview until it ends. + let rail = h.get_by_role_and_label(Role::Slider, "Area:").rect(); + let at = |x: f32| egui::pos2(rail.left() + x * rail.width(), rail.center().y); + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + h.event(egui::Event::PointerMoved(at(0.2))); + h.event(button(at(0.2), true)); + h.run(); + for x in [0.4, 0.6, 0.8] { + h.event(egui::Event::PointerMoved(at(x))); + h.run(); + } + assert!(h.state().0.bool("__sliding"), "the drag is in progress"); + let dragged = value(&h, "area"); + assert!(dragged > set && (dragged / 5.0).fract() == 0.0 && dragged <= 100.0, "moved right on the grid: {dragged}"); + h.event(button(at(0.8), false)); + h.run(); + assert!(!h.state().0.bool("__sliding"), "the drag ended"); +} + +/// During a drag on a plug-in parameter's slider, the preview runs at most every +/// [`form::SLIDE_PREVIEW_EVERY`] on the latest value, and the value the drag ends on previews even +/// when its turn hadn't come; outside a drag every change previews at once. +#[test] +fn a_slider_drag_previews_a_few_times_a_second_and_its_last_value() { + let mut slide = form::SlidePreview::default(); + let frame = 1.0 / 60.0; + // A drag of one second, with a new value on every frame. + let previews = (0..60).filter(|i| slide.due(*i as f64 * frame, true, true) == Ok(true)).count(); + assert!(previews > 1 && previews <= (1.0 / form::SLIDE_PREVIEW_EVERY) as usize + 1, "{previews} previews in 60 frames"); + // A change just after a preview waits; the frame the drag ends on previews it. + assert_eq!(slide.due(1.5, true, true), Ok(true)); + assert!(slide.due(1.5 + frame, true, true).is_err() && slide.held, "the last change is still to preview"); + assert_eq!(slide.due(1.5 + 2.0 * frame, false, false), Ok(true)); + assert_eq!(slide.due(1.5 + 3.0 * frame, false, false), Ok(false), "nothing left to preview"); + // A change that waits previews on the first frame after its wait, even without another change. + assert_eq!(slide.due(2.0, true, true), Ok(true)); + let wait = slide.due(2.0 + frame, true, true).expect_err("too soon after the last preview"); + assert!(wait > 0.0 && wait <= form::SLIDE_PREVIEW_EVERY); + assert_eq!(slide.due(2.0 + frame + wait, true, false), Ok(true)); + // Outside a drag, a change previews at once however soon it comes. + assert_eq!((slide.due(3.0, false, true), slide.due(3.0 + frame, false, true)), (Ok(true), Ok(true))); +} + +/// A filter's and a live effect's dialogs, at frames a sixtieth of a second apart: a drag on a +/// slider previews fewer values than it has frames, and the value it ends on previews. In the +/// filter's dialog, turning Preview off during the drag rolls the preview back at once. +#[test] +fn a_slider_drag_in_a_plug_in_dialog_previews_a_few_times_a_second() { + use egui::accesskit::Role; + let params = r#"{"area":{"type":"number","min":0,"max":100,"default":10,"label":"Area","widget":"slider","step":1}}"#; + for kind in ["filter", "effect"] { + let id = format!("test.ui.fields.slide{kind}"); + let mut app = VectorcraftApp::new(Session::new(), Default::default()); + app.run("file.new", json!({"width": 200, "height": 200})).unwrap(); + let shape = app.run("shape.rectangle", json!({"x": 10, "y": 10, "width": 50, "height": 50})).unwrap()["id"].as_u64().unwrap(); + let wasm = wat::parse_str(tpl::module(&tpl::manifest(&id, kind, params), tpl::ECHO, "", 1)).unwrap(); + app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wasm)})).unwrap(); + match kind { + "filter" => app.run("plugin.dialog", json!({"id": id})), + _ => app.run("effect.dialog", json!({"effect": vectorcraft_plugins::effect::effect_id(&id)})), + } + .unwrap(); + let mut fonts = false; + let mut h: Harness = egui_kittest::Harness::builder().with_size(vec2(900.0, 800.0)).with_step_dt(1.0 / 60.0).build_ui_state( + move |ui, app: &mut VectorcraftApp| { + if !std::mem::replace(&mut fonts, true) { + crate::theme::install_fonts(ui.ctx()); + return; + } + show(app, ui.ctx()); + }, + app, + ); + h.run_steps(4); + set(&mut h, "preview", json!(true)); + // What the canvas shows: the filter's last previewed params, the effect's previewed value. + let previewed = |h: &Harness| match kind { + "filter" => h.state().ui.dialog.as_ref().and_then(|d| d.fields.get(form::PREVIEWED)).map(|p| p["params"]["area"].clone()), + _ => { + let doc = h.state().session.doc().unwrap(); + doc.doc.node(vectorcraft_doc::NodeId(shape)).and_then(|n| n.appearance.effects.last()).map(|e| e.params["area"].clone()) + } + }; + let area = |h: &Harness| h.state().ui.dialog.as_ref().expect("the dialog is open").fields["area"].clone(); + let rail = h.get_by_role_and_label(Role::Slider, "Area:").rect(); + let at = |x: f32| egui::pos2(rail.left() + x * rail.width(), rail.center().y); + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + h.event(egui::Event::PointerMoved(at(0.1))); + h.event(button(at(0.1), true)); + h.step(); + let mut seen = vec![]; + for i in 1..=30 { + h.event(egui::Event::PointerMoved(at(0.1 + 0.025 * i as f32))); + h.step(); + let shown = previewed(&h); + if seen.last() != Some(&shown) { + seen.push(shown); + } + } + assert!(seen.len() > 2 && seen.len() < 15, "{kind}: {} values previewed in 30 frames: {seen:?}", seen.len()); + h.event(button(at(0.85), false)); + h.step(); + h.step(); + assert_eq!(previewed(&h), Some(area(&h)), "{kind}: the value the drag ended on previews"); + if kind == "filter" { + // A second drag, until a frame previews; the next frame waits, and Preview off rolls back then. + h.event(button(at(0.5), true)); + h.step(); + for i in 1..=10 { + let before = previewed(&h); + h.event(egui::Event::PointerMoved(at(0.5 - 0.02 * i as f32))); + h.step(); + if previewed(&h) != before { + break; + } + } + h.state_mut().ui.dialog.as_mut().unwrap().fields.insert("preview".into(), json!(false)); + h.event(egui::Event::PointerMoved(at(0.2))); + h.step(); + assert_eq!(previewed(&h), None, "Preview off rolled the preview back"); + assert!(!h.state().session.in_interaction(), "and ended its interaction"); + h.event(button(at(0.2), false)); + h.step(); + } + h.state_mut().ui.dialog = None; + let _ = h.state_mut().session.cancel_interaction(); + remove(&mut h, &id); + } +} + /// `CRAFT_UI_PLUGIN_FIELDS_SHOT=` saves a picture of a dialog whose parameters use every /// presentation key there, and the test plug-in beside it (`hatch-test-filter.wasm`) to install in /// the app. Its parameter names are written as many plug-ins write them, in snake case, and it uses diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index e4271f7926..a29912a288 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -7749,6 +7749,11 @@ variable-list-end {0}, {1} {0} i {1} @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` anomena `{other}`, que no és un paràmetre declarat abans d’aquest @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` anomena com a màxim {MAX_CONDITIONS} paràmetres @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` pren els valors de `{other}`, d’una casella de selecció o d’una opció +@msg `step` is only for a parameter with a slider `step` només s’aplica a un paràmetre amb control lliscant +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} un control lliscant necessita `min` inferior a `max`, i un de `int` un interval dins de ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters un control lliscant només s’aplica a paràmetres `number` i `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` ha de ser un nombre superior a 0 i com a màxim `max` menys `min` +@msg an `int` parameter's `step` must be a whole number el `step` d’un paràmetre `int` ha de ser un nombre enter @msg `visible` must be true or false `visible` ha de ser true o false @msg `{key}` must be a number from {_1} to {_2} `{key}` ha de ser un nombre de {_1} a {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` ha de ser una matriu de {MAX_ITEMS} entrades com a màxim diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 488df173c3..df10024d18 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -7359,6 +7359,11 @@ axis Y Axis osa Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` uvádí `{other}`, což není parametr deklarovaný před tímto @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` smí uvádět nejvýše {MAX_CONDITIONS} parametrů @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` přebírá hodnoty `{other}`, a to zaškrtávacího políčka nebo volby +@msg `step` is only for a parameter with a slider `step` je jen pro parametr s posuvníkem +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} posuvník potřebuje `min` menší než `max` a posuvník typu `int` rozsah v mezích ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters posuvník je jen pro parametry `number` a `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` musí být číslo větší než 0 a nejvýše `max` minus `min` +@msg an `int` parameter's `step` must be a whole number `step` parametru `int` musí být celé číslo @msg `visible` must be true or false `visible` musí být true nebo false @msg `{key}` must be a number from {_1} to {_2} `{key}` musí být číslo od {_1} do {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` musí být pole s nejvýše {MAX_ITEMS} položkami diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 302ab6aa69..64a5722e1c 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -590,6 +590,11 @@ liquify-list-end {0}, {1} {0} og {1} @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` angiver `{other}`, som ikke er en parameter, der er erklæret før denne @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` angiver højst {MAX_CONDITIONS} parametre @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` tager værdierne for `{other}`, fra et afkrydsningsfelt eller et valg +@msg `step` is only for a parameter with a slider `step` gælder kun for en parameter med skyder +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} en skyder kræver, at `min` er mindre end `max`, og en `int`-skyder et interval inden for ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters en skyder gælder kun for `number`- og `int`-parametre +@msg `step` must be a number above 0 and at most `max` minus `min` `step` skal være et tal over 0 og højst `max` minus `min` +@msg an `int` parameter's `step` must be a whole number `step` for en `int`-parameter skal være et heltal @msg `visible` must be true or false `visible` skal være true eller false @msg `{key}` must be a number from {_1} to {_2} `{key}` skal være et tal fra {_1} til {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` skal være et array med højst {MAX_ITEMS} elementer diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 9482345f18..84ba615bcc 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -6942,6 +6942,11 @@ axis Y Axis Y-Achse @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nennt `{other}`, aber das ist kein Parameter, der vor diesem deklariert ist @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` darf höchstens {MAX_CONDITIONS} Parameter nennen @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` nimmt die Werte von `{other}` an, die eines Kontrollkästchens oder einer Auswahl +@msg `step` is only for a parameter with a slider `step` gibt es nur für einen Parameter mit Schieberegler +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} ein Schieberegler braucht `min` unter `max`, und ein `int`-Schieberegler einen Bereich innerhalb von ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters ein Schieberegler ist nur für `number`- und `int`-Parameter +@msg `step` must be a number above 0 and at most `max` minus `min` `step` muss eine Zahl über 0 und höchstens `max` minus `min` sein +@msg an `int` parameter's `step` must be a whole number der `step` eines `int`-Parameters muss eine ganze Zahl sein @msg `visible` must be true or false `visible` muss true oder false sein @msg `{key}` must be a number from {_1} to {_2} `{key}` muss eine Zahl von {_1} bis {_2} sein @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` muss ein Array mit höchstens {MAX_ITEMS} Einträgen sein diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index 434d0cc0b8..a3daf1f4e8 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -7349,6 +7349,11 @@ axis Y Axis Άξονας Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one το `visibleWhen` αναφέρει το `{other}`, που δεν είναι παράμετρος δηλωμένη πριν από αυτήν @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters το `visibleWhen` αναφέρει έως {MAX_CONDITIONS} παραμέτρους @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice το `visibleWhen` δέχεται τιμές του `{other}`, ενός πλαισίου ελέγχου ή μιας επιλογής +@msg `step` is only for a parameter with a slider το `step` ισχύει μόνο για παράμετρο με ρυθμιστικό +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} ένα ρυθμιστικό χρειάζεται `min` μικρότερο από `max`, και ένα ρυθμιστικό `int` εύρος εντός ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters ένα ρυθμιστικό ισχύει μόνο για παραμέτρους `number` και `int` +@msg `step` must be a number above 0 and at most `max` minus `min` το `step` πρέπει να είναι αριθμός μεγαλύτερος από 0 και το πολύ `max` μείον `min` +@msg an `int` parameter's `step` must be a whole number το `step` μιας παραμέτρου `int` πρέπει να είναι ακέραιος αριθμός @msg `visible` must be true or false το `visible` πρέπει να είναι true ή false @msg `{key}` must be a number from {_1} to {_2} το `{key}` πρέπει να είναι αριθμός από {_1} έως {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries το `{key}` πρέπει να είναι πίνακας έως {MAX_ITEMS} στοιχείων diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 3f83e928e4..a40f5a08ea 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -7335,6 +7335,11 @@ axis Y Axis Eje Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nombra `{other}`, que no es un parámetro declarado antes de este @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` nombra como máximo {MAX_CONDITIONS} parámetros @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` toma los valores de `{other}`, de una casilla de verificación o una opción +@msg `step` is only for a parameter with a slider `step` solo es para un parámetro con control deslizante +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} un control deslizante necesita `min` menor que `max`, y uno de `int` un intervalo dentro de ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters un control deslizante solo es para parámetros `number` e `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` debe ser un número mayor que 0 y como máximo `max` menos `min` +@msg an `int` parameter's `step` must be a whole number el `step` de un parámetro `int` debe ser un número entero @msg `visible` must be true or false `visible` debe ser true o false @msg `{key}` must be a number from {_1} to {_2} `{key}` debe ser un número de {_1} a {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` debe ser una lista de {MAX_ITEMS} entradas como máximo diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index a4d85b23e8..652508fccb 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -7426,6 +7426,11 @@ axis Y Axis Y-akseli @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nimeää parametrin `{other}`, jota ei ole esitelty ennen tätä parametria @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` nimeää enintään {MAX_CONDITIONS} parametria @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` ottaa parametrin `{other}` arvot, valintaruudun tai valinnan arvot +@msg `step` is only for a parameter with a slider `step` on vain liukusäätimellä varustetulle parametrille +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} liukusäädin vaatii, että `min` on pienempi kuin `max`, ja `int`-liukusäädin alueen välillä ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters liukusäädin on vain `number`- ja `int`-parametreille +@msg `step` must be a number above 0 and at most `max` minus `min` `step`-arvon on oltava 0:aa suurempi luku ja enintään `max` miinus `min` +@msg an `int` parameter's `step` must be a whole number `int`-parametrin `step`-arvon on oltava kokonaisluku @msg `visible` must be true or false `visible` on oltava true tai false @msg `{key}` must be a number from {_1} to {_2} `{key}` on oltava luku {_1} ja {_2} väliltä @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` on oltava enintään {MAX_ITEMS} kohteen taulukko diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 8f56486157..7060ca0afb 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -7355,6 +7355,11 @@ axis Y Axis Axe Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nomme `{other}`, qui n’est pas un paramètre déclaré avant celui-ci @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` nomme au plus {MAX_CONDITIONS} paramètres @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` prend les valeurs de `{other}`, celles d’une case à cocher ou d’un choix +@msg `step` is only for a parameter with a slider `step` ne s’applique qu’à un paramètre avec un curseur +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} un curseur exige `min` inférieur à `max`, et un curseur `int` une plage comprise dans ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters un curseur ne s’applique qu’aux paramètres `number` et `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` doit être un nombre supérieur à 0 et au plus égal à `max` moins `min` +@msg an `int` parameter's `step` must be a whole number le `step` d’un paramètre `int` doit être un nombre entier @msg `visible` must be true or false `visible` doit valoir true ou false @msg `{key}` must be a number from {_1} to {_2} `{key}` doit être un nombre de {_1} à {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` doit être un tableau d’au plus {MAX_ITEMS} entrées diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index e9509d9202..22b5cd3a64 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -6543,6 +6543,11 @@ arrowhead Feather पंख @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` में `{other}` दिया गया है, जो इससे पहले घोषित पैरामीटर नहीं है @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` में अधिकतम {MAX_CONDITIONS} पैरामीटर हो सकते हैं @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` `{other}` के मान लेता है, जो चेकबॉक्स या विकल्प होना चाहिए +@msg `step` is only for a parameter with a slider `step` केवल स्लाइडर वाले पैरामीटर के लिए है +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} स्लाइडर के लिए `min` का `max` से कम होना ज़रूरी है, और `int` स्लाइडर की सीमा ±{EXACT_INT} के भीतर होनी चाहिए +@msg a slider is only for `number` and `int` parameters स्लाइडर केवल `number` और `int` पैरामीटर के लिए है +@msg `step` must be a number above 0 and at most `max` minus `min` `step` 0 से बड़ी और अधिकतम `max` घटा `min` जितनी संख्या होनी चाहिए +@msg an `int` parameter's `step` must be a whole number `int` पैरामीटर का `step` पूर्ण संख्या होना चाहिए @msg `visible` must be true or false `visible` true या false होना चाहिए @msg `{key}` must be a number from {_1} to {_2} `{key}` {_1} से {_2} तक की संख्या होना चाहिए @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` अधिकतम {MAX_ITEMS} प्रविष्टियों का ऐरे होना चाहिए diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 87f050ef0d..6b8edaec62 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -7344,6 +7344,11 @@ axis Y Axis Y tengely @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one a `visibleWhen` ezt nevezi meg: `{other}`, de ez nem az ennél korábban megadott paraméterek egyike @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters a `visibleWhen` legfeljebb {MAX_CONDITIONS} paramétert nevezhet meg @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice a `visibleWhen` a(z) `{other}` értékeit veszi át, egy jelölőnégyzetét vagy egy választásét +@msg `step` is only for a parameter with a slider a `step` csak csúszkás paraméterhez adható meg +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} a csúszkához a `min` értéknek kisebbnek kell lennie a `max` értéknél, egy `int` csúszka tartományának pedig ±{EXACT_INT} között kell lennie +@msg a slider is only for `number` and `int` parameters csúszka csak `number` és `int` paraméterhez adható +@msg `step` must be a number above 0 and at most `max` minus `min` a `step` értéke 0-nál nagyobb és legfeljebb `max` mínusz `min` lehet +@msg an `int` parameter's `step` must be a whole number egy `int` paraméter `step` értékének egész számnak kell lennie @msg `visible` must be true or false `visible`: true vagy false kell @msg `{key}` must be a number from {_1} to {_2} `{key}`: {_1} és {_2} közötti szám kell @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}`: legfeljebb {MAX_ITEMS} elemű tömb kell diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index 924d3d80b5..edd22bccda 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -472,6 +472,11 @@ @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` menyebut `{other}`, yang bukan parameter yang dideklarasikan sebelum parameter ini @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` menyebut paling banyak {MAX_CONDITIONS} parameter @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` menerima nilai `{other}`, dari kotak centang atau pilihan +@msg `step` is only for a parameter with a slider `step` hanya untuk parameter dengan penggeser +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} penggeser memerlukan `min` di bawah `max`, dan penggeser `int` memerlukan rentang dalam ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters penggeser hanya untuk parameter `number` dan `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` harus berupa angka di atas 0 dan paling banyak `max` dikurangi `min` +@msg an `int` parameter's `step` must be a whole number `step` parameter `int` harus berupa bilangan bulat @msg `visible` must be true or false `visible` harus true atau false @msg `{key}` must be a number from {_1} to {_2} `{key}` harus berupa angka dari {_1} sampai {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` harus berupa larik berisi paling banyak {MAX_ITEMS} entri diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index 5f47e3f117..c51dbd94ed 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -6981,6 +6981,11 @@ axis Y Axis Asse Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nomina `{other}`, che non è un parametro dichiarato prima di questo @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` nomina al massimo {MAX_CONDITIONS} parametri @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` accetta i valori di `{other}`, quelli di una casella di controllo o di una scelta +@msg `step` is only for a parameter with a slider `step` vale solo per un parametro con cursore +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} un cursore richiede `min` minore di `max`, e un cursore `int` un intervallo entro ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters un cursore vale solo per i parametri `number` e `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` deve essere un numero maggiore di 0 e al massimo `max` meno `min` +@msg an `int` parameter's `step` must be a whole number lo `step` di un parametro `int` deve essere un numero intero @msg `visible` must be true or false `visible` deve essere true o false @msg `{key}` must be a number from {_1} to {_2} `{key}` deve essere un numero da {_1} a {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` deve essere un array di al massimo {MAX_ITEMS} voci diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 9a1b5f6354..c17c753429 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -7056,6 +7056,11 @@ axis Y Axis Y 軸 @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` が指定した `{other}` は、このパラメーターより前に宣言されたパラメーターではありません @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` に指定できるパラメーターは {MAX_CONDITIONS} 個までです @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` が受け取るのは、チェックボックスか選択肢である `{other}` の値です +@msg `step` is only for a parameter with a slider `step` はスライダーのあるパラメーターにのみ指定できます +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} スライダーには `max` より小さい `min` が必要で、`int` のスライダーの範囲は ±{EXACT_INT} 以内である必要があります +@msg a slider is only for `number` and `int` parameters スライダーは `number` と `int` のパラメーターにのみ使えます +@msg `step` must be a number above 0 and at most `max` minus `min` `step` は 0 より大きく、`max` から `min` を引いた値以下の数値である必要があります +@msg an `int` parameter's `step` must be a whole number `int` パラメーターの `step` は整数である必要があります @msg `visible` must be true or false `visible` は true または false にしてください @msg `{key}` must be a number from {_1} to {_2} `{key}` は {_1} から {_2} の数値にしてください @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` は {MAX_ITEMS} 項目以下の配列にしてください diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 8eeacee621..358338736d 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -9462,6 +9462,11 @@ axis Y Axis Y ღერძი @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` ასახელებს `{other}`-ს, რომელიც ამაზე ადრე გამოცხადებული პარამეტრი არ არის @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` ასახელებს არაუმეტეს {MAX_CONDITIONS} პარამეტრს @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` იღებს `{other}`-ის მნიშვნელობებს, მოსანიშნი ველის ან არჩევანისას +@msg `step` is only for a parameter with a slider `step` მხოლოდ სლაიდერიანი პარამეტრისთვისაა +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} სლაიდერს სჭირდება `min`, რომელიც `max`-ზე ნაკლებია, ხოლო `int` სლაიდერს დიაპაზონი ±{EXACT_INT}-ის ფარგლებში +@msg a slider is only for `number` and `int` parameters სლაიდერი მხოლოდ `number` და `int` პარამეტრებისთვისაა +@msg `step` must be a number above 0 and at most `max` minus `min` `step` უნდა იყოს 0-ზე მეტი რიცხვი და არაუმეტეს `max` მინუს `min` +@msg an `int` parameter's `step` must be a whole number `int` პარამეტრის `step` მთელი რიცხვი უნდა იყოს @msg `visible` must be true or false `visible` უნდა იყოს true ან false @msg `{key}` must be a number from {_1} to {_2} `{key}` უნდა იყოს რიცხვი {_1}-დან {_2}-მდე @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` უნდა იყოს მასივი, არაუმეტეს {MAX_ITEMS} ელემენტით diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 57e0b8be10..c6342c4d2a 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -6953,6 +6953,11 @@ axis Y Axis Y축 @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen`이 지정한 `{other}`은(는) 이 매개변수보다 앞에 선언된 매개변수가 아닙니다 @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen`에는 매개변수를 최대 {MAX_CONDITIONS}개까지 지정할 수 있습니다 @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen`은 확인란 또는 선택 항목인 `{other}`의 값을 받습니다 +@msg `step` is only for a parameter with a slider `step`은 슬라이더가 있는 매개변수에만 쓸 수 있습니다 +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} 슬라이더에는 `max`보다 작은 `min`이 필요하며, `int` 슬라이더의 범위는 ±{EXACT_INT} 이내여야 합니다 +@msg a slider is only for `number` and `int` parameters 슬라이더는 `number` 및 `int` 매개변수에만 쓸 수 있습니다 +@msg `step` must be a number above 0 and at most `max` minus `min` `step`은 0보다 크고 `max`에서 `min`을 뺀 값 이하인 숫자여야 합니다 +@msg an `int` parameter's `step` must be a whole number `int` 매개변수의 `step`은 정수여야 합니다 @msg `visible` must be true or false `visible`은(는) true 또는 false여야 합니다 @msg `{key}` must be a number from {_1} to {_2} `{key}`은(는) {_1}에서 {_2} 사이의 숫자여야 합니다 @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}`은(는) 항목이 최대 {MAX_ITEMS}개인 배열이어야 합니다 diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 5ed5cdc3e0..4955b377ad 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -436,6 +436,11 @@ liquify-list-end {0}, {1} {0} en {1} @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` noemt `{other}`, dat geen parameter is die vóór deze is gedeclareerd @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` noemt maximaal {MAX_CONDITIONS} parameters @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` neemt de waarden van `{other}`, een selectievakje of een keuzelijst +@msg `step` is only for a parameter with a slider `step` geldt alleen voor een parameter met een schuifregelaar +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} een schuifregelaar vereist dat `min` kleiner is dan `max`, en een `int`-schuifregelaar een bereik binnen ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters een schuifregelaar geldt alleen voor `number`- en `int`-parameters +@msg `step` must be a number above 0 and at most `max` minus `min` `step` moet een getal groter dan 0 zijn en hoogstens `max` min `min` +@msg an `int` parameter's `step` must be a whole number de `step` van een `int`-parameter moet een geheel getal zijn @msg `visible` must be true or false `visible` moet true of false zijn @msg `{key}` must be a number from {_1} to {_2} `{key}` moet een getal van {_1} tot {_2} zijn @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` moet een array van maximaal {MAX_ITEMS} items zijn diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 74029133dc..9063b84bfb 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -7214,6 +7214,11 @@ axis Y Axis Oś Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` wskazuje `{other}`, który nie jest parametrem zadeklarowanym przed tym @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` wskazuje co najwyżej {MAX_CONDITIONS} parametrów @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` przyjmuje wartości `{other}`, czyli pola wyboru lub listy opcji +@msg `step` is only for a parameter with a slider `step` dotyczy tylko parametru z suwakiem +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} suwak wymaga `min` mniejszego niż `max`, a suwak `int` zakresu w granicach ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters suwak jest tylko dla parametrów `number` i `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` musi być liczbą większą od 0 i co najwyżej równą `max` minus `min` +@msg an `int` parameter's `step` must be a whole number `step` parametru `int` musi być liczbą całkowitą @msg `visible` must be true or false `visible` musi mieć wartość true lub false @msg `{key}` must be a number from {_1} to {_2} `{key}` musi być liczbą od {_1} do {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` musi być tablicą o co najwyżej {MAX_ITEMS} elementach diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index a1747af0b2..f20f0d9004 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -7258,6 +7258,11 @@ axis Y Axis Eixo Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nomeia `{other}`, que não é um parâmetro declarado antes deste @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` nomeia no máximo {MAX_CONDITIONS} parâmetros @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` aceita os valores de `{other}`, de uma caixa de seleção ou de uma escolha +@msg `step` is only for a parameter with a slider `step` só vale para um parâmetro com controle deslizante +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} um controle deslizante precisa de `min` menor que `max`, e um de `int` de um intervalo dentro de ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters um controle deslizante só vale para parâmetros `number` e `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` deve ser um número maior que 0 e no máximo `max` menos `min` +@msg an `int` parameter's `step` must be a whole number o `step` de um parâmetro `int` deve ser um número inteiro @msg `visible` must be true or false `visible` deve ser true ou false @msg `{key}` must be a number from {_1} to {_2} `{key}` deve ser um número de {_1} a {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` deve ser uma matriz de no máximo {MAX_ITEMS} entradas diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index ca0c8d5145..1657ca8814 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -6981,6 +6981,11 @@ axis Y Axis Ось Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` указывает `{other}`, но это не параметр, объявленный раньше этого @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` указывает не более {MAX_CONDITIONS} параметров @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` принимает значения `{other}`, флажка или списка вариантов +@msg `step` is only for a parameter with a slider `step` допустим только для параметра с ползунком +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} ползунку нужен `min` меньше `max`, а ползунку `int` диапазон в пределах ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters ползунок допустим только для параметров `number` и `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` должен быть числом больше 0 и не больше `max` минус `min` +@msg an `int` parameter's `step` must be a whole number `step` параметра `int` должен быть целым числом @msg `visible` must be true or false `visible` должно быть true или false @msg `{key}` must be a number from {_1} to {_2} `{key}` должно быть числом от {_1} до {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` должно быть массивом не более чем из {MAX_ITEMS} элементов diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index c26474cf93..cd3840d1e6 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -7371,6 +7371,11 @@ axis Y Axis Y-axel @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` anger `{other}`, som inte är en parameter som deklarerats före den här @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` anger högst {MAX_CONDITIONS} parametrar @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` tar värden från `{other}`, en kryssruta eller ett val +@msg `step` is only for a parameter with a slider `step` gäller bara en parameter med skjutreglage +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} ett skjutreglage kräver att `min` är mindre än `max`, och ett `int`-skjutreglage ett intervall inom ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters ett skjutreglage gäller bara `number`- och `int`-parametrar +@msg `step` must be a number above 0 and at most `max` minus `min` `step` måste vara ett tal över 0 och högst `max` minus `min` +@msg an `int` parameter's `step` must be a whole number `step` för en `int`-parameter måste vara ett heltal @msg `visible` must be true or false `visible` måste vara true eller false @msg `{key}` must be a number from {_1} to {_2} `{key}` måste vara ett tal från {_1} till {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` måste vara en array med högst {MAX_ITEMS} poster diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 82186ebcdd..57a4c47f81 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -7431,6 +7431,11 @@ axis Y Axis Y ekseni @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` `{other}` adını veriyor, ancak bu, bundan önce bildirilmiş bir parametre değil @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` en fazla {MAX_CONDITIONS} parametre adı verir @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen`, bir onay kutusu veya seçim olan `{other}` parametresinin değerlerini alır +@msg `step` is only for a parameter with a slider `step` yalnızca kaydırıcısı olan bir parametre içindir +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} bir kaydırıcı için `min`, `max` değerinden küçük olmalı; bir `int` kaydırıcının aralığı ise ±{EXACT_INT} içinde olmalıdır +@msg a slider is only for `number` and `int` parameters kaydırıcı yalnızca `number` ve `int` parametreleri içindir +@msg `step` must be a number above 0 and at most `max` minus `min` `step`, 0'dan büyük ve en fazla `max` eksi `min` olan bir sayı olmalıdır +@msg an `int` parameter's `step` must be a whole number bir `int` parametresinin `step` değeri tam sayı olmalıdır @msg `visible` must be true or false `visible` true veya false olmalıdır @msg `{key}` must be a number from {_1} to {_2} `{key}` {_1} ile {_2} arasında bir sayı olmalıdır @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` en fazla {MAX_ITEMS} öğeli bir dizi olmalıdır diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index de3329ef10..01a0c98178 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -6963,6 +6963,11 @@ axis Y Axis Вісь Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` указує `{other}`, але це не параметр, оголошений раніше за цей @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` указує не більше {MAX_CONDITIONS} параметрів @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` приймає значення `{other}`, прапорця або списку варіантів +@msg `step` is only for a parameter with a slider `step` допустимий лише для параметра з повзунком +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} повзунку потрібен `min`, менший за `max`, а повзунку `int` діапазон у межах ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters повзунок допустимий лише для параметрів `number` і `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` має бути числом, більшим за 0 і не більшим за `max` мінус `min` +@msg an `int` parameter's `step` must be a whole number `step` параметра `int` має бути цілим числом @msg `visible` must be true or false `visible` має бути true або false @msg `{key}` must be a number from {_1} to {_2} `{key}` має бути числом від {_1} до {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` має бути масивом не більше ніж із {MAX_ITEMS} елементів diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 675143a8d6..dd3c11a1fd 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -7010,6 +7010,11 @@ axis Y Axis Trục Y @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` nêu `{other}`, nhưng đó không phải là tham số được khai báo trước tham số này @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` nêu tối đa {MAX_CONDITIONS} tham số @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` nhận giá trị của `{other}`, là một hộp kiểm hoặc một lựa chọn +@msg `step` is only for a parameter with a slider `step` chỉ dành cho tham số có thanh trượt +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} thanh trượt cần `min` nhỏ hơn `max`, và thanh trượt `int` cần phạm vi trong khoảng ±{EXACT_INT} +@msg a slider is only for `number` and `int` parameters thanh trượt chỉ dành cho tham số `number` và `int` +@msg `step` must be a number above 0 and at most `max` minus `min` `step` phải là số lớn hơn 0 và tối đa bằng `max` trừ `min` +@msg an `int` parameter's `step` must be a whole number `step` của tham số `int` phải là số nguyên @msg `visible` must be true or false `visible` phải là true hoặc false @msg `{key}` must be a number from {_1} to {_2} `{key}` phải là một số từ {_1} đến {_2} @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` phải là một mảng có tối đa {MAX_ITEMS} mục diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 57f6a4403b..6fab818bd8 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -7191,6 +7191,11 @@ axis Y Axis Y 轴 @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` 指定了 `{other}`,但它不是在此参数之前声明的参数 @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` 最多指定 {MAX_CONDITIONS} 个参数 @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` 接受 `{other}` 的值,该参数须为复选框或选项 +@msg `step` is only for a parameter with a slider `step` 仅适用于带滑块的参数 +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} 滑块需要 `min` 小于 `max`,`int` 滑块的范围须在 ±{EXACT_INT} 以内 +@msg a slider is only for `number` and `int` parameters 滑块仅适用于 `number` 和 `int` 参数 +@msg `step` must be a number above 0 and at most `max` minus `min` `step` 必须是大于 0 且不超过 `max` 减 `min` 的数 +@msg an `int` parameter's `step` must be a whole number `int` 参数的 `step` 必须是整数 @msg `visible` must be true or false `visible` 必须是 true 或 false @msg `{key}` must be a number from {_1} to {_2} `{key}` 必须是 {_1} 到 {_2} 之间的数字 @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` 必须是最多 {MAX_ITEMS} 项的数组 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 9834c17ea6..63003da6b7 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -7012,6 +7012,11 @@ axis Y Axis Y 軸 @msg `visibleWhen` names `{other}`, which isn't a parameter declared before this one `visibleWhen` 指定了 `{other}`,但它不是在此參數之前宣告的參數 @msg `visibleWhen` names at most {MAX_CONDITIONS} parameters `visibleWhen` 最多指定 {MAX_CONDITIONS} 個參數 @msg `visibleWhen` takes `{other}`'s values, of a checkbox or a choice `visibleWhen` 接受 `{other}` 的值,該參數須為核取方塊或選項 +@msg `step` is only for a parameter with a slider `step` 僅適用於帶滑桿的參數 +@msg a slider needs `min` below `max`, and an `int` slider a range within ±{EXACT_INT} 滑桿需要 `min` 小於 `max`,`int` 滑桿的範圍須在 ±{EXACT_INT} 以內 +@msg a slider is only for `number` and `int` parameters 滑桿僅適用於 `number` 和 `int` 參數 +@msg `step` must be a number above 0 and at most `max` minus `min` `step` 必須是大於 0 且不超過 `max` 減 `min` 的數 +@msg an `int` parameter's `step` must be a whole number `int` 參數的 `step` 必須是整數 @msg `visible` must be true or false `visible` 必須是 true 或 false @msg `{key}` must be a number from {_1} to {_2} `{key}` 必須是介於 {_1} 到 {_2} 之間的數字 @msg `{key}` must be an array of at most {MAX_ITEMS} entries `{key}` 必須是最多 {MAX_ITEMS} 項的陣列 diff --git a/crates/ui-egui/src/panels/appearance.rs b/crates/ui-egui/src/panels/appearance.rs index 52b36b4535..8976502aa4 100644 --- a/crates/ui-egui/src/panels/appearance.rs +++ b/crates/ui-egui/src/panels/appearance.rs @@ -1377,6 +1377,7 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: let t = Tokens::get(ui.ctx()); let params = editor_params(e); let mut change: Option<(String, Value)> = None; + let mut slid: Option<(String, Value, widgets::Live)> = None; let mut edit = false; let built_in = built_in_effect(&e.id); // A plug-in effect's parameters are labelled, measured and shown as its manifest says. @@ -1451,6 +1452,18 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: } return; } + // A plug-in's number that asks for a slider shows it before the number, as its + // dialog does; the number shows the value a drag in progress reached. + let dragged; + let v = match manifest.and_then(|m| m.param(key)).and_then(|p| Some((p, p.ui.slider_range(&p.spec)?))) { + Some((p, range)) => { + let (shown, edit) = param_slider_edit(ui, (item, k, key.as_str()), p, v, range); + slid = edit.map(|(value, phase)| (key.clone(), value, phase)).or(slid.take()); + dragged = shown; + &dragged + } + None => v, + }; match v { Value::Bool(b) => { if widgets::check_box(ui, &label, *b, true) { @@ -1461,11 +1474,13 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: let (x, id) = (n.as_f64().unwrap_or(0.0), ("fx", item, k, key.as_str())); let suffix = ui_keys.and_then(|u| u.unit.as_deref()).map(crate::dialogs::unit_suffix).unwrap_or_default(); let nx = if vectorcraft_effects::is_length(&e.id, key, relative) { - widgets::num_field(ui, id, Some(x), unit, 70.0) + widgets::num_field(ui, id, Some(x), unit, NUMBER_W) } else if let Some(range) = vectorcraft_effects::raster_px_range(&e.id, key) { - widgets::range_field_named(ui, id, None, x, range, &crate::dialogs::unit_suffix("px"), 2, 70.0) + widgets::range_field_named(ui, id, None, x, range, &crate::dialogs::unit_suffix("px"), 2, NUMBER_W) } else { - widgets::plain_field(ui, id, x, &suffix, 2, 70.0) + // A plug-in number with a slider shows the places its slider moves to. + let places = manifest.and_then(|m| m.param(key)).map_or(2, crate::dialogs::field_places); + widgets::plain_field(ui, id, x, &suffix, places, NUMBER_W) }; if let Some(nx) = nx { change = Some((key.clone(), json!(nx))); @@ -1496,11 +1511,71 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: if let Some((key, v)) = change { app.run("effect.setParams", aligned(app, json!({"item": item, "index": k, "params": {key: v}}))).ok(); } + if let Some((key, v, phase)) = slid { + let p = aligned(app, json!({"item": item, "index": k, "params": {key: v}})); + super::live_run(app, "Effect Options", "effect.setParams", p, phase); + } if edit { app.run("effect.dialog", aligned(app, json!({"effect": e.id, "index": k, "item": item}))).ok(); } } +/// Width of a number field in [`effect_editor`]. +const NUMBER_W: f32 = 70.0; + +/// The narrowest a plug-in parameter's slider gets in [`effect_editor`]. +const SLIDER_MIN_W: f32 = 24.0; + +/// What a drag on the slider of a plug-in effect's parameter in [`effect_editor`] keeps between +/// frames: the value it reached, and when it last previewed. +#[derive(Clone, Debug, Default)] +struct ParamSlide { + value: Option, + preview: crate::dialogs::SlidePreview, +} + +/// The slider of plug-in parameter `p` with value `v`, which asks for one, over `range`, in the row +/// `id` (appearance item, effect index and parameter name) → the value the row's number shows (a +/// drag's in progress, else `v`) and the edit to run with its phase ([`super::live_run`]): a click +/// or key as one undo step, and a drag previewed on the canvas about ten times a second +/// ([`crate::dialogs::SlidePreview`]) and kept as one undo step when it ends. +fn param_slider_edit( + ui: &mut Ui, + id: (Option, usize, &str), + p: &vectorcraft_plugins::Param, + v: &Value, + range: std::ops::RangeInclusive, +) -> (Value, Option<(Value, widgets::Live)>) { + let memory = egui::Id::unique(("fx-slide", id)); + let mut slide: ParamSlide = ui.data(|d| d.get_temp(memory)).unwrap_or_default(); + let cur = slide.value.clone().unwrap_or_else(|| v.clone()); + // The slider takes the room the row has left after the number field after it, so a narrow + // panel keeps both in view. + let room = ui.available_width() - NUMBER_W - 2.0 * ui.spacing().item_spacing.x; + let width = room.clamp(SLIDER_MIN_W, crate::dialogs::PARAM_SLIDER_WIDTH); + let (new, resp) = crate::dialogs::plugin_slider(ui, ("fx-slider", id), &p.spec, &cur, range, p.ui.step, width); + let edit = if resp.drag_stopped() { + // The value the drag ended on, kept even when its last preview waited. + new.or(std::mem::take(&mut slide).value).map(|value| (value, widgets::Live::Released)) + } else if resp.dragged() { + let changed = new.is_some(); + slide.value = new.or(slide.value.take()); + let due = slide.preview.due_now(ui, true, changed) == Some(true); + slide.value.clone().filter(|_| due).map(|value| (value, widgets::Live::Dragging)) + } else { + new.map(|value| (value, widgets::Live::Released)) + }; + let shown = slide.value.clone().unwrap_or(cur); + ui.data_mut(|d| { + if slide.value.is_some() { + d.insert_temp(memory, slide); + } else { + d.remove_temp::(memory); + } + }); + (shown, edit) +} + /// The values [`effect_editor`] lists: the effect's own values over its defaults, with earlier keys /// in their current form (Scribble's one `variation` as its Path Overlap and Spacing variations). fn editor_params(e: &Effect) -> serde_json::Map { diff --git a/crates/ui-egui/src/panels/appearance/tests.rs b/crates/ui-egui/src/panels/appearance/tests.rs index 4816d0838d..8efe31adfb 100644 --- a/crates/ui-egui/src/panels/appearance/tests.rs +++ b/crates/ui-egui/src/panels/appearance/tests.rs @@ -461,6 +461,98 @@ fn a_plug_in_effect_s_editor_follows_its_manifest() { app.run("plugin.remove", json!({"id": "test.ui.inlinekeys"})).unwrap(); } +/// A plug-in effect's number that asks for a slider shows one in the editor. A drag previews on +/// the canvas while it lasts, fewer times than it has frames, and ends as one undo step with the +/// value it reached; an arrow key then moves the value by one step as another undo step. +#[test] +fn a_plug_in_slider_in_the_editor_previews_a_drag_and_keeps_it_as_one_step() { + use egui::accesskit::Role; + use vectorcraft_plugins::wat as tpl; + let params = r#"{"amount":{"type":"number","min":0,"max":100,"default":10,"label":"Amount","widget":"slider"}, + "count":{"type":"int","min":0,"max":20,"default":4,"label":"Count","widget":"slider","step":2}, + "odd":{"type":"number","min":0,"max":100,"default":12,"label":"Odd","widget":"slider","step":5}}"#; + let src = tpl::module(&tpl::manifest("test.ui.inlineslider", "effect", params), tpl::ECHO, "", 1); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wat::parse_str(src).unwrap())})).unwrap(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let id = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("effect.apply", json!({"effect": "plugin.test.ui.inlineslider"})).unwrap(); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + set_pstate(&ctx, "ap-fx-open-None-0", true); + // Frames a sixtieth of a second apart, which a drag's previews are coarser than. + let mut time = 0.0; + let mut frame = |app: &mut VectorcraftApp, events: Vec| { + time += 1.0 / 60.0; + let screen = Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 700.0)); + let mut out = ctx.run_ui(egui::RawInput { events, time: Some(time), screen_rect: Some(screen), ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default() + }; + let params = |app: &VectorcraftApp| app.session.doc().unwrap().doc.node(NodeId(id)).unwrap().appearance.effects[0].params.clone(); + let (undo, applied) = (app.session.doc().unwrap().history.undo.len(), params(&app)); + frame(&mut app, vec![]); + let nodes = frame(&mut app, vec![]); + // Showing the sliders leaves the effect alone, its value off Odd's grid included. + assert_eq!((app.session.doc().unwrap().history.undo.len(), params(&app)), (undo, applied), "drawing the editor changed the effect"); + let sliders: Vec<_> = nodes.iter().filter(|(_, n)| n.role() == Role::Slider).map(|(_, n)| n.clone()).collect(); + assert_eq!(sliders.len(), 3, "every number that asks for one has a slider"); + // Each slider is named by its row's label. + let label_of = + |l: &egui::accesskit::NodeId| nodes.iter().find(|(nid, _)| nid == l).and_then(|(_, n)| n.label().or(n.value())).unwrap_or_default(); + for name in ["Amount", "Count", "Odd"] { + let named = sliders.iter().any(|n| n.labelled_by().iter().any(|l| label_of(l).starts_with(name))); + assert!(named, "no slider is named by {name}"); + } + // The number fields after the sliders stay inside the 320-point panel. + let fields: Vec<_> = nodes.iter().filter(|(_, n)| n.role() != Role::Slider && matches!(n.value(), Some("10" | "4" | "12"))).collect(); + assert!(fields.len() >= 3, "every number has a field"); + for (_, n) in fields { + let right = n.bounds().expect("the field is laid out").x1; + assert!(right <= 320.0, "the {:?} field ends at {right}, past the panel", n.value()); + } + let amount = sliders.iter().find(|n| n.numeric_value() == Some(10.0)).expect("Amount's slider shows its value"); + let rail = amount.bounds().expect("the slider is laid out"); + let at = |x: f64| egui::pos2((rail.x0 + x * (rail.x1 - rail.x0)) as f32, ((rail.y0 + rail.y1) / 2.0) as f32); + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + frame(&mut app, vec![egui::Event::PointerMoved(at(0.1))]); + frame(&mut app, vec![button(at(0.1), true)]); + // Thirty frames of dragging right, each to a new value. + let mut seen = vec![]; + for i in 1..=30 { + frame(&mut app, vec![egui::Event::PointerMoved(at(0.1 + 0.025 * i as f64))]); + let shown = params(&app)["amount"].clone(); + if seen.last() != Some(&shown) { + seen.push(shown); + } + } + assert!(seen.len() > 2 && seen.len() < 15, "the canvas showed {} values in 30 frames: {seen:?}", seen.len()); + frame(&mut app, vec![button(at(0.85), false)]); + frame(&mut app, vec![]); + let kept = params(&app)["amount"].as_f64().unwrap(); + assert!(kept > 70.0 && kept <= 100.0, "the value the drag ended on: {kept}"); + assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 1, "the drag is one undo step"); + assert!(!app.session.in_interaction(), "the drag's interaction ended"); + // Count's slider: focused, an arrow moves it by its step of 2, as one more undo step. + let nodes = frame(&mut app, vec![]); + let count = nodes.iter().find(|(_, n)| n.role() == Role::Slider && n.numeric_value() == Some(4.0)).map(|(nid, _)| *nid).unwrap(); + let focus = egui::accesskit::ActionRequest { + action: egui::accesskit::Action::Focus, + target_tree: egui::accesskit::TreeId::ROOT, + target_node: count, + data: None, + }; + frame(&mut app, vec![egui::Event::AccessKitActionRequest(focus)]); + frame(&mut app, vec![]); + let right = egui::Event::Key { key: egui::Key::ArrowRight, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() }; + frame(&mut app, vec![right]); + frame(&mut app, vec![]); + assert_eq!(params(&app)["count"], json!(6)); + assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 2); + app.run("plugin.remove", json!({"id": "test.ui.inlineslider"})).unwrap(); +} + /// Glass with a loaded texture lists Loaded Texture in its Texture menu, as its dialog does. #[test] fn the_effect_editor_lists_a_loaded_glass_texture() { diff --git a/docs/plugins.md b/docs/plugins.md index ab294db1ff..eabd0d9235 100644 --- a/docs/plugins.md +++ b/docs/plugins.md @@ -600,10 +600,18 @@ declares them still installs there: | `help` | Shows what the parameter does when the pointer rests on its label (1–1,000 characters; line breaks allowed). | | `helpUrl` | Opens this `https://` page (at most 512 bytes) from a button after the field. | | `visibleWhen` | `{"pattern": ["lines", "crosshatch"], "outline": [true]}` shows the parameter only while each parameter it names (a checkbox or a choice declared before it) has one of the values listed and is shown itself. | +| `widget` | `"slider"` shows a slider over `min..max` before the number field of a `number` or `int` parameter. Its range needs `min` below `max`, and an `int`'s range lies within ±9,007,199,254,740,992. On any other parameter, or with another value, the manifest is refused at install. | +| `step` | How far the slider moves the value at a time, counted from `min`: a number above 0 and at most `max` minus `min`, and a whole number for an `int`. Without it, a slider moves a `number` to two decimal places (more when `max` minus `min` is under 1) and an `int` by 1. The number field shows as many decimal places as the slider moves to, from 2 to 6. A value off the slider's steps, typed in the field or set by a script, is kept until the slider is moved. `step` without `"widget": "slider"` is refused. | A hidden parameter still goes to the plug-in with its value: what the dialog showed never changes a run. The filter, live-effect and exporter dialogs use all of these keys. The Appearance panel's editor of a plug-in effect's -parameters uses `label`, `unit`, `help` and `visibleWhen`, and lists the parameters without sections or help buttons. +parameters uses `label`, `unit`, `help`, `visibleWhen`, `widget` and `step`, and lists the parameters without +sections or help buttons. + +The arrow keys move a slider by its `step`, or by 1 for an `int` without one, and screen readers read it as a slider +named by the parameter's label. While a slider is dragged, the preview of a filter or live effect runs the plug-in +at most about ten times a second, on the latest value, and the value the drag ends on always previews. In the +Appearance panel, a drag is one undo step. ### Input diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index 3da663c191..1c313ba64f 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -2647,6 +2647,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - **Importer plug-ins (G17):** a WebAssembly plug-in of kind `importer` adds a read-only file format, as [the help page](https://ai-sdk-2020.84.nz/html/struct_a_i_file_format_suite) describes for file format plug-ins that read: File › Open lists its files under "All readable files" and its own filter, and File › Open With lists each importer by name. `document.open` uses it for a file whose extension no built-in format reads, by content or extension (the importer whose id sorts first, when several list the extension), or the one `importer` names, also for an extension a built-in format reads; a damaged file of a built-in format reports that format's error. The plug-in is given at most 128 MiB of the file and `_context` (`mode: "import"`, `extension`, `name`), and returns paths and compound paths in the filters' object JSON, checked as a filter's output is; they become a new document whose artboard is their bounds, which Save asks a name for. A decline, invalid output, a trap or Cancel opens nothing. The routing rule, the limit and Open With are VectorCraft's own. Regressions: `crates/engine/tests/plugin_import.rs`, `crates/plugins/src/import.rs`, `crates/ui-egui/src/dialogs/tests_plugin_import.rs`. Scores and hours unchanged. - **Plug-in parameters as their manifest presents them (G17):** each parameter may have a `label`, a `unit` shown after its value, `help` on its label and a `helpUrl` page opened from a button, a `group` (sections that fold, after the parameters outside any group) and a `visibleWhen` that shows it only while the checkboxes and choices it names have one of the listed values (a hidden parameter still goes to the plug-in). `string` and `numberList` parameters join number, int, bool and choice, and a plug-in declares up to 256 parameters, at most 64 outside groups. The filter, live-effect and exporter dialogs use these keys, and the Appearance panel's effect editor the labels, units, help and conditions; hosts from before them ignore them. Regressions: `crates/plugins/src/dialog.rs`, `crates/plugins/src/manifest.rs`, `crates/ui-egui/src/dialogs/tests_plugin_fields.rs`, `crates/ui-egui/src/panels/appearance.rs`. Scores and hours unchanged. +- **Plug-in number parameters as sliders (G17):** a `number` or `int` parameter with `"widget": "slider"` shows a slider over its range before its number field, in the filter, live-effect and exporter dialogs and in the Appearance panel's effect editor, moving by an optional `step` counted from `min`; the manifest is refused at install when the parameter cannot have one. A drag previews the plug-in about ten times a second and ends on its last value, as one undo step in the Appearance panel. Regressions: `crates/plugins/src/dialog.rs`, `crates/ui-egui/src/dialogs/tests_plugin_fields.rs`, `crates/ui-egui/src/panels/appearance/tests.rs`. Scores and hours unchanged. - **Live-effect plug-ins read their object's paints (G17):** a live effect is given the object's `fills` and `strokes` as a filter gets them, read only, and `_context.item` (`"object"`, or the fill or stroke whose own effects hold it); the result is cached by paint too, so a change of paint runs it again. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/plugins/src/effect.rs`. Scores and hours unchanged. - **Live-effect plug-ins before a fill's or stroke's own 3D effect:** a live effect listed before a fill's or stroke's own Extrude & Bevel, Inflate or Rotate effect is given `_context.item` for that fill or stroke (`{"fill": i}` or `{"stroke": i}`), not `"object"`, in the drawn art, in the 3D meshes and in Expand as Wireframes; a deferred stage there is listed at that fill's or stroke's place. Regressions: `crates/effects/src/tests/solidcontext.rs`. Scores and hours unchanged. - **Filter plug-ins set effects and stroke styles (G17):** a filter is given each object's effect records and its strokes' `join`, `cap` and `miterLimit`, and may return them; the records are admitted as `effect.apply` admits them (a known effect or installed live-effect plug-in, parameters it takes, one 3D effect that fits, no texture read from a file), and one refused refuses the output. Regressions: `crates/engine/src/tests/plugins.rs`, `crates/plugins/src/objects/tests.rs`. Scores and hours unchanged. From 6280006e801d01b8b87e2347423b8a70ed3bb11f Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 01:57:38 -0800 Subject: [PATCH 2/3] Plug-ins: a slider drag in the Appearance panel stays with its objects The Appearance panel kept a plug-in slider's drag value under the row's appearance item, effect index and parameter name only. When the selection changed while the button was down and the drag ended off the editor, the value stayed behind: the next object with the same effect, or the same object selected again, showed it in place of its own. The drag's interaction also stayed open, since the slider never saw its release. The kept value now carries the document and selection it was made for and the UI pass that last drew its row, and it is dropped when either changes or a pass does not draw the row. A drag that a pass did not draw (its row or the panel closed), or that ended with no value to keep, keeps what it previewed as one undo step and ends its interaction. The app checks this at the end of every pass, after the panels, as it does for the 3D panel's drags. Any other interaction is left open. The inline slider test now ends its drag on a value the canvas had not previewed yet, and checks that the drag keeps that exact value. --- crates/ui-egui/src/app.rs | 1 + crates/ui-egui/src/panels/appearance.rs | 89 ++++++++++++-- crates/ui-egui/src/panels/appearance/tests.rs | 112 +++++++++++++++++- 3 files changed, 191 insertions(+), 11 deletions(-) diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index bba6a5d83d..7e7a3f9328 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -654,6 +654,7 @@ impl VectorcraftApp { crate::toasts::show(self, &ctx); // After every panel had its chance to draw in this pass. crate::panels::three_d::end_stale_drag(self, &ctx); + crate::panels::appearance::end_stale_slide(self, &ctx); if self.custom_titlebar { titlebar::resize_zones(ui); } diff --git a/crates/ui-egui/src/panels/appearance.rs b/crates/ui-egui/src/panels/appearance.rs index 8976502aa4..5287aa0f4d 100644 --- a/crates/ui-egui/src/panels/appearance.rs +++ b/crates/ui-egui/src/panels/appearance.rs @@ -16,7 +16,7 @@ //! fills/strokes for Duplicate and Delete. Delete on a selected Opacity row sets it back to //! Default (100%, Normal). -use std::sync::{Arc, OnceLock}; +use std::sync::{Arc, OnceLock, Weak}; use egui::{Rect, Sense, Stroke, StrokeKind, Ui, pos2, vec2}; use serde_json::{Value, json}; @@ -555,6 +555,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) { // An empty spacer row at the end of the list. ui.allocate_exact_size(vec2(ui.available_width(), 10.0), Sense::hover()); }); + end_stale_slide(app, ui.ctx()); bottom(app, ui, node.as_deref(), sel); delete_key(app, ui); // A row's popup, beside the panel (in the same window when the panel floats). @@ -1378,6 +1379,8 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: let params = editor_params(e); let mut change: Option<(String, Value)> = None; let mut slid: Option<(String, Value, widgets::Live)> = None; + // The objects a slider drag edits: the editor shows a drag's value for these alone. + let target = app.session.active().map(|d| (d.uid, d.selection.subjects().to_vec())); let mut edit = false; let built_in = built_in_effect(&e.id); // A plug-in effect's parameters are labelled, measured and shown as its manifest says. @@ -1457,7 +1460,7 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: let dragged; let v = match manifest.and_then(|m| m.param(key)).and_then(|p| Some((p, p.ui.slider_range(&p.spec)?))) { Some((p, range)) => { - let (shown, edit) = param_slider_edit(ui, (item, k, key.as_str()), p, v, range); + let (shown, edit) = param_slider_edit(ui, (item, k, key.as_str()), &target, p, v, range); slid = edit.map(|(value, phase)| (key.clone(), value, phase)).or(slid.take()); dragged = shown; &dragged @@ -1513,7 +1516,9 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: } if let Some((key, v, phase)) = slid { let p = aligned(app, json!({"item": item, "index": k, "params": {key: v}})); - super::live_run(app, "Effect Options", "effect.setParams", p, phase); + super::live_run(app, SLIDE_LABEL, "effect.setParams", p, phase); + let owner = if phase == widgets::Live::Dragging { slide_interaction(app) } else { None }; + set_pstate(ui.ctx(), SLIDE_OWNER, owner); } if edit { app.run("effect.dialog", aligned(app, json!({"effect": e.id, "index": k, "item": item}))).ok(); @@ -1526,28 +1531,91 @@ const NUMBER_W: f32 = 70.0; /// The narrowest a plug-in parameter's slider gets in [`effect_editor`]. const SLIDER_MIN_W: f32 = 24.0; +/// The UI pass that last drew a drag on a plug-in parameter's slider in [`effect_editor`] that has +/// not ended with a value to keep ([`end_stale_slide`]). +const SLIDE_LIVE: &str = "ap-fx-slide-live"; + +/// The interaction that a drag on a plug-in parameter's slider in [`effect_editor`] previews in +/// ([`slide_interaction`]). +const SLIDE_OWNER: &str = "ap-fx-slide-owner"; + +/// The undo step a drag on a plug-in parameter's slider in [`effect_editor`] is kept as. +const SLIDE_LABEL: &str = "Effect Options"; + +/// An interaction: its document's uid and the selection snapshot it previews from, which each +/// interaction makes anew when it begins and keeps while it lasts. +type SlideOwner = (u64, Weak); + +/// The interaction open in the active document, when it is one a plug-in parameter's slider starts. +fn slide_interaction(app: &VectorcraftApp) -> Option { + let d = app.session.active()?; + d.interaction.as_ref().filter(|it| it.label == SLIDE_LABEL).map(|it| (d.uid, Arc::downgrade(&it.selection))) +} + +/// A drag on a plug-in parameter's slider that this pass did not draw (its row closed, the +/// selection changed so the row is gone, or the panel closed), or that ended with no value to +/// keep, reports no release: the preview it made in its own interaction is kept as one undo step +/// and the interaction ends. Any other interaction is left alone. The panel runs this after its +/// rows, and the app at the end of every pass, after the panels. +pub(crate) fn end_stale_slide(app: &mut VectorcraftApp, ctx: &egui::Context) { + if pstate::>(ctx, SLIDE_LIVE).is_some_and(|pass| pass != root_pass(ctx)) { + let owner = pstate::>(ctx, SLIDE_OWNER); + let ours = match (owner, slide_interaction(app)) { + (Some((uid, snapshot)), Some((open, now))) => uid == open && snapshot.ptr_eq(&now), + _ => false, + }; + if ours { + if let Err(e) = app.session.commit_interaction() { + app.status(e.to_string()); + } + app.sync_views(); + } + set_pstate(ctx, SLIDE_LIVE, None::); + set_pstate(ctx, SLIDE_OWNER, None::); + } +} + +/// The main window's pass in progress. A floating window draws inside it and counts its own +/// passes, so the slider's marks use this one wherever the panel draws. +fn root_pass(ctx: &egui::Context) -> u64 { + ctx.cumulative_pass_nr_for(egui::ViewportId::ROOT) +} + /// What a drag on the slider of a plug-in effect's parameter in [`effect_editor`] keeps between -/// frames: the value it reached, and when it last previewed. +/// frames: the value it reached, and when it last previewed, for the objects (document and +/// selection) it edits, as of the UI pass that last drew it. #[derive(Clone, Debug, Default)] struct ParamSlide { value: Option, preview: crate::dialogs::SlidePreview, + target: Option<(u64, Vec)>, + pass: u64, } /// The slider of plug-in parameter `p` with value `v`, which asks for one, over `range`, in the row -/// `id` (appearance item, effect index and parameter name) → the value the row's number shows (a -/// drag's in progress, else `v`) and the edit to run with its phase ([`super::live_run`]): a click -/// or key as one undo step, and a drag previewed on the canvas about ten times a second -/// ([`crate::dialogs::SlidePreview`]) and kept as one undo step when it ends. +/// `id` (appearance item, effect index and parameter name) of the objects `target` (document and +/// selection) → the value the row's number shows (a drag's in progress, else `v`) and the edit to +/// run with its phase ([`super::live_run`]): a click or key as one undo step, and a drag previewed +/// on the canvas about ten times a second ([`crate::dialogs::SlidePreview`]) and kept as one undo +/// step when it ends. A drag's value is dropped when the selection or the document changes, or +/// after a pass that did not draw the row, so it never shows on or goes to other objects; a drag in +/// progress is noted under [`SLIDE_LIVE`] until it ends with a value to keep. fn param_slider_edit( ui: &mut Ui, id: (Option, usize, &str), + target: &Option<(u64, Vec)>, p: &vectorcraft_plugins::Param, v: &Value, range: std::ops::RangeInclusive, ) -> (Value, Option<(Value, widgets::Live)>) { let memory = egui::Id::unique(("fx-slide", id)); + let pass = root_pass(ui.ctx()); let mut slide: ParamSlide = ui.data(|d| d.get_temp(memory)).unwrap_or_default(); + if slide.target != *target || slide.pass.saturating_add(1) < pass { + slide = ParamSlide::default(); + } + slide.target.clone_from(target); + slide.pass = pass; let cur = slide.value.clone().unwrap_or_else(|| v.clone()); // The slider takes the room the row has left after the number field after it, so a narrow // panel keeps both in view. @@ -1565,6 +1633,11 @@ fn param_slider_edit( } else { new.map(|value| (value, widgets::Live::Released)) }; + if matches!(edit, Some((_, widgets::Live::Released))) { + set_pstate(ui.ctx(), SLIDE_LIVE, None::); + } else if resp.dragged() { + set_pstate(ui.ctx(), SLIDE_LIVE, Some(pass)); + } let shown = slide.value.clone().unwrap_or(cur); ui.data_mut(|d| { if slide.value.is_some() { diff --git a/crates/ui-egui/src/panels/appearance/tests.rs b/crates/ui-egui/src/panels/appearance/tests.rs index 8efe31adfb..28945cf076 100644 --- a/crates/ui-egui/src/panels/appearance/tests.rs +++ b/crates/ui-egui/src/panels/appearance/tests.rs @@ -528,10 +528,18 @@ fn a_plug_in_slider_in_the_editor_previews_a_drag_and_keeps_it_as_one_step() { } } assert!(seen.len() > 2 && seen.len() < 15, "the canvas showed {} values in 30 frames: {seen:?}", seen.len()); - frame(&mut app, vec![button(at(0.85), false)]); + // One more move, too soon after the last preview to preview, then the release: the drag keeps + // the value it ended on, which the canvas had not shown yet. + let nodes = frame(&mut app, vec![egui::Event::PointerMoved(at(0.95))]); + let ended = nodes + .iter() + .find(|(_, n)| n.role() == Role::Slider && n.labelled_by().iter().any(|l| label_of(l).starts_with("Amount"))) + .and_then(|(_, n)| n.numeric_value()) + .expect("Amount's slider shows the value the drag reached"); + assert_ne!(params(&app)["amount"].as_f64(), Some(ended), "the last move previewed at once"); + frame(&mut app, vec![button(at(0.95), false)]); frame(&mut app, vec![]); - let kept = params(&app)["amount"].as_f64().unwrap(); - assert!(kept > 70.0 && kept <= 100.0, "the value the drag ended on: {kept}"); + assert_eq!(params(&app)["amount"].as_f64(), Some(ended), "the value the drag ended on"); assert_eq!(app.session.doc().unwrap().history.undo.len(), undo + 1, "the drag is one undo step"); assert!(!app.session.in_interaction(), "the drag's interaction ended"); // Count's slider: focused, an arrow moves it by its step of 2, as one more undo step. @@ -553,6 +561,104 @@ fn a_plug_in_slider_in_the_editor_previews_a_drag_and_keeps_it_as_one_step() { app.run("plugin.remove", json!({"id": "test.ui.inlineslider"})).unwrap(); } +/// A drag on a plug-in slider whose end the editor did not see, because the selection changed +/// while the button was down, keeps what it previewed as its undo step, ends its interaction and +/// leaves no value behind: the editor then shows each object's own value, for another object with +/// the same effect and for the object the drag started on. +#[test] +fn a_plug_in_slider_drag_s_value_stays_with_its_drag() { + use egui::accesskit::Role; + use vectorcraft_plugins::wat as tpl; + let params = r#"{"amount":{"type":"number","min":0,"max":100,"default":10,"label":"Amount","widget":"slider"}}"#; + let src = tpl::module(&tpl::manifest("test.ui.slideselection", "effect", params), tpl::ECHO, "", 1); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wat::parse_str(src).unwrap())})).unwrap(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let add = |app: &mut VectorcraftApp, x: f64| { + let id = app.run("shape.rectangle", json!({"x": x, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("effect.apply", json!({"effect": "plugin.test.ui.slideselection"})).unwrap(); + id + }; + let (a, b) = (add(&mut app, 0.0), add(&mut app, 40.0)); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + set_pstate(&ctx, "ap-fx-open-None-0", true); + let mut time = 0.0; + let mut frame = |app: &mut VectorcraftApp, events: Vec| { + time += 1.0 / 60.0; + let screen = Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 700.0)); + let mut out = ctx.run_ui(egui::RawInput { events, time: Some(time), screen_rect: Some(screen), ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default() + }; + let amount = + |app: &VectorcraftApp, id: u64| app.session.doc().unwrap().doc.node(NodeId(id)).unwrap().appearance.effects[0].params["amount"].as_f64(); + let slider = |nodes: &[(egui::accesskit::NodeId, egui::accesskit::Node)]| { + nodes.iter().find(|(_, n)| n.role() == Role::Slider).and_then(|(_, n)| Some((n.numeric_value()?, n.bounds()?))) + }; + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + for (back, name) in [(a, "the object the drag started on"), (b, "another object")] { + app.run("select.set", json!({"ids": [a]})).unwrap(); + frame(&mut app, vec![]); + let (_, rail) = slider(&frame(&mut app, vec![])).expect("the slider shows"); + let at = |x: f64| egui::pos2((rail.x0 + x * (rail.x1 - rail.x0)) as f32, ((rail.y0 + rail.y1) / 2.0) as f32); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + // The first move previews at once; the next comes too soon and waits. + frame(&mut app, vec![egui::Event::PointerMoved(at(0.4))]); + let (reached, _) = slider(&frame(&mut app, vec![egui::Event::PointerMoved(at(0.7))])).expect("the slider shows"); + let previewed = amount(&app, a); + assert_ne!(previewed, Some(reached), "the second move previewed at once"); + assert!(app.session.in_interaction(), "the drag previews"); + // With the button still down, nothing is selected, and the button comes up off the editor: + // the drag keeps what it previewed, and its interaction ends. + app.run("select.set", json!({"ids": []})).unwrap(); + frame(&mut app, vec![]); + frame(&mut app, vec![button(at(0.7), false)]); + assert!(!app.session.in_interaction(), "{name}: the drag's interaction is still open"); + assert_eq!(amount(&app, a), previewed, "{name}: the drag did not keep its preview"); + app.run("select.set", json!({"ids": [back]})).unwrap(); + frame(&mut app, vec![]); + let (shown, _) = slider(&frame(&mut app, vec![])).expect("the slider shows"); + assert_eq!(Some(shown), amount(&app, back), "{name} shows the drag's value"); + } + // A drag whose interaction another one replaced, of the same name on the same document, leaves + // that one open when its row goes. + app.run("select.set", json!({"ids": [a]})).unwrap(); + frame(&mut app, vec![]); + let (_, rail) = slider(&frame(&mut app, vec![])).expect("the slider shows"); + let at = |x: f64| egui::pos2((rail.x0 + x * (rail.x1 - rail.x0)) as f32, ((rail.y0 + rail.y1) / 2.0) as f32); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.5))]); + assert!(app.session.in_interaction(), "the drag previews"); + app.session.cancel_interaction().unwrap(); + app.session.begin_interaction("Effect Options").unwrap(); + app.run("select.set", json!({"ids": []})).unwrap(); + frame(&mut app, vec![]); + frame(&mut app, vec![button(at(0.5), false)]); + assert!(app.session.in_interaction(), "the other interaction was ended"); + app.session.cancel_interaction().unwrap(); + // A drag whose panel closes keeps what it previewed at the end of the first pass that does not + // draw the panel, as the app checks after its panels. + app.run("select.set", json!({"ids": [a]})).unwrap(); + frame(&mut app, vec![]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.6))]); + let previewed = amount(&app, a); + assert!(app.session.in_interaction(), "the drag previews"); + for events in [vec![], vec![button(at(0.6), false)]] { + time += 1.0 / 60.0; + let input = egui::RawInput { events, time: Some(time), ..Default::default() }; + let _ = ctx.run_ui(input, |ui| crate::panels::appearance::end_stale_slide(&mut app, ui.ctx())); + assert!(!app.session.in_interaction(), "the drag's interaction is still open after the panel closed"); + } + assert_eq!(amount(&app, a), previewed, "the drag did not keep its preview"); + app.run("plugin.remove", json!({"id": "test.ui.slideselection"})).unwrap(); +} + /// Glass with a loaded texture lists Loaded Texture in its Texture menu, as its dialog does. #[test] fn the_effect_editor_lists_a_loaded_glass_texture() { From cbfc785886e29bbd91e9ebdaee2626a8e492f7ec Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sun, 22 Nov 2026 05:49:55 -0800 Subject: [PATCH 3/3] Plug-ins: a slider drag previews only in its own interaction - A drag on a plug-in parameter's slider in the Appearance panel notes the interaction it begins and previews and keeps values only in that one. An interaction that was open before the drag, or that replaced the drag's own while its row stays in view, is left as it is. - The slider is a widget of its own for each document and selection, so a release in the same pass as a change of selection does not reach the objects selected now. The objects the drag began on keep its last preview as one undo step. - A switch to another document during the drag keeps what it previewed as one undo step in the document it began in, instead of canceling it (Session::keep_interaction_on_switch). --- crates/engine/src/interaction.rs | 3 + crates/engine/src/session/documents.rs | 6 +- crates/engine/src/session/edit.rs | 10 ++ crates/ui-egui/src/panels/appearance.rs | 84 +++++++++- crates/ui-egui/src/panels/appearance/tests.rs | 156 ++++++++++++++++++ 5 files changed, 248 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/interaction.rs b/crates/engine/src/interaction.rs index 06cc86859e..d6b572535c 100644 --- a/crates/engine/src/interaction.rs +++ b/crates/engine/src/interaction.rs @@ -33,6 +33,9 @@ pub struct Interaction { /// The bounding box of `selection` in `doc`, measured once for a move drag /// ([`crate::Session::move_drag_box`]): each step offsets it by the drag's move. pub(crate) move_box: std::sync::OnceLock>, + /// A switch to another document keeps the preview as one undo step instead of canceling it + /// ([`crate::Session::keep_interaction_on_switch`]). + pub(crate) keep_on_switch: bool, } /// What Object → Transform → Transform Again (⌘D) repeats ([`SessionState::last_transform`]). diff --git a/crates/engine/src/session/documents.rs b/crates/engine/src/session/documents.rs index 1685adc40f..804ef2f494 100644 --- a/crates/engine/src/session/documents.rs +++ b/crates/engine/src/session/documents.rs @@ -218,9 +218,11 @@ impl Session { let _ = self.give_back_tool(view); let _ = self.deactivate_tool(view); // A batch leaves its interaction open in the document it leaves, to keep or roll back with - // the rest of the batch; anything else in progress (a drag) is cancelled. + // the rest of the batch; anything else in progress (a drag) is cancelled, except a drag on a + // panel's slider, which keeps its preview as one undo step there. if self.batch_stash.is_none() { - let _ = self.cancel_interaction(); + let keep = self.active().and_then(|d| d.interaction.as_ref()).is_some_and(|it| it.keep_on_switch); + let _ = if keep { self.commit_interaction() } else { self.cancel_interaction() }; } self.keep_tool_settings(); self.tool = self.make_tool(self.tool.id()); diff --git a/crates/engine/src/session/edit.rs b/crates/engine/src/session/edit.rs index e2ba1715b9..95827f0ff6 100644 --- a/crates/engine/src/session/edit.rs +++ b/crates/engine/src/session/edit.rs @@ -312,6 +312,7 @@ impl Session { plane_placed: false, copies: None, move_box: std::sync::OnceLock::new(), + keep_on_switch: false, }); Ok(()) } @@ -508,6 +509,15 @@ impl Session { Ok(()) } + /// Keep the open interaction's preview as one undo step, instead of canceling it, when another + /// document becomes active: a drag on a panel's slider, which keeps what it previewed when it + /// ends without a release. + pub fn keep_interaction_on_switch(&mut self) { + if let Some(it) = self.active_mut().and_then(|d| d.interaction.as_mut()) { + it.keep_on_switch = true; + } + } + pub fn in_interaction(&self) -> bool { self.active().is_some_and(|d| d.interaction.is_some()) } diff --git a/crates/ui-egui/src/panels/appearance.rs b/crates/ui-egui/src/panels/appearance.rs index 5287aa0f4d..af504e8dac 100644 --- a/crates/ui-egui/src/panels/appearance.rs +++ b/crates/ui-egui/src/panels/appearance.rs @@ -1516,9 +1516,36 @@ fn effect_editor(app: &mut VectorcraftApp, ui: &mut Ui, item: Option, k: } if let Some((key, v, phase)) = slid { let p = aligned(app, json!({"item": item, "index": k, "params": {key: v}})); - super::live_run(app, SLIDE_LABEL, "effect.setParams", p, phase); - let owner = if phase == widgets::Live::Dragging { slide_interaction(app) } else { None }; - set_pstate(ui.ctx(), SLIDE_OWNER, owner); + let hold = match pstate::(ui.ctx(), SLIDE_OWNER) { + // A drag that previewed goes on only in the interaction it began. + SlideHold::Live(owner) => { + if slide_interaction(app).is_some_and(|now| same_slide(&owner, &now)) { + SlideHold::Live(owner) + } else { + SlideHold::Lost + } + } + SlideHold::Lost => SlideHold::Lost, + SlideHold::Idle => begin_slide(app), + }; + match hold { + SlideHold::Live(owner) => { + super::live_run(app, SLIDE_LABEL, "effect.setParams", p, phase); + let next = if phase == widgets::Live::Dragging { SlideHold::Live(owner) } else { SlideHold::Idle }; + set_pstate(ui.ctx(), SLIDE_OWNER, next); + } + // The slider's own interaction could not begin: a click or a key still runs its edit. + SlideHold::Idle => { + if phase == widgets::Live::Released { + app.run("effect.setParams", p).ok(); + } + } + // Another interaction is open, or replaced the drag's own: the drag leaves it alone. + SlideHold::Lost => { + let next = if phase == widgets::Live::Dragging { SlideHold::Lost } else { SlideHold::Idle }; + set_pstate(ui.ctx(), SLIDE_OWNER, next); + } + } } if edit { app.run("effect.dialog", aligned(app, json!({"effect": e.id, "index": k, "item": item}))).ok(); @@ -1536,9 +1563,22 @@ const SLIDER_MIN_W: f32 = 24.0; const SLIDE_LIVE: &str = "ap-fx-slide-live"; /// The interaction that a drag on a plug-in parameter's slider in [`effect_editor`] previews in -/// ([`slide_interaction`]). +/// ([`SlideHold`]). const SLIDE_OWNER: &str = "ap-fx-slide-owner"; +/// Where a drag on a plug-in parameter's slider in [`effect_editor`] previews. +#[derive(Clone, Debug, Default)] +enum SlideHold { + /// No drag has previewed yet. + #[default] + Idle, + /// The drag previews in the interaction it began ([`slide_interaction`]). + Live(SlideOwner), + /// Another interaction was open when the drag began, or replaced the one it began: the drag + /// previews nothing and keeps nothing until it ends. + Lost, +} + /// The undo step a drag on a plug-in parameter's slider in [`effect_editor`] is kept as. const SLIDE_LABEL: &str = "Effect Options"; @@ -1552,6 +1592,30 @@ fn slide_interaction(app: &VectorcraftApp) -> Option { d.interaction.as_ref().filter(|it| it.label == SLIDE_LABEL).map(|it| (d.uid, Arc::downgrade(&it.selection))) } +/// Whether two [`SlideOwner`]s are the same interaction. +fn same_slide(a: &SlideOwner, b: &SlideOwner) -> bool { + a.0 == b.0 && a.1.ptr_eq(&b.1) +} + +/// Begin the interaction a drag on a plug-in parameter's slider previews in → [`SlideHold::Live`] +/// with it; [`SlideHold::Lost`] when another interaction is open, which beginning leaves as it is; +/// [`SlideHold::Idle`] when it could not begin (a script runs). A switch to another document during +/// the drag keeps what it previewed as one undo step in the document it began in. +fn begin_slide(app: &mut VectorcraftApp) -> SlideHold { + let open: Option = app.session.active().and_then(|d| d.interaction.as_ref().map(|it| (d.uid, Arc::downgrade(&it.selection)))); + if app.begin_interaction(SLIDE_LABEL).is_err() { + return SlideHold::Idle; + } + match slide_interaction(app) { + // One that was open before the drag, of the same name, is not the drag's own. + Some(now) if !open.is_some_and(|o| same_slide(&o, &now)) => { + app.session.keep_interaction_on_switch(); + SlideHold::Live(now) + } + _ => SlideHold::Lost, + } +} + /// A drag on a plug-in parameter's slider that this pass did not draw (its row closed, the /// selection changed so the row is gone, or the panel closed), or that ended with no value to /// keep, reports no release: the preview it made in its own interaction is kept as one undo step @@ -1559,9 +1623,8 @@ fn slide_interaction(app: &VectorcraftApp) -> Option { /// rows, and the app at the end of every pass, after the panels. pub(crate) fn end_stale_slide(app: &mut VectorcraftApp, ctx: &egui::Context) { if pstate::>(ctx, SLIDE_LIVE).is_some_and(|pass| pass != root_pass(ctx)) { - let owner = pstate::>(ctx, SLIDE_OWNER); - let ours = match (owner, slide_interaction(app)) { - (Some((uid, snapshot)), Some((open, now))) => uid == open && snapshot.ptr_eq(&now), + let ours = match (pstate::(ctx, SLIDE_OWNER), slide_interaction(app)) { + (SlideHold::Live(owner), Some(now)) => same_slide(&owner, &now), _ => false, }; if ours { @@ -1571,7 +1634,7 @@ pub(crate) fn end_stale_slide(app: &mut VectorcraftApp, ctx: &egui::Context) { app.sync_views(); } set_pstate(ctx, SLIDE_LIVE, None::); - set_pstate(ctx, SLIDE_OWNER, None::); + set_pstate(ctx, SLIDE_OWNER, SlideHold::Idle); } } @@ -1621,7 +1684,10 @@ fn param_slider_edit( // panel keeps both in view. let room = ui.available_width() - NUMBER_W - 2.0 * ui.spacing().item_spacing.x; let width = room.clamp(SLIDER_MIN_W, crate::dialogs::PARAM_SLIDER_WIDTH); - let (new, resp) = crate::dialogs::plugin_slider(ui, ("fx-slider", id), &p.spec, &cur, range, p.ui.step, width); + // The slider is a widget of its own for each document and selection, so a drag on it ends when + // they change and sends no more values: the objects the drag began on keep what it previewed + // ([`end_stale_slide`]), and the others stay as they are. + let (new, resp) = crate::dialogs::plugin_slider(ui, ("fx-slider", id, target), &p.spec, &cur, range, p.ui.step, width); let edit = if resp.drag_stopped() { // The value the drag ended on, kept even when its last preview waited. new.or(std::mem::take(&mut slide).value).map(|value| (value, widgets::Live::Released)) diff --git a/crates/ui-egui/src/panels/appearance/tests.rs b/crates/ui-egui/src/panels/appearance/tests.rs index 28945cf076..df827eba40 100644 --- a/crates/ui-egui/src/panels/appearance/tests.rs +++ b/crates/ui-egui/src/panels/appearance/tests.rs @@ -659,6 +659,162 @@ fn a_plug_in_slider_drag_s_value_stays_with_its_drag() { app.run("plugin.remove", json!({"id": "test.ui.slideselection"})).unwrap(); } +/// A drag on a plug-in slider ends when another object with the same effect is selected while the +/// button is down: the object the drag began on keeps what the drag previewed, as one undo step, and +/// the other object stays selected and unchanged, also when the button comes up in the same pass. +/// A drag also leaves alone an interaction that it did not begin: one that replaced its own while +/// its row stays in view, and one that was open before it began. +#[test] +fn a_plug_in_slider_drag_ends_on_another_object_and_leaves_other_interactions_alone() { + use egui::accesskit::Role; + use vectorcraft_plugins::wat as tpl; + let params = r#"{"amount":{"type":"number","min":0,"max":100,"default":10,"label":"Amount","widget":"slider"}}"#; + let src = tpl::module(&tpl::manifest("test.ui.slideswitch", "effect", params), tpl::ECHO, "", 1); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wat::parse_str(src).unwrap())})).unwrap(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + let add = |app: &mut VectorcraftApp, x: f64| { + let id = app.run("shape.rectangle", json!({"x": x, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("effect.apply", json!({"effect": "plugin.test.ui.slideswitch"})).unwrap(); + id + }; + let (a, b) = (add(&mut app, 0.0), add(&mut app, 40.0)); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + set_pstate(&ctx, "ap-fx-open-None-0", true); + let mut time = 0.0; + let mut frame = |app: &mut VectorcraftApp, events: Vec| { + time += 1.0 / 60.0; + let screen = Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 700.0)); + let mut out = ctx.run_ui(egui::RawInput { events, time: Some(time), screen_rect: Some(screen), ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default() + }; + let amount = + |app: &VectorcraftApp, id: u64| app.session.doc().unwrap().doc.node(NodeId(id)).unwrap().appearance.effects[0].params["amount"].as_f64(); + let slider = |nodes: &[(egui::accesskit::NodeId, egui::accesskit::Node)]| { + nodes.iter().find(|(_, n)| n.role() == Role::Slider).and_then(|(_, n)| n.bounds()) + }; + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + let undo = |app: &VectorcraftApp| app.session.doc().unwrap().history.undo.len(); + let open_preview = |app: &VectorcraftApp| app.session.doc().unwrap().interaction.as_ref().map(|it| it.preview.is_some()); + app.run("select.set", json!({"ids": [a]})).unwrap(); + frame(&mut app, vec![]); + let rail = slider(&frame(&mut app, vec![])).expect("the slider shows"); + let at = |x: f64| egui::pos2((rail.x0 + x * (rail.x1 - rail.x0)) as f32, ((rail.y0 + rail.y1) / 2.0) as f32); + // B is selected while the button is down, and the button comes up in the next pass. + let steps = undo(&app); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.4))]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.7))]); + let previewed = amount(&app, a); + assert_ne!(previewed, Some(10.0), "the drag previews"); + app.run("select.set", json!({"ids": [b]})).unwrap(); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.9)), button(at(0.9), false)]); + frame(&mut app, vec![]); + assert!(!app.session.in_interaction(), "the drag's interaction is still open"); + assert_eq!(amount(&app, a), previewed, "the drag did not keep only what it previewed"); + assert_eq!(amount(&app, b), Some(10.0), "the drag changed the other object"); + let sel = &app.session.doc().unwrap().selection; + assert!(sel.len() == 1 && sel.contains(NodeId(b)), "the other object is no longer the selection"); + assert_eq!(undo(&app), steps + 1, "the drag is one undo step"); + // A drag whose interaction another one replaced, of the same name, while its row stays in view. + app.run("select.set", json!({"ids": [a]})).unwrap(); + frame(&mut app, vec![]); + frame(&mut app, vec![]); + let before = amount(&app, a); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.5))]); + assert_eq!(open_preview(&app), Some(true), "the drag previews"); + app.session.cancel_interaction().unwrap(); + app.session.begin_interaction("Effect Options").unwrap(); + for i in 1..=12 { + frame(&mut app, vec![egui::Event::PointerMoved(at(0.5 + 0.03 * i as f64))]); + } + frame(&mut app, vec![button(at(0.9), false)]); + frame(&mut app, vec![]); + assert_eq!(open_preview(&app), Some(false), "the drag previewed in, or ended, the interaction that replaced it"); + assert_eq!(amount(&app, a), before, "the drag changed the object"); + app.session.cancel_interaction().unwrap(); + // A drag that begins while another interaction is open. + app.session.begin_interaction("Move").unwrap(); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + for i in 1..=12 { + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2 + 0.05 * i as f64))]); + } + frame(&mut app, vec![button(at(0.8), false)]); + frame(&mut app, vec![]); + assert_eq!(open_preview(&app), Some(false), "the drag previewed in, or ended, the interaction open before it"); + assert_eq!(amount(&app, a), before, "the drag changed the object"); + app.session.cancel_interaction().unwrap(); + // A drag after them previews and keeps its value again. + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.6))]); + frame(&mut app, vec![button(at(0.6), false)]); + frame(&mut app, vec![]); + assert!(!app.session.in_interaction(), "the drag's interaction is still open"); + assert_ne!(amount(&app, a), before, "the drag kept nothing"); + app.run("plugin.remove", json!({"id": "test.ui.slideswitch"})).unwrap(); +} + +/// A drag on a plug-in slider keeps what it previewed as one undo step in its own document when +/// another document becomes active while the button is down (as the keyboard switches documents). +#[test] +fn a_plug_in_slider_drag_keeps_its_preview_when_another_document_becomes_active() { + use egui::accesskit::Role; + use vectorcraft_plugins::wat as tpl; + let params = r#"{"amount":{"type":"number","min":0,"max":100,"default":10,"label":"Amount","widget":"slider"}}"#; + let src = tpl::module(&tpl::manifest("test.ui.slidedoc", "effect", params), tpl::ECHO, "", 1); + let mut app = VectorcraftApp::new(vectorcraft_engine::Session::new(), Default::default()); + app.run("plugin.install", json!({"dataBase64": vectorcraft_format::base64_encode(&wat::parse_str(src).unwrap())})).unwrap(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + app.run("file.new", json!({"width": 100, "height": 100})).unwrap(); + assert!(app.session.set_active(0)); + let a = app.run("shape.rectangle", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap()["id"].as_u64().unwrap(); + app.run("effect.apply", json!({"effect": "plugin.test.ui.slidedoc"})).unwrap(); + app.run("select.set", json!({"ids": [a]})).unwrap(); + let ctx = egui::Context::default(); + ctx.enable_accesskit(); + crate::theme::install_fonts(&ctx); + set_pstate(&ctx, "ap-fx-open-None-0", true); + let mut time = 0.0; + let mut frame = |app: &mut VectorcraftApp, events: Vec| { + time += 1.0 / 60.0; + let screen = Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(320.0, 700.0)); + let mut out = ctx.run_ui(egui::RawInput { events, time: Some(time), screen_rect: Some(screen), ..Default::default() }, |ui| show(app, ui)); + out.textures_delta.clear(); + out.platform_output.accesskit_update.map(|u| u.nodes).unwrap_or_default() + }; + let amount = |app: &VectorcraftApp| app.session.doc().unwrap().doc.node(NodeId(a)).unwrap().appearance.effects[0].params["amount"].as_f64(); + let slider = |nodes: &[(egui::accesskit::NodeId, egui::accesskit::Node)]| { + nodes.iter().find(|(_, n)| n.role() == Role::Slider).and_then(|(_, n)| n.bounds()) + }; + let button = |pos, pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; + frame(&mut app, vec![]); + let rail = slider(&frame(&mut app, vec![])).expect("the slider shows"); + let at = |x: f64| egui::pos2((rail.x0 + x * (rail.x1 - rail.x0)) as f32, ((rail.y0 + rail.y1) / 2.0) as f32); + let steps = app.session.doc().unwrap().history.undo.len(); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.2))]); + frame(&mut app, vec![button(at(0.2), true)]); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.6))]); + let previewed = amount(&app); + assert_ne!(previewed, Some(10.0), "the drag previews"); + assert!(app.session.set_active(1)); + frame(&mut app, vec![egui::Event::PointerMoved(at(0.8))]); + frame(&mut app, vec![button(at(0.8), false)]); + assert!(!app.session.in_interaction(), "the other document has an interaction open"); + assert!(app.session.set_active(0)); + assert!(!app.session.in_interaction(), "the drag's interaction is still open"); + assert_eq!(amount(&app), previewed, "the drag did not keep its preview"); + assert_eq!(app.session.doc().unwrap().history.undo.len(), steps + 1, "the drag is not one undo step"); + app.run("plugin.remove", json!({"id": "test.ui.slidedoc"})).unwrap(); +} + /// Glass with a loaded texture lists Loaded Texture in its Texture menu, as its dialog does. #[test] fn the_effect_editor_lists_a_loaded_glass_texture() {