mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge #15954 into the merge queue batch
Disable edge resizing on the floating Tools palette
This commit is contained in:
commit
ba2345fbc1
2 files changed
+65
-2
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<PhotocraftApp>> {
|
||||
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<PhotocraftApp>>, rect: Rect) {
|
||||
h.run_steps(4);
|
||||
}
|
||||
|
||||
fn drag(h: &mut Harness<'static, Box<PhotocraftApp>>, 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<PhotocraftApp>>) -> (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:?}");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user