diff --git a/crates/ui-egui/src/dialogs/columns_dialog_tests.rs b/crates/ui-egui/src/dialogs/columns_dialog_tests.rs index 6f1ba2fcd..e23acd214 100644 --- a/crates/ui-egui/src/dialogs/columns_dialog_tests.rs +++ b/crates/ui-egui/src/dialogs/columns_dialog_tests.rs @@ -94,6 +94,16 @@ fn a_field_left_as_shown_keeps_each_text_box_s_own_value() { assert_eq!(columns_of_each(&h), before); } +/// The bug this prevents: opening Columns with the earlier dialog's `spacing` in inches applied that number in points. +#[test] +fn an_opening_spacing_is_in_inches() { + let mut h = harness(); + dialog_method(&mut h, "ui.dialog.open", json!({"id": "columns", "fields": {"spacing": 0.5}})); + h.run_steps(2); + confirm(&mut h); + assert_eq!(columns_of(&h).1, Some(0.5 * 72.0)); +} + fn field(h: &Harness<'_, SlideApp>, key: &str) -> Option { super::inspect(&h.ctx).as_array()?.iter().find(|dialog| dialog["key"] == "columns")?.get("fields")?.get(key).cloned() } diff --git a/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs b/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs index b38a8b89c..ba46ff34b 100644 --- a/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs +++ b/crates/ui-egui/src/dialogs/paragraph_dialog_tests.rs @@ -69,6 +69,19 @@ fn paragraph_button_aligns_text_in_one_undo() { assert_eq!(h.state().session.active().unwrap().history.undo.len(), undo); } +/// The bug this prevents: opening Paragraph with the fields the earlier dialog took (`before` in inches, `align: +/// right`) was refused or set the indent in points. +#[test] +fn opening_fields_as_the_earlier_dialog_took_them_apply() { + let mut h = harness(); + dialog(&mut h, "ui.dialog.open", json!({"id": "paragraph", "fields": {"before": "0.5", "align": "right"}})); + dialog(&mut h, "ui.dialog.confirm", json!({"dialog": "top"})); + assert!(super::open_keys(&h.ctx).is_empty(), "status {:?}", h.state().status); + assert_eq!(align_of(&h).as_deref(), Some(deckcraft_model::text::Align::Right.xml())); + let st = h.state().session.active().unwrap(); + assert_eq!(st.selected_shapes()[0].text.as_ref().unwrap().paragraphs[0].props.margin_left, Some(0.5 * 72.0)); +} + /// Paragraph-dialog tab settings apply the chosen stop and return to the paragraph controls. #[test] fn tabs_from_paragraph_applies_a_stop_and_returns() { diff --git a/crates/ui-egui/src/dialogs/protocol_fields.rs b/crates/ui-egui/src/dialogs/protocol_fields.rs index 4f56d312a..fc08505b6 100644 --- a/crates/ui-egui/src/dialogs/protocol_fields.rs +++ b/crates/ui-egui/src/dialogs/protocol_fields.rs @@ -7,7 +7,7 @@ use serde_json::{Value, json}; /// The opener parameters of dialog `id`, with the fields that choose how it opens taken out of `fields`: the tab -/// Bullets and Action Settings open on. +/// Bullets and Action Settings open on. The opening fields the earlier dialogs took become the hosted dialogs' own. pub(super) fn opener(id: &str, params: &Value, fields: &mut Vec<(String, Value)>) -> Value { let mut params = if params.is_object() { params.clone() } else { json!({}) }; if matches!(id, "bullets" | "action") @@ -15,9 +15,50 @@ pub(super) fn opener(id: &str, params: &Value, fields: &mut Vec<(String, Value)> { params["tab"] = fields.remove(at).1; } + for (field, value) in fields.iter_mut() { + let (name, translated) = opening_field(id, field, value.take()); + *field = name; + *value = translated; + } params } +/// An opening field as the earlier dialogs named it, in the hosted dialog's name and unit: Columns' `spacing` and +/// Paragraph's `before`, `after` and `by` in inches, Paragraph's `align`, `special`, `spaceBefore` and `spaceAfter`. +/// A value that cannot be read goes as it is, for the dialog to refuse. +fn opening_field(id: &str, field: &str, value: Value) -> (String, Value) { + let inches = |value: Value| number(&value).map_or(value, |inches| json!(inches * 72.0)); + let named = |value: Value, names: &[(&str, &str)]| match names.iter().find(|(old, _)| value.as_str() == Some(*old)) { + Some((_, name)) => json!(name), + None => value, + }; + let (name, value) = match (id, field) { + ("columns", "spacing") => (field, inches(value)), + ("paragraph", "before") => ("before_text", inches(value)), + ("paragraph", "after") => ("after_text", inches(value)), + ("paragraph", "by") => (field, inches(value)), + ("paragraph", "spaceBefore") => ("space_before", value), + ("paragraph", "spaceAfter") => ("space_after", value), + ("paragraph", "align") => ( + field, + named( + value, + &[ + ("left", "Left"), + ("center", "Center"), + ("right", "Right"), + ("justify", "Justify"), + ("justLow", "JustifyLow"), + ("distributed", "Distributed"), + ], + ), + ), + ("paragraph", "special") => (field, named(value, &[("none", "None"), ("first", "FirstLine"), ("hanging", "Hanging")])), + _ => (field, value), + }; + (name.to_owned(), value) +} + /// `fields` as dialog `key` takes them, read against its current fields `current`; `tab` is the Action Settings tab /// a `kind` applies to. pub(super) fn typed(key: &str, current: &Value, tab: &str, fields: Vec<(String, Value)>) -> Result, String> { diff --git a/docs/control-protocol.md b/docs/control-protocol.md index 152386a3c..855afc5d9 100644 --- a/docs/control-protocol.md +++ b/docs/control-protocol.md @@ -46,7 +46,7 @@ Coordinates are slide points (1/72 inch; a 16:9 slide is 960 × 540) unless note | `ui.wheel` / `ui.drop` / `ui.capsLock` | Library synthetic-input parameters | Wheel input, file drops and Caps Lock state through the window host | | `ui.set` | `{tab?, view?, pane?, notes?, zoom?, dark?, recent?, palette?: {query, selected?}, backstage?: {page?, query?, exportTask?, fileType?, printLayout?, printRange?}, paneWidth?, thumbsWidth?, notesHeight?, caretBlink?, presenterView?, handoutPerPage?, …}` | Set UI state and return the full state. Pane sizes are finite numbers in points, clamped to the supported ranges. `caretBlink: false` requests a solid editor caret; true inherits the motion policy. `recent` is a list of paths. Palette selection is a displayed-result ordinal, excluding headings and dividers; it is normalized by the palette. File-page keyboard focus uses `ui.focus` on the entry label | | `ui.notify` | `{text, kind?: toast\|status}` | Post a notice; the default kind is `toast` | -| `ui.dialog.open` | `{id, params?, fields?}` | Open a dialog through its registered implementation; `fields` pre-fills its fields, and `tab` among them picks the tab Bullets and Action Settings open on | +| `ui.dialog.open` | `{id, params?, fields?}` | Open a dialog through its registered implementation; `fields` pre-fills its fields, and `tab` among them picks the tab Bullets and Action Settings open on. Columns `spacing` and Paragraph `before`, `after` and `by` are in inches; Paragraph also takes `align` (`left`, `center`, `right`, `justify`, `justLow`, `distributed`), `special` (`none`, `first`, `hanging`), `spaceBefore` and `spaceAfter` | | `ui.dialog.set` / `ui.dialog.confirm` / `ui.dialog.cancel` / `ui.dialog.close` | Dialog selector and fields for `set` | Edit or answer the real hosted dialog; closing follows its cancel path. A value may be text: a number field takes its digits, a check box `1`/`0` or `true`/`false`. Some dialogs also take these names: Find `text` (Find what), Hyperlink `mode: slide` (a place in this document), Action Settings `kind` (`none`, `program`, `playMedia` or a hyperlink target such as `url`), Paragraph `lineKind` (`multiple` or `exactly`) and `lineValue`, Tabs `stops` as `position:align\|…` (inches; `l`, `ctr`, `r`, `dec`), Reuse Slides `off{index}: 1` (untick a slide). A value outside a field's range is refused at `set` | | `ui.screenshot` | `{path?, region?: [x0,y0,x1,y1], window?: docWindow\|presenter}` | Capture a PNG of the named window or the main window. A region is in window points. Without a path, return `{base64, mime, width, height, pixels_per_point}`; with a path, return `{path, width, height, pixels_per_point}`. Unknown or closed windows are refused | | `ui.render` | `{path?, slide?, scale?}` | Render a slide headlessly |