diff --git a/crates/engine/src/doc_state.rs b/crates/engine/src/doc_state.rs index e66e54d9ed..39303760a3 100644 --- a/crates/engine/src/doc_state.rs +++ b/crates/engine/src/doc_state.rs @@ -706,7 +706,7 @@ impl DocState { } } /// Ask the Layers panel to reveal what changed since `before`, in this order: isolation entered - /// or left, the highlighted rows, the current layer, the last selected object. A request made + /// or left, the highlighted rows, the last selected object, the current layer. A request made /// meanwhile (`layer.locate`) stands, and nothing is asked while an interaction is open, so a /// drag's previews reveal nothing and its commit does. pub(crate) fn request_reveal(&mut self, before: &LayersView) { @@ -721,9 +721,8 @@ impl DocState { if request.is_none() && now.rows != before.rows { request = self.highlighted_rows().first().copied().map(LayersReveal::Row); } - if request.is_none() && now.active_layer != before.active_layer { - request = self.current_layer().map(LayersReveal::Current); - } + // A new selection asks for its object even when it changed the current layer too: the panel + // falls back to the current layer when it does not locate the object. if request.is_none() && now.last_selected != before.last_selected { request = now.last_selected.map(LayersReveal::Selected); // An emptied selection leaves no object to locate. @@ -731,6 +730,9 @@ impl DocState { self.layers_reveal = None; } } + if request.is_none() && now.active_layer != before.active_layer { + request = self.current_layer().map(LayersReveal::Current); + } if request.is_some() { self.layers_reveal = request; } diff --git a/crates/ui-egui/src/chrome.rs b/crates/ui-egui/src/chrome.rs index b9ce78df01..da631b764d 100644 --- a/crates/ui-egui/src/chrome.rs +++ b/crates/ui-egui/src/chrome.rs @@ -91,7 +91,10 @@ impl Trailing { Trailing::Discord => crate::community::discord_button(app, ui), Trailing::Learn => { // PLAN: assumed `IconButton::command` is bound by a `&str` command id. - IconButton::command(IconId::new("graduation-cap"), "window.learn").selected(crate::panels::learn::visible(app)).show(ui); + IconButton::command(IconId::new("graduation-cap"), "window.learn") + .label(tl!("Explore tutorials")) + .selected(crate::panels::learn::visible(app)) + .show(ui); } Trailing::Arrange => arrange_documents(app, ui), Trailing::Search => { diff --git a/crates/ui-egui/src/dialogs/save_library.rs b/crates/ui-egui/src/dialogs/save_library.rs index e961c6ee5b..0e69c82c15 100644 --- a/crates/ui-egui/src/dialogs/save_library.rs +++ b/crates/ui-egui/src/dialogs/save_library.rs @@ -69,10 +69,14 @@ pub(super) fn open(app: &mut VectorcraftApp, library: Library, names: Vec Value { let fields = &result.fields; let mut p = json!({"name": fields.text("name").unwrap_or_default(), "user": fields.text("saveTo") == Some("user")}); + if let Some(format) = fields.text("format") { + p["format"] = json!(format); + } if fields.bool("selectedOnly") == Some(true) { let names = fields.list("names").map(|l| l.iter().filter_map(|v| if let FieldValue::Text(s) = v { Some(json!(s)) } else { None }).collect()); p["names"] = Value::Array(names.unwrap_or_default()); diff --git a/crates/ui-egui/src/menus/model.rs b/crates/ui-egui/src/menus/model.rs index 93ec42b7b7..f5ebf631ce 100644 --- a/crates/ui-egui/src/menus/model.rs +++ b/crates/ui-egui/src/menus/model.rs @@ -102,6 +102,8 @@ pub(crate) fn state_key(app: &VectorcraftApp, input: Option) -> u64 { (v.edges, v.templates, v.corner_widgets, v.shape_widgets, v.text_threads, v.hidden_chars, v.gradient_annotator).hash(&mut h); (v.live_paint_gaps, v.artboards, v.rulers, v.video_rulers, v.bounding_box, v.guides, v.grid).hash(&mut h); (app.outline_view(), s.guides_locked(), s.slices_hidden()).hash(&mut h); + // The Align To choice: Object › Align's checks and the Distribute buttons with the Artboard tool. + app.ui.align_to.hash(&mut h); crate::panels::actions::menu::key(app).hash(&mut h); crate::panels::script_console::key(app).hash(&mut h); h.finish() diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index 5bdb0b8abd..02ab349b55 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -304,6 +304,15 @@ pub(crate) fn floating_window<'a>(layout: &'a Layout, panel: &str) -> Op layout.floating.iter().find(|w| w.contains(panel)) } +/// The top left a new floating window `height` tall takes beside the window floated last: a cascade +/// step from it, inside the float space. None while nothing floats. +pub(crate) fn cascaded_float_origin(app: &VectorcraftApp, height: f32) -> Option { + let last = layout_of(&app.ui).floating.last()?.rect; + let space = command_space(app); + let size = egui::vec2(space.default_size.x, height); + Some(craft::behavior::placement::cascade(last, size, space.area, space.inset).min) +} + /// Is `panel` showing: in front of its group and not in a column collapsed to icons, or in the /// open flyout of an iconic column? The Window menu checks these. pub(crate) fn showing(ui: &UiState, panel: &str) -> bool { diff --git a/crates/ui-egui/src/panels/align.rs b/crates/ui-egui/src/panels/align.rs index 2ef80aea11..05b4c599bf 100644 --- a/crates/ui-egui/src/panels/align.rs +++ b/crates/ui-egui/src/panels/align.rs @@ -25,7 +25,7 @@ const HIDE_OPTIONS: &str = "align-hide-options"; /// What Align aligns to. The Align To choice kept with the UI state ([`crate::UiState::align_to`]) /// is Selection or Artboard: Align to Key Object stores no choice. -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize)] #[serde(rename_all = "lowercase")] pub enum AlignTo { #[default] diff --git a/crates/ui-egui/src/panels/color_themes.rs b/crates/ui-egui/src/panels/color_themes.rs index 23e0d53bfc..b152be5f28 100644 --- a/crates/ui-egui/src/panels/color_themes.rs +++ b/crates/ui-egui/src/panels/color_themes.rs @@ -634,9 +634,10 @@ mod tests { fx } - /// The slider rails, top to bottom (the wheel's Brightness rail first). + /// The slider rails, top to bottom (the wheel's Brightness rail first). The wheel's colour markers are + /// sliders too, but square: a rail is wider than tall. fn rails(fx: &Fixture) -> Vec { - let mut rails = fx.by_role(Role::SLIDER); + let mut rails: Vec<_> = fx.by_role(Role::SLIDER).into_iter().filter(|t| t.rect.width() > 2.0 * t.rect.height()).collect(); rails.sort_by(|a, b| a.center().y.total_cmp(&b.center().y)); rails } diff --git a/crates/ui-egui/src/panels/history.rs b/crates/ui-egui/src/panels/history.rs index b77b9b80fd..80508d9e4e 100644 --- a/crates/ui-egui/src/panels/history.rs +++ b/crates/ui-egui/src/panels/history.rs @@ -269,12 +269,14 @@ mod tests { }; frame(&mut app, vec![]); let nodes = frame(&mut app, vec![]); - // PLAN: the button is named by the framework's words; the name is matched by its start. - let button = nodes.iter().map(|(_, n)| n).find(|n| n.label().is_some_and(|l| l.starts_with("New Document"))).expect("the button"); + // PLAN: the button is named by the framework's words ("Create New Document from Current State"); the name is + // matched by the words it holds. + let button = nodes.iter().map(|(_, n)| n).find(|n| n.label().is_some_and(|l| l.contains("New Document"))).expect("the button"); let at = button.bounds().expect("its bounds"); let at = egui::pos2((at.x0 + at.x1) as f32 / 2.0, (at.y0 + at.y1) as f32 / 2.0); let press = |pressed| egui::Event::PointerButton { pos: at, button: egui::PointerButton::Primary, pressed, modifiers: Default::default() }; - frame(&mut app, vec![egui::Event::PointerMoved(at), press(true), press(false)]); + frame(&mut app, vec![egui::Event::PointerMoved(at), press(true)]); + frame(&mut app, vec![press(false)]); assert_eq!(app.session.documents().len(), 2); assert_eq!(app.session.active_index(), Some(1), "the new document is the active one"); let st = app.session.active().unwrap(); diff --git a/crates/ui-egui/src/panels/image_trace/tests.rs b/crates/ui-egui/src/panels/image_trace/tests.rs index 85b96f4d75..93e560bcf1 100644 --- a/crates/ui-egui/src/panels/image_trace/tests.rs +++ b/crates/ui-egui/src/panels/image_trace/tests.rs @@ -180,7 +180,8 @@ fn with_preview_off_a_slider_change_waits_for_trace() { panel.click("Trace"); assert_eq!(undo(&panel.app()), steps + 1, "Trace applies it as one undo step"); assert_eq!(children(&panel.app()), 1, "only the source remains below the ink's luminance"); - assert_eq!(find_target(&panel.app()).stored.unwrap()["params"], shown(&panel).params); + let stored = find_target(&panel.app()).stored.unwrap(); + assert_eq!(stored["params"], shown(&panel).params); assert!(!panel.app().ui.image_trace_preview, "Trace leaves Preview off"); } diff --git a/crates/ui-egui/src/panels/layers/tests_reveal.rs b/crates/ui-egui/src/panels/layers/tests_reveal.rs index 1538cdbb94..c8d2820094 100644 --- a/crates/ui-egui/src/panels/layers/tests_reveal.rs +++ b/crates/ui-egui/src/panels/layers/tests_reveal.rs @@ -663,6 +663,11 @@ fn with_the_option_the_panels_own_clicks_locate_nothing() { assert_eq!(listed_ids(&app).len(), 3, "Layer 1, Sub (closed) and c"); select_rows(&mut app, &[layer, sub, c]); assert_eq!(rows_of(&app), [layer, sub, c]); + // Shift-clicks on c's target circle, then Sub's, as the panel's pass runs them: Sub's and c's art is selected. + unrevealed(&mut app, |app| app.run("layer.target", json!({"id": c.0})).unwrap()); + unrevealed(&mut app, |app| app.run("layer.target", json!({"range": [sub.0, c.0]})).unwrap()); + let st = app.session.active().unwrap(); + assert!(st.selection.objects.len() >= 3 && st.selection.objects.contains(&c), "c and Sub's art are selected"); assert_eq!(reveal_of(&app), None, "a selection made in the panel asks for no reveal"); pass(&mut app, &ctx); assert_eq!(listed_ids(&app).len(), 3, "no row opens"); @@ -801,11 +806,10 @@ fn with_the_option_and_show_layers_only_the_active_layer_is_revealed() { pass(&mut app, &ctx); let bottom_layer = app.session.active().unwrap().doc.layer_of(NodeId(bottom)).unwrap(); run(&mut app, "select.set", json!({"ids": [bottom]})); - // PLAN: the sheet row says `Current(layer)` here while writer note 3 says the session sets `Selected(object)` and - // the panel falls back; the sheet row is asserted. - assert_eq!(reveal_of(&app), Some(LayersReveal::Current(bottom_layer))); - pass(&mut app, &ctx); - assert_eq!(reveal_of(&app), None, "the pass took the request"); + // The session asks for the object (writer note 3); the panel, which lists no row for it, reveals its layer. + assert_eq!(reveal_of(&app), Some(LayersReveal::Selected(NodeId(bottom)))); + assert_eq!(reveal_for(&mut app), Some(bottom_layer), "the panel reveals the active layer"); + assert_eq!(reveal_of(&app), None, "the panel took the request"); } /// With Locate Selected Objects on, art selected outside the panel that Show Layers Only or the filter leaves without a @@ -859,11 +863,13 @@ fn a_canvas_selection_reveals_its_active_layer() { let top_layer = doc.layer_of(NodeId(rects[59])).unwrap(); run(&mut app, "select.set", json!({"ids": [rects[0]]})); assert_eq!(app.session.active().unwrap().current_layer(), Some(bottom_layer)); - assert_eq!(reveal_of(&app), Some(LayersReveal::Current(bottom_layer)), "no row is highlighted: the active layer"); - pass(&mut app, &ctx); + assert_eq!(reveal_for(&mut app), Some(bottom_layer), "no row is highlighted: the active layer"); // A row highlighted in the panel keeps the view when the active layer changes. run(&mut app, "layer.highlight", json!({"ids": [top_layer.0], "mode": "set"})); pass(&mut app, &ctx); - run(&mut app, "select.set", json!({"ids": [rects[30]]})); - assert_eq!(reveal_of(&app), None, "a highlighted row keeps the view"); + // The active layer changes, as production's test set it, with the request a change of it makes. + let st = app.session.active_mut().unwrap(); + st.active_layer = Some(bottom_layer); + st.layers_reveal = Some(LayersReveal::Current(bottom_layer)); + assert_eq!(reveal_for(&mut app), None, "a highlighted row keeps the view"); } diff --git a/crates/ui-egui/src/panels/library_panel.rs b/crates/ui-egui/src/panels/library_panel.rs index a476a8357d..d1a67740b6 100644 --- a/crates/ui-egui/src/panels/library_panel.rs +++ b/crates/ui-egui/src/panels/library_panel.rs @@ -413,10 +413,16 @@ pub(crate) fn open_command(app: &mut VectorcraftApp, p: &Value) Ok(json!({"open": id, "panel": panel, "name": name, "count": count})) } -/// Float library panel `panel`, as tall as its body in the kind's view. +/// Float library panel `panel`, as tall as its body in the kind's view, beside the window floated last. pub(crate) fn float(app: &mut VectorcraftApp, panel: &str) -> Result { let large = parse(panel).is_some_and(|(k, _)| k.view == View::LargeThumb); - app.run("window.panel.float", json!({ "panel": panel, "height": if large { 400 } else { 340 } })) + let height = if large { 400.0 } else { 340.0 }; + let mut p = json!({ "panel": panel, "height": height }); + if let Some(at) = crate::panel_docking::cascaded_float_origin(app, height) { + p["x"] = json!(at.x); + p["y"] = json!(at.y); + } + app.run("window.panel.float", p) } /// `ui.libraryPanel {panel, library?, view?, showFind?, persistent?}`: show another library in an diff --git a/crates/ui-egui/src/panels/library_panel/tests.rs b/crates/ui-egui/src/panels/library_panel/tests.rs index 3eb235973d..77183d3f6d 100644 --- a/crates/ui-egui/src/panels/library_panel/tests.rs +++ b/crates/ui-egui/src/panels/library_panel/tests.rs @@ -40,7 +40,9 @@ pub(crate) fn click(app: &mut VectorcraftApp, ctx: &egui::Context, name: &str, m let (_, at) = control(app, ctx, &draw, name); let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers }; draw_frame(app, ctx, &draw, vec![Event::ModifiersChanged(modifiers), Event::PointerMoved(at)]); - draw_frame(app, ctx, &draw, vec![button(true), button(false)]); + // The release comes a frame after the press, as a hand's does. + draw_frame(app, ctx, &draw, vec![button(true)]); + draw_frame(app, ctx, &draw, vec![button(false)]); draw_frame(app, ctx, &draw, vec![Event::ModifiersChanged(Modifiers::NONE)]); } @@ -267,7 +269,7 @@ fn the_save_dialog_writes_swatch_exchange_files() { })), ..Default::default() }; - let mut web = VectorcraftApp::new(Session::new(), services); + let mut web = crate::testing::windowed(VectorcraftApp::new(Session::new(), services)); web.run("file.new", json!({"width": 100, "height": 100})).unwrap(); web.run("ui.saveSwatchLibrary", json!({})).unwrap(); confirm_save(&mut web, &[("format", json!("ase")), ("name", json!(" Brand: Kit. "))]); @@ -361,7 +363,8 @@ fn control(app: &mut VectorcraftApp, ctx: &egui::Context, draw: &dyn Fn(&mut Vec fn click_at(app: &mut VectorcraftApp, ctx: &egui::Context, draw: &dyn Fn(&mut VectorcraftApp, &mut Ui), at: Pos2) { let button = |pressed| Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }; draw_frame(app, ctx, draw, vec![Event::PointerMoved(at)]); - draw_frame(app, ctx, draw, vec![button(true), button(false)]); + draw_frame(app, ctx, draw, vec![button(true)]); + draw_frame(app, ctx, draw, vec![button(false)]); } /// The app restarted with the preferences `app` saves.