mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-03 12:35:48 -05:00
Cascade newly opened floating panels from the Window menu
[skip ci]
(cherry picked from commit 9af51c41f6)
This commit is contained in:
1 parent
6efb0dda4b
commit
755763a046
2 files changed
+26
-3
No files matched your search
@@ -319,10 +319,14 @@ pub(crate) fn floating_window<'a>(layout: &'a Layout<String>, panel: &str) -> Op
|
||||
/// 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<egui::Pos2> {
|
||||
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)
|
||||
cascaded_float_rect(layout_of(&app.ui), &space, size).map(|rect| rect.min)
|
||||
}
|
||||
|
||||
fn cascaded_float_rect(layout: &Layout<String>, space: &FloatSpace<String>, size: egui::Vec2) -> Option<egui::Rect> {
|
||||
let last = layout.floating.last()?.rect;
|
||||
Some(craft::behavior::placement::cascade(last, size, space.area, space.inset))
|
||||
}
|
||||
|
||||
/// Is `panel` showing: in front of its group and not in a column collapsed to icons, or in the
|
||||
@@ -958,7 +962,8 @@ fn show_actions(ws: &Workspace<String>, space: &FloatSpace<String>, panel: &str,
|
||||
(Some(mate), _) => vec![Action::open_at(id, (*mate).to_owned(), DockPlacement::tab(None))],
|
||||
(None, true) => vec![Action::open(id, first_dock_panel(layout, panel))],
|
||||
(None, false) => {
|
||||
let rect = space.place(space.size_of(&DragUnit::Panel(id.clone()), None));
|
||||
let size = space.size_of(&DragUnit::Panel(id.clone()), None);
|
||||
let rect = cascaded_float_rect(layout, space, size).unwrap_or_else(|| space.place(size));
|
||||
vec![Action::float(id, rect)]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,6 +784,24 @@ fn independently_reopened_tab_is_not_restored_by_the_group_key() {
|
||||
assert!(showing(&h.app.ui, "layers"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_window_panels_cascade_and_reopened_panels_keep_their_positions() {
|
||||
let mut h = Harness::new();
|
||||
let show = |h: &mut Harness, panel: &str| {
|
||||
h.app.run("window.panel", json!({"panel": panel, "toggle": true})).unwrap();
|
||||
floating_window(&h.layout(), panel).unwrap().rect
|
||||
};
|
||||
let trace = show(&mut h, "imageTrace");
|
||||
let preview = show(&mut h, "separations");
|
||||
assert_ne!(trace.min, preview.min, "the second panel must leave the first title bar visible");
|
||||
|
||||
h.app.run("window.panel.float", json!({"panel": "imageTrace", "x": 180, "y": 100})).unwrap();
|
||||
let moved = floating_window(&h.layout(), "imageTrace").unwrap().rect;
|
||||
assert_ne!(moved.min, trace.min);
|
||||
h.app.run("window.panel.close", json!({"panel": "imageTrace"})).unwrap();
|
||||
assert_eq!(show(&mut h, "imageTrace"), moved, "reopening a placed panel restores its chosen position");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn showing_a_hidden_floating_group_returns_its_window_panels() {
|
||||
let mut h = Harness::new();
|
||||
|
||||
Reference in new issue
Block a user