Merge pull request #10617 from dotCooCoo/fix/float-tools-beside-rail

Tools: a strip floated before the canvas is laid out opens beside the rail
This commit is contained in:
.CooCoo authored and GitHub committed 2026-12-02 15:12:26 -08:00
commit 1bb9699b5c
3 files changed
+55 -3

No files matched your search

+22
View File
@@ -301,6 +301,28 @@ pub(crate) fn column_of<'a>(layout: &'a Layout<String>, panel: &str) -> Option<(
Some((edge, column))
}
/// Where the dock last drew the docked column holding `panel`; none until the dock has drawn it, and while `panel`
/// floats or is closed.
pub(crate) fn column_rect(app: &VectorcraftApp, panel: &str) -> Option<egui::Rect> {
let (Some(_), column) = column_of(layout_of(&app.ui), panel)? else { return None };
app.dock_rt.columns.iter().find(|(first, _)| column.panels().any(|p| p == first)).map(|(_, rect)| *rect)
}
/// The top left a new floating window of `panel` takes beside the docked column holding `beside`: level with the
/// column's top, the cascade inset away from it on the side toward the middle of the float space. None until the dock
/// has drawn that column.
pub(crate) fn float_origin_beside(app: &VectorcraftApp, panel: &str, beside: &str) -> Option<egui::Pos2> {
let column = column_rect(app, beside)?;
let space = command_space(app);
let x = if column.center().x <= space.area.center().x {
column.right() + space.inset
} else {
let width = space.size_of(&DragUnit::Panel(panel.to_owned()), None).x;
column.left() - space.inset - width
};
Some(egui::pos2(x, column.top()))
}
/// Is the dock's outer column of panels (Properties · Layers · Libraries) collapsed to icons?
pub(crate) fn dock_collapsed(ui: &UiState) -> bool {
dock_columns(layout_of(ui)).first().is_some_and(|c| c.iconic)
+9 -3
View File
@@ -294,11 +294,17 @@ pub(crate) fn is_floating(app: &VectorcraftApp, toolbar: Option<&str>, key: &str
strips(app, toolbar).iter().any(|g| g.first() == Some(&key))
}
/// Float the group `first` of `owner` as a strip at `at` (none: the canvas's corner).
/// Float the group `first` of `owner` as a strip at `at`. Without `at` the strip opens at the canvas's corner, or,
/// before a view has been laid out, beside `owner`'s docked rail, else beside the Tools panel's.
fn place_strip(app: &mut VectorcraftApp, owner: &Owner, first: &str, at: Option<Pos2>) -> Result<(), String> {
let at = at.unwrap_or_else(|| app.canvas_view().map_or(Pos2::ZERO, |v| v.rect.min));
let id = strip_id(owner, first);
let at = at
.or_else(|| app.canvas_view().map(|v| v.rect.min))
.or_else(|| crate::panel_docking::float_origin_beside(app, &id, &owner.panel()))
.or_else(|| crate::panel_docking::float_origin_beside(app, &id, TOOLS))
.unwrap_or(Pos2::ZERO);
// A width of 0 leaves the window's width to the panel's grid.
crate::panel_docking::place_floating(app, &strip_id(owner, first), at, 0.0)
crate::panel_docking::place_floating(app, &id, at, 0.0)
}
/// Float the toolbar group (of the current layout) holding `tool` as a strip of tool buttons, put
+24
View File
@@ -483,6 +483,30 @@ fn window_float_tools_floats_and_puts_back_a_group() {
assert!(strip_rect(&app, "rectangle").is_none() && !is_floating(&app, None, "pen"));
}
/// `window.floatTools` run before a view has been laid out (right after a document opens, or with none open) floats the
/// strip beside the docked Tools rail, not over it, and the strip stays clear of the rail once the frames are drawn.
#[test]
fn a_strip_floated_before_a_view_is_laid_out_opens_beside_the_tools_rail() {
for (case, document) in [("document just opened", true), ("no document", false)] {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
let ctx = crate::testing::ui_context();
settled(&mut app, &ctx, 0.0, 900.0);
if document {
app.run("file.new", json!({"width": 300, "height": 300})).unwrap();
}
assert!(app.canvas_view().is_none(), "{case}: no view has been laid out yet");
let rail = crate::panel_docking::column_rect(&app, TOOLS).unwrap_or_else(|| panic!("{case}: the Tools rail is docked"));
app.run("window.floatTools", json!({"tool": "pen"})).unwrap();
let strip = strip_rect(&app, "pen").unwrap_or_else(|| panic!("{case}: the Pen strip floats"));
assert!(strip.left() >= rail.right(), "{case}: the strip {strip:?} opens right of the rail {rail:?}");
assert!((strip.top() - rail.top()).abs() <= f32::EPSILON, "{case}: the strip {strip:?} is level with the rail {rail:?}");
settled(&mut app, &ctx, 1.0, 900.0);
let rail = crate::panel_docking::column_rect(&app, TOOLS).unwrap_or_else(|| panic!("{case}: the Tools rail stays docked"));
let strip = strip_rect(&app, "pen").unwrap_or_else(|| panic!("{case}: the Pen strip still floats"));
assert!(!strip.intersects(rail), "{case}: the strip {strip:?} is clear of the rail {rail:?}");
}
}
/// A floated group is a panel of the workspace's layout: a saved workspace brings it back, the built-in ones have none.
#[test]
fn workspaces_keep_floating_flyouts_and_reset_puts_them_back() {