mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-04 13:02:50 -05:00
Merge pull request #10763 from dotCooCoo/fix/drops-ignore-hidden-palettes
Panels: hidden or minimized palette windows no longer block canvas drops
This commit is contained in:
2 files changed
+60
-3
No files matched your search
@@ -1317,15 +1317,24 @@ fn window_viewport(app: &VectorcraftApp, panel: &str) -> Option<egui::ViewportId
|
||||
}
|
||||
|
||||
/// Whether the OS window of a floating panel lies at `pos`, a point of the main window: a palette
|
||||
/// window stays in front of the main window.
|
||||
/// window stays in front of the main window. A hidden or minimized palette window does not count.
|
||||
pub(crate) fn os_window_at(app: &VectorcraftApp, ctx: &egui::Context, pos: egui::Pos2) -> bool {
|
||||
if app.dock_rt.windows.is_empty() {
|
||||
return false;
|
||||
}
|
||||
// Workaround for craft-libs#4739: `WindowHost::viewports_at` still lists palette windows that are minimized, or
|
||||
// hidden while a dialog or popup shows. Remove these checks when the craft-libs pin includes craft-libs#4739.
|
||||
if app.any_dialog_open() {
|
||||
return false;
|
||||
}
|
||||
let origin = ctx.input(|i| i.raw.viewports.get(&i.raw.viewport_id).and_then(|v| v.inner_rect).map(|r| r.min.to_vec2()));
|
||||
let Some(origin) = origin else { return false };
|
||||
let under = craft::ui::runtime::windows::WindowHost::of(ctx).viewports_at(pos + origin);
|
||||
under.iter().any(|viewport| app.dock_rt.windows.iter().any(|(_, shown)| shown == viewport))
|
||||
let host = craft::ui::runtime::windows::WindowHost::of(ctx);
|
||||
let under = host.viewports_at(pos + origin);
|
||||
// Workaround for craft-libs#4739 (see above).
|
||||
let restored =
|
||||
|viewport: &egui::ViewportId| host.facts(*viewport).is_some_and(|facts| facts.state != craft::host::target::WindowState::Minimized);
|
||||
under.iter().filter(|viewport| restored(viewport)).any(|viewport| app.dock_rt.windows.iter().any(|(_, shown)| shown == viewport))
|
||||
}
|
||||
|
||||
/// Brings the OS window of the floating window holding `panel` forward, as it was last drawn.
|
||||
|
||||
@@ -28,6 +28,8 @@ struct Window {
|
||||
/// Whether the window shows on the desktop: the builder's visibility when it opened, then each
|
||||
/// `Visible` command.
|
||||
visible: bool,
|
||||
/// Whether the OS reports the window minimized.
|
||||
minimized: bool,
|
||||
frames: usize,
|
||||
/// The texts its last frame drew, with their rects in the window.
|
||||
texts: Vec<(String, Rect)>,
|
||||
@@ -59,6 +61,7 @@ impl Host {
|
||||
std::iter::once((ViewportId::ROOT, info(ViewportId::ROOT, SCREEN.translate(ORIGIN.to_vec2()))))
|
||||
.chain(self.windows.iter().map(|(id, w)| {
|
||||
let mut info = info(*id, w.rect);
|
||||
info.minimized = Some(w.minimized);
|
||||
if w.close_requested {
|
||||
info.events.push(egui::ViewportEvent::Close);
|
||||
}
|
||||
@@ -96,6 +99,7 @@ impl Host {
|
||||
dropped: Vec::new(),
|
||||
close_requested: false,
|
||||
visible: builder.visible != Some(false),
|
||||
minimized: false,
|
||||
frames: 0,
|
||||
texts: Vec::new(),
|
||||
nodes: Vec::new(),
|
||||
@@ -633,3 +637,47 @@ fn a_window_menu_panel_stays_shown_while_art_is_selected_and_moved() {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// A floating panel's window over the canvas, with the main window holding the keyboard: the window and the point at
|
||||
/// its middle, in the main window's points.
|
||||
fn palette_over_canvas(h: &mut Harness) -> (ViewportId, Pos2) {
|
||||
let viewport = h.float("graphicStyles");
|
||||
h.host.borrow_mut().focus = ViewportId::ROOT;
|
||||
h.frames(2);
|
||||
let middle = h.host.borrow().windows[&viewport].rect.center() - ORIGIN.to_vec2();
|
||||
let view = h.app.canvas_view().expect("the canvas was drawn");
|
||||
assert!(view.rect.contains(middle), "the window lies over the canvas");
|
||||
assert!(os_window_at(&h.app, &h.ctx, middle), "the shown window covers the canvas under it");
|
||||
(viewport, middle)
|
||||
}
|
||||
|
||||
/// A minimized palette window leaves the canvas under the place it had uncovered, and covers it again once restored.
|
||||
#[test]
|
||||
fn a_minimized_palette_window_does_not_cover_the_canvas() {
|
||||
let mut h = Harness::new();
|
||||
let (viewport, middle) = palette_over_canvas(&mut h);
|
||||
h.host.borrow_mut().windows.get_mut(&viewport).unwrap().minimized = true;
|
||||
h.frames(2);
|
||||
assert!(!os_window_at(&h.app, &h.ctx, middle), "a minimized window covers nothing");
|
||||
h.host.borrow_mut().windows.get_mut(&viewport).unwrap().minimized = false;
|
||||
h.frames(2);
|
||||
assert!(os_window_at(&h.app, &h.ctx, middle), "the restored window covers the canvas again");
|
||||
}
|
||||
|
||||
/// While a dialog shows, the palette windows are hidden and leave the canvas uncovered.
|
||||
#[test]
|
||||
fn a_hidden_palette_window_does_not_cover_the_canvas() {
|
||||
let mut h = Harness::new();
|
||||
let (_, middle) = palette_over_canvas(&mut h);
|
||||
crate::menus::invoke(&mut h.app, "view.rotate", json!({}));
|
||||
h.frames(2);
|
||||
assert!(h.app.any_dialog_open(), "the Rotate View dialog shows");
|
||||
assert!(!os_window_at(&h.app, &h.ctx, middle), "a palette hidden behind a dialog covers nothing");
|
||||
let ctx = h.app.ui_ctx.clone().expect("a frame ran");
|
||||
let id = h.app.dialogs().expect("a window").with(|host| host.open_dialogs().last().map(|d| d.id)).expect("a dialog is open");
|
||||
assert!(h.app.dialogs().expect("a window").with(|host| host.cancel_by_id(&ctx, id)), "the dialog took the answer");
|
||||
crate::dialogs::host::pump(&mut h.app, &ctx);
|
||||
h.frames(2);
|
||||
assert!(!h.app.any_dialog_open(), "the dialog closed");
|
||||
assert!(os_window_at(&h.app, &h.ctx, middle), "the palette covers the canvas again once the dialog closes");
|
||||
}
|
||||
Reference in new issue
Block a user