From b1a33973e0545d1e9ab61a66ebdb31d1a3b18a18 Mon Sep 17 00:00:00 2001 From: KotovGGG <162052215+KotovGGG@users.noreply.github.com> Date: Sun, 29 Nov 2026 16:40:39 +0300 Subject: [PATCH] fix(ui): disable edge resizing on the floating Tools palette --- crates/ui-egui/src/panels/panel_docking.rs | 2 +- .../src/panels/toolbar_docking_tests.rs | 65 ++++++++++++++++++- 2 files changed, 65 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panels/panel_docking.rs b/crates/ui-egui/src/panels/panel_docking.rs index b2ebeac752..aac0b61b7e 100644 --- a/crates/ui-egui/src/panels/panel_docking.rs +++ b/crates/ui-egui/src/panels/panel_docking.rs @@ -210,7 +210,7 @@ fn spec(specs: &DockSpecs, panel: &str) -> PanelSpec { if panel == TOOLBAR { // The toolbar floats in the main window, as production's: its tooltips, tool flyouts and Edit Toolbar drawer // open beside the one-button-wide rail, which its own OS window would clip. - spec = spec.grid(DockGrid::rail(specs.toolbar_cells)).allow_native(false); + spec = spec.grid(DockGrid::rail(specs.toolbar_cells)).allow_native(false).allow_float_resize(false); } spec } diff --git a/crates/ui-egui/src/panels/toolbar_docking_tests.rs b/crates/ui-egui/src/panels/toolbar_docking_tests.rs index e0c0823b71..09f58dd2c8 100644 --- a/crates/ui-egui/src/panels/toolbar_docking_tests.rs +++ b/crates/ui-egui/src/panels/toolbar_docking_tests.rs @@ -8,7 +8,7 @@ use craft::behavior::DockSide; use craft::behavior::dock::{Action, DockPlacement, PanelPlace, Permissions, Target}; use egui::{PointerButton, Pos2, Rect}; use egui_kittest::Harness; -use egui_kittest::kittest::Queryable; +use egui_kittest::kittest::{NodeT, Queryable}; use serde_json::json; const SIZE: egui::Vec2 = egui::vec2(1200.0, 800.0); @@ -18,6 +18,7 @@ fn harness() -> Harness<'static, Box> { let mut h = Harness::builder().with_size(SIZE).with_max_steps(64).build_eframe(|cc| { PhotocraftApp::setup_context(&cc.egui_ctx, crate::theme::AppTheme::pro()); let mut app = PhotocraftApp::with_context(cc.egui_ctx.clone(), photocraft_engine::Session::new(), crate::Services::default()); + app.run("prefs.set", json!({"path": "interface.language", "value": "en"})).expect("set the fixture's label language"); app.run("file.new", json!({"width": 64, "height": 64})).expect("new document"); app }); @@ -49,6 +50,20 @@ fn right_click(h: &mut Harness<'static, Box>, rect: Rect) { h.run_steps(4); } +fn drag(h: &mut Harness<'static, Box>, from: Pos2, to: Pos2) { + let button = |pos, pressed| egui::Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + h.event(egui::Event::PointerMoved(from)); + h.run_steps(1); + h.event(button(from, true)); + h.run_steps(1); + for step in 1..=4 { + h.event(egui::Event::PointerMoved(from.lerp(to, step as f32 / 4.0))); + h.run_steps(2); + } + h.event(button(to, false)); + h.run_steps(4); +} + /// The Lasso slot's flyout rows, opened from the toolbar: the slot's button and the Polygonal Lasso row. fn lasso_flyout(h: &mut Harness<'static, Box>) -> (Rect, Rect) { let button = rect_of(h, "Lasso Tool").expect("the Lasso slot is drawn"); @@ -126,3 +141,51 @@ fn a_saved_toolbar_below_the_canvas_loads_in_a_dock_column() { assert!(matches!(toolbar_place(&app), Some(PanelPlace::Dock { .. })), "{:?}", toolbar_place(&app)); assert!(app.ui.docking.layout().contains(&CANVAS.to_owned())); } + +#[test] +fn the_floating_toolbar_switches_columns_by_its_header_button() { + let mut h = harness(); + h.state_mut().run("window.panel.float", json!({"panel": TOOLBAR, "column": true, "x": 350, "y": 90})).expect("the Tools palette floats"); + h.run_steps(4); + + let placement = |app: &PhotocraftApp| { + let window = app.ui.docking.layout().floating.iter().find(|window| window.panels().any(|panel| panel == TOOLBAR)).expect("floating Tools"); + (window.rect, window.column.steps) + }; + assert_eq!(placement(h.state()).1, Some(1)); + h.query_by_label("Show in two columns").expect("the floating palette's column button").click(); + h.run_steps(4); + let (rect, steps) = placement(h.state()); + assert_eq!(steps, Some(2)); + + let grip = Pos2::new(rect.right() - 1.0, rect.top() + 50.0); + drag(&mut h, grip, grip - egui::vec2(rect.width() * 0.6, 0.0)); + assert_eq!(placement(h.state()).1, Some(2), "dragging an edge leaves Tools at two columns"); + + h.query_by_label("Show in one column").expect("the floating palette's column button").click(); + h.run_steps(4); + assert_eq!(placement(h.state()).1, Some(1)); +} + +#[test] +fn dropping_a_panel_just_above_or_below_the_document_tabs_leaves_it_floating() { + use craft::behavior::dock::PanelPlace; + use egui::accesskit::Role; + + for above in [true, false] { + let mut h = harness(); + let tab_named = |name: &str| { + h.query_all_by_role(Role::Tab) + .find(|tab| tab.accesskit_node().label().is_some_and(|label| label.contains(name))) + .expect("the tab is visible") + .rect() + }; + let from = tab_named("Layers").center(); + let document = tab_named("Untitled"); + let to = Pos2::new(document.center().x, if above { document.top() - 1.0 } else { document.bottom() + 1.0 }); + drag(&mut h, from, to); + + let place = h.state().ui.docking.layout().place(&"layers".to_owned()); + assert!(matches!(place, Some(PanelPlace::Floating { .. })), "drop at {to:?}, above the tabs: {above}, place: {place:?}"); + } +}