diff --git a/crates/ui-egui/src/addons/shapes.rs b/crates/ui-egui/src/addons/shapes.rs index ac5cf97d74..5d7b11bcaf 100644 --- a/crates/ui-egui/src/addons/shapes.rs +++ b/crates/ui-egui/src/addons/shapes.rs @@ -6,7 +6,6 @@ use std::ops::RangeInclusive; use craft::behavior::{IconId, NumberCodec}; -use craft::keymap::CommandRef; use craft::menu::Node; use craft::ui::buttons::{Button, ToggleButton}; use craft::ui::choice::Segmented; @@ -67,10 +66,13 @@ pub fn control_bar(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { // The tools with live shape widgets: Hide/Show Shape Widgets first, so a narrow bar leaves out // the shape's fields before it. if vectorcraft_tools::shape::shows_shape_widgets(&tool) { - // The command's own title is the label, and a click runs the command. - member(ui, |ui| { - Button::command(CommandRef::new("view.shapeWidgets")).show(ui); - }); + // The command is in no menu, so the button names it: Hide, or Show while the widgets are hidden. + let label = if app.ui.view.shape_widgets { tl!("Hide Shape Widgets") } else { tl!("Show Shape Widgets") }; + let mut clicked = false; + member(ui, |ui| clicked |= Button::new(label.to_string()).show(ui).clicked()); + if clicked { + crate::menus::invoke(app, "view.shapeWidgets", json!({})); + } divider(ui); } diff --git a/crates/ui-egui/src/app.rs b/crates/ui-egui/src/app.rs index af61045261..9c3ca298ed 100644 --- a/crates/ui-egui/src/app.rs +++ b/crates/ui-egui/src/app.rs @@ -487,6 +487,7 @@ impl VectorcraftApp { let Ok(mut app) = app.try_borrow_mut() else { return }; let app: &mut VectorcraftApp = &mut app; app.canvas.windows.area = Some(ui.available_rect_before_wrap()); + app.canvas.windows.last_noted = std::mem::take(&mut app.canvas.windows.noted); let floats = crate::doc_windows::current_floats(app); if !canvas::tiled_area(app, ui) { if floats { diff --git a/crates/ui-egui/src/canvas/drops.rs b/crates/ui-egui/src/canvas/drops.rs index b4a3b65378..ba391eda1e 100644 --- a/crates/ui-egui/src/canvas/drops.rs +++ b/crates/ui-egui/src/canvas/drops.rs @@ -190,11 +190,13 @@ impl Component for CanvasDrops<'_> { /// the carry it catches: the pane's area is noted instead. pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut Ui, win: Win, kind: BodyKind) { let rect = ui.max_rect(); - if kind == BodyKind::Pane - && let Some(later) = &mut app.canvas.panes.drops - { - later.push((win, rect)); - return; + if kind == BodyKind::Pane { + if let Some(later) = &mut app.canvas.panes.drops { + later.push((win, rect)); + return; + } + // A pane outside Tile (a floating window's, the main window's while the current window floats). + app.canvas.windows.noted.push((win, rect)); } let view = match kind { BodyKind::Live => app.canvas_view(), @@ -248,28 +250,31 @@ pub(crate) fn drop_on_pane(app: &mut VectorcraftApp, win: Win, drop: &Dropped) { } } -/// Art carried off the canvas and released at `at` (screen) over a pane this pass noted, in the frame the pointer -/// reached it, before the pane could take it as a drop: the pane's window and the drop there. +/// Art carried off the canvas and released at `at` (screen) over a pane this pass noted, or a pane outside Tile the +/// last frame drew (the front one first), in the frame the pointer reached it, before the pane could take it as a drop: +/// the pane's window and the drop there. pub(crate) fn released_on_pane(app: &VectorcraftApp, art: CarriedArt, at: Pos2, op: DropOperation) -> Option<(Win, Dropped)> { - let (win, rect) = app.canvas.panes.drops.as_ref()?.iter().rev().copied().find(|(_, rect)| rect.contains(at))?; + let outside = app.canvas.windows.last_noted.iter().rev(); + let (win, rect) = outside.chain(app.canvas.panes.drops.iter().flatten().rev()).copied().find(|(_, rect)| rect.contains(at))?; let view = pane_view(app, win, rect)?; Some((win, Dropped { payload: Payload::Art(art), at: view.to_doc(at), zoom: view.zoom, op })) } /// Starts carrying the art of a Selection, Direct Selection or Group Selection move that left the canvas, handing it -/// to the drag session. Moves of anchors or segments stay reshapes. → whether a carry runs. -pub(crate) fn carry_out(app: &mut VectorcraftApp, cx: &mut ToolContext<'_>, pointer: &ToolPointer) -> bool { - let Some(art) = carried(app, cx, pointer) else { return false }; +/// to the drag session. Moves of anchors or segments stay reshapes. `covered`: another window is over the canvas at the +/// pointer. → whether a carry runs. +pub(crate) fn carry_out(app: &mut VectorcraftApp, cx: &mut ToolContext<'_>, pointer: &ToolPointer, covered: bool) -> bool { + let Some(art) = carried(app, cx, pointer, covered) else { return false }; let panel = PanelDrag::Art { document: art.document, ids: art.ids.clone() }; cx.start_drag_also(art, Arc::new(panel), DragPreview::None); true } /// The art a Selection, Direct Selection or Group Selection move carries with the pointer at `pointer`, off the -/// canvas; `None` on the canvas or for any other gesture. -pub(crate) fn carried(app: &VectorcraftApp, cx: &ToolContext<'_>, pointer: &ToolPointer) -> Option { +/// canvas or where another window (`covered`) is over it; `None` on the canvas or for any other gesture. +pub(crate) fn carried(app: &VectorcraftApp, cx: &ToolContext<'_>, pointer: &ToolPointer, covered: bool) -> Option { let tool = app.session.tool_id(); - if !matches!(tool, "selection" | "directSelection" | "groupSelection") || cx.rect.contains(pointer.pos) { + if !matches!(tool, "selection" | "directSelection" | "groupSelection") || (cx.rect.contains(pointer.pos) && !covered) { return None; } let st = app.session.active()?; diff --git a/crates/ui-egui/src/canvas/panes.rs b/crates/ui-egui/src/canvas/panes.rs index dd101827c8..4dedfa2f09 100644 --- a/crates/ui-egui/src/canvas/panes.rs +++ b/crates/ui-egui/src/canvas/panes.rs @@ -377,10 +377,7 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { let mut catcher = ui.new_child(egui::UiBuilder::new().id_salt(("pane-drops", w)).max_rect(area)); super::drops::show(app, &mut catcher, w, BodyKind::Pane); } - app.canvas.panes.released_from = None; - if let Some((w, drop)) = app.canvas.panes.released.take() { - super::drops::drop_on_pane(app, w, &drop); - } + drop_released(app); // Note the fits this frame made, for `refit_resized`. for ((w, area), was_unfitted) in areas.iter().zip(unfitted) { if let (true, Some(v), Some(s)) = (was_unfitted, crate::doc_windows::view(app, *w).filter(|v| v.fitted).copied(), slot(app, *w)) { @@ -397,6 +394,15 @@ pub(crate) fn tiled_area(app: &mut VectorcraftApp, ui: &mut Ui) -> bool { true } +/// Drops the art released over a pane in the frame the pointer reached it ([`super::drops::released_on_pane`]), once +/// the panes that could have taken it as a drop have drawn. +pub(crate) fn drop_released(app: &mut VectorcraftApp) { + app.canvas.panes.released_from = None; + if let Some((w, drop)) = app.canvas.panes.released.take() { + super::drops::drop_on_pane(app, w, &drop); + } +} + /// Window `w`'s [`Slot`]. fn slot(app: &VectorcraftApp, (i, n): Win) -> Option { app.session.documents().get(i).map(|d| (d.uid, n)) diff --git a/crates/ui-egui/src/canvas/tool_adapter.rs b/crates/ui-egui/src/canvas/tool_adapter.rs index 0e43ca0dc9..9bb95ae577 100644 --- a/crates/ui-egui/src/canvas/tool_adapter.rs +++ b/crates/ui-egui/src/canvas/tool_adapter.rs @@ -116,11 +116,19 @@ struct SessionTool<'a> { view: ViewInfo, /// The art of this gesture goes to a drag session (another tab or a panel): the view stays. carrying: Cell, + /// The canvas's context and layer: a window over the canvas (a floating document's) hides it from the pointer. + ctx: egui::Context, + layer: egui::LayerId, } impl<'a> SessionTool<'a> { - fn new(app: &'a mut VectorcraftApp, view: ViewInfo) -> Self { - Self { app: RefCell::new(app), view, carrying: Cell::new(false) } + fn new(app: &'a mut VectorcraftApp, view: ViewInfo, ui: &Ui) -> Self { + Self { app: RefCell::new(app), view, carrying: Cell::new(false), ctx: ui.ctx().clone(), layer: ui.layer_id() } + } + + /// Whether another window covers the canvas at `pointer`, so art moved there leaves the canvas. + fn covered(&self, pointer: &ToolPointer) -> bool { + self.ctx.layer_id_at(pointer.pos).is_some_and(|l| l != self.layer) } fn app(&self) -> RefMut<'_, &'a mut VectorcraftApp> { @@ -278,7 +286,7 @@ impl CanvasTool for SessionTool<'_> { return; } // Art carried off the canvas waits where it last moved; back on the canvas the move goes on. - let carried = super::drops::carry_out(&mut self.app(), cx, pointer); + let carried = super::drops::carry_out(&mut self.app(), cx, pointer, self.covered(pointer)); if !carried { let ev = pointer_event(PointerKind::Drag, pointer, cx); dispatch(&mut self.app(), &ev, self.view); @@ -298,7 +306,7 @@ impl CanvasTool for SessionTool<'_> { return; } drop(app); - let carried = super::drops::carried(&self.app(), cx, pointer); + let carried = super::drops::carried(&self.app(), cx, pointer, self.covered(pointer)); self.app().canvas.panes.released_from = carried.as_ref().map(|art| (art.document, art.revision)); if cx.over_drop_target() || carried.is_some() { // The art goes to the drop target, or nowhere off the canvas: the move is given up where it started. @@ -529,7 +537,7 @@ pub(crate) fn run(app: &mut VectorcraftApp, ui: &mut Ui, pass: &ToolPass) -> Too let mut response = if crate::dialogs::recolor::edit_tab::with_theme_pick(app, |app, tool| picked = host_run(app, ui, pass, tool)) { picked } else { - let mut tool = SessionTool::new(app, view_info); + let mut tool = SessionTool::new(app, view_info, ui); let response = host_run_session(&mut tool, ui, pass); drop(tool); response diff --git a/crates/ui-egui/src/doc_windows.rs b/crates/ui-egui/src/doc_windows.rs index 0e45531ac4..619d1ee8c8 100644 --- a/crates/ui-egui/src/doc_windows.rs +++ b/crates/ui-egui/src/doc_windows.rs @@ -81,6 +81,10 @@ pub struct Windows { known: Vec, /// The documents' views beyond the one each shows ([`views`]). pub(crate) views: Views, + /// The panes drawn outside Tile in this frame so far (the floating windows', the main window's while the current + /// window floats), back to front, with the art area each takes drops in; and those of the last frame. + pub(crate) noted: Vec<(Win, egui::Rect)>, + pub(crate) last_noted: Vec<(Win, egui::Rect)>, } impl Windows { @@ -311,8 +315,14 @@ pub(crate) fn focus_main_window(app: &VectorcraftApp, ctx: &egui::Context) { } /// Draw the floating document windows, after the main window's canvas. Call once per frame from -/// the main window. +/// the main window. Art released over a pane in the frame the pointer reached it drops there then. pub(crate) fn show(app: &mut VectorcraftApp, ui: &mut egui::Ui) { + show_windows(app, ui); + crate::canvas::panes::drop_released(app); +} + +/// [`show`]'s windows. +fn show_windows(app: &mut VectorcraftApp, ui: &mut egui::Ui) { let live: Vec<(u64, u32)> = windows(app).into_iter().filter_map(|w| key(app, w)).collect(); app.ui.floating.retain(|w| live.contains(&(w.uid, w.view))); let current = current(app).and_then(|w| key(app, w)); diff --git a/crates/ui-egui/src/panel_docking.rs b/crates/ui-egui/src/panel_docking.rs index 85adf88eb7..29278127f2 100644 --- a/crates/ui-egui/src/panel_docking.rs +++ b/crates/ui-egui/src/panel_docking.rs @@ -816,7 +816,8 @@ fn shared_command_with(app: &mut VectorcraftApp, id: &str, params: &Value, extra let mut actions = match id { _ if shown => Vec::new(), "window.panel.close" | "window.panel.minimize" => Vec::new(), - _ => show_actions(ws, &space, &panel, id != "window.panel.float"), + // Only Dock and Move put a panel with no place in the dock; showing it (`window.panel.activate`) floats it. + _ => show_actions(ws, &space, &panel, matches!(id, "window.panel.dock" | "window.panel.move")), }; // The command's own actions read the layout with the panel shown. let trial = if actions.is_empty() { diff --git a/crates/ui-egui/src/panel_docking/tests.rs b/crates/ui-egui/src/panel_docking/tests.rs index 44e32f8326..3668ad92f5 100644 --- a/crates/ui-egui/src/panel_docking/tests.rs +++ b/crates/ui-egui/src/panel_docking/tests.rs @@ -52,7 +52,9 @@ impl Harness { /// The rect of the node of `role` named like `panel` (its title, ignoring case and spaces) in the last frame. // PLAN: assumed the dock names a tab and an icon by the panel's title, with the roles Tab and Button. fn named(&self, panel: &str, role: egui::accesskit::Role) -> Option { - let wanted = panel.to_lowercase().replace(' ', ""); + // A library panel's title is its library's name. + let title = crate::panels::library_panel::tab_label(&self.app, panel).unwrap_or_else(|| panel.to_owned()); + let wanted = title.to_lowercase().replace(' ', ""); self.nodes .iter() .filter(|(_, node)| node.role() == role && node.label().is_some_and(|l| l.to_lowercase().replace(' ', "") == wanted)) @@ -163,15 +165,19 @@ fn icon_column(columns: &[Column]) -> Option { .map(|(_, k)| k) } -/// Answers the topmost open dialog with OK or Cancel, then runs the frame's dialog pump. +/// Answers the topmost open dialog with OK or Cancel, then runs the frame's dialog pump. A held OK is answered +/// through the pump. fn answer(app: &mut VectorcraftApp, ok: bool) { let ctx = app.ui_ctx.clone().expect("a frame ran"); - let answered = app.dialogs().expect("a window").with(|host| { - let id = host.open_dialogs().last().map(|d| d.id).expect("a dialog is open"); - if ok { host.confirm_by_id(&ctx, id) } else { host.cancel_by_id(&ctx, id) } - }); - assert!(answered, "the dialog took the answer"); - crate::dialogs::host::pump(app, &ctx); + let id = app.dialogs().expect("a window").with(|host| host.open_dialogs().last().map(|d| d.id)).expect("a dialog is open"); + if ok { + crate::tests::picks::answer_dialog(app, id, &[], true); + } else { + assert!(app.dialogs().expect("a window").with(|host| host.cancel_by_id(&ctx, id)), "the dialog took the answer"); + crate::dialogs::host::pump(app, &ctx); + } + let still = app.dialogs().expect("a window").with(|host| host.open_dialogs().iter().any(|d| d.id == id)); + assert!(!still, "the dialog took the answer"); } fn first_column_iconic(h: &Harness) -> bool { diff --git a/crates/ui-egui/src/toolbar/tests.rs b/crates/ui-egui/src/toolbar/tests.rs index d94ee98633..745ce0f32b 100644 --- a/crates/ui-egui/src/toolbar/tests.rs +++ b/crates/ui-egui/src/toolbar/tests.rs @@ -142,7 +142,9 @@ fn tools_open_their_options() { assert_eq!(open_options(&mut app, tool), Err("nothing selected".into()), "{tool}"); } assert!(open_options(&mut app, "lasso").is_err(), "a tool without options"); - // Hand fits the artboard in the window, Zoom goes to 100%. + // Hand fits the active artboard in the window, Zoom goes to 100%. The Artboard tool made the second active above: + // the first is the active one again. + crate::panels::artboards::select(&mut app, 0); app.view_mut().unwrap().rect = egui::Rect::from_min_size(Pos2::ZERO, egui::vec2(660.0, 460.0)); app.run("view.setZoom", json!({"zoom": 333, "center": [10, 10]})).unwrap(); open_options(&mut app, "hand").unwrap();