Repository navigation
PAN pans in realtime by dragging; -PAN asks for two points #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fc67a5c
PAN pans in realtime by dragging; -PAN asks for two points
mattlafy a9294b5
Merge remote-tracking branch 'upstream/main' into pr/realtime-pan
mattlafy b2ebb39
Place no point on the release of a realtime PAN or ZOOM drag
mattlafy 53ac71c
Clear the navigation drag when its button is released after Escape st…
mattlafy b17523e
Merge remote-tracking branch 'upstream/main' into pr/realtime-pan
mattlafy a5c8b1a
Format the Escape-drag test
mattlafy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| //! A drag that pans in realtime places no point when it is let go, even after Enter ended the | ||
| //! transparent PAN mid-drag and handed the prompt back to the drawing command; a pan drag that | ||
| //! Escape stopped leaves the next drag free to place a point. | ||
|
|
||
| use cadcraft_engine::Session; | ||
| use cadcraft_engine::doc::{Drawing, EntityKind, Space}; | ||
| use cadcraft_engine::geom::Vec2; | ||
| use cadcraft_ui_egui::{CadApp, Services}; | ||
| use egui::{Event, Key, Modifiers, PointerButton, Pos2, vec2}; | ||
| use egui_kittest::Harness; | ||
| use serde_json::json; | ||
|
|
||
| fn harness() -> Harness<'static, CadApp> { | ||
| let mut session = Session::empty(); | ||
| session.open_drawing(Drawing::new_imperial(), "Realtime release", None); | ||
| session.execute("view.set", &json!({"center":[50,50],"height":100})).unwrap(); | ||
| session.settings.osmode = 0; | ||
| session.settings.snapmode = false; | ||
| session.settings.orthomode = false; | ||
| let mut app = CadApp::new(session, Services::default()); | ||
| app.canvas.zoom_pending = false; | ||
| let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_ui_state( | ||
| |ui, app: &mut CadApp| { | ||
| app.logic(ui.ctx()); | ||
| app.ui(ui); | ||
| }, | ||
| app, | ||
| ); | ||
| h.run_steps(5); | ||
| h | ||
| } | ||
|
|
||
| fn screen(h: &Harness<'_, CadApp>, p: Vec2) -> Pos2 { | ||
| h.state().canvas.xf.unwrap().to_screen(p) | ||
| } | ||
|
|
||
| fn button(h: &mut Harness<'_, CadApp>, pos: Pos2, pressed: bool) { | ||
| h.event(Event::PointerMoved(pos)); | ||
| h.event(Event::PointerButton { pos, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); | ||
| h.run_steps(1); | ||
| } | ||
|
|
||
| fn lines(h: &Harness<'_, CadApp>) -> usize { | ||
| let st = h.state().session.state().unwrap(); | ||
| st.doc.space(&Space::Model).unwrap().iter().filter(|e| matches!(e.kind, EntityKind::Line(_))).count() | ||
| } | ||
|
|
||
| #[test] | ||
| fn enter_mid_drag_ends_pan_and_the_release_places_no_point() { | ||
| let mut h = harness(); | ||
| h.state_mut().start("line"); | ||
| h.run_steps(2); | ||
| let first = screen(&h, Vec2::new(10.0, 10.0)); | ||
| button(&mut h, first, true); | ||
| button(&mut h, first, false); | ||
| h.run_steps(2); | ||
| h.state_mut().session.cmdline("'PAN").unwrap(); | ||
| h.run_steps(1); | ||
| assert!(h.state().session.realtime_pan_active()); | ||
| let (a, b) = (screen(&h, Vec2::new(40.0, 40.0)), screen(&h, Vec2::new(60.0, 30.0))); | ||
| button(&mut h, a, true); | ||
| for i in 1..=4 { | ||
| h.event(Event::PointerMoved(a + (b - a) * (i as f32 / 4.0))); | ||
| h.run_steps(1); | ||
| } | ||
| h.state_mut().session.cmdline("").unwrap(); | ||
| h.run_steps(1); | ||
| assert_eq!(h.state().session.running.as_ref().map(|r| r.id.as_str()), Some("line")); | ||
| button(&mut h, b, false); | ||
| h.run_steps(2); | ||
| assert_eq!(lines(&h), 0, "the release of the pan drag placed a point"); | ||
| assert_eq!(h.state().session.running.as_ref().map(|r| r.id.as_str()), Some("line")); | ||
| // A click after it still places the next point. | ||
| button(&mut h, b, true); | ||
| button(&mut h, b, false); | ||
| h.run_steps(2); | ||
| assert_eq!(lines(&h), 1); | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_pan_drag_stopped_by_escape_leaves_the_next_drag_placing_a_point() { | ||
| let mut h = harness(); | ||
| h.state_mut().session.cmdline("PAN").unwrap(); | ||
| h.run_steps(1); | ||
| assert!(h.state().session.realtime_pan_active()); | ||
| let (a, b) = (screen(&h, Vec2::new(40.0, 40.0)), screen(&h, Vec2::new(60.0, 30.0))); | ||
| button(&mut h, a, true); | ||
| for i in 1..=4 { | ||
| h.event(Event::PointerMoved(a + (b - a) * (i as f32 / 4.0))); | ||
| h.run_steps(1); | ||
| } | ||
| for pressed in [true, false] { | ||
| h.event(Event::Key { key: Key::Escape, physical_key: None, pressed, repeat: false, modifiers: Modifiers::NONE }); | ||
| h.run_steps(1); | ||
| } | ||
| button(&mut h, b, false); | ||
| h.run_steps(2); | ||
| assert!(!h.state().session.realtime_pan_active()); | ||
| h.state_mut().start("line"); | ||
| h.run_steps(2); | ||
| // Screen points near the middle of the canvas, wherever the pan left the drawing. | ||
| let first = Pos2::new(700.0, 450.0); | ||
| button(&mut h, first, true); | ||
| button(&mut h, first, false); | ||
| h.run_steps(2); | ||
| // The second point is a press, a drag and a release. | ||
| let (c, d) = (Pos2::new(760.0, 420.0), Pos2::new(820.0, 400.0)); | ||
| button(&mut h, c, true); | ||
| for i in 1..=4 { | ||
| h.event(Event::PointerMoved(c + (d - c) * (i as f32 / 4.0))); | ||
| h.run_steps(1); | ||
| } | ||
| button(&mut h, d, false); | ||
| h.run_steps(2); | ||
| assert_eq!(lines(&h), 1, "the drag after an Escape-stopped pan drag placed no point"); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Limit realtime PAN drags to the active tile.
When model tiles are visible,
respcoversfull, butrectidentifies only the active tile. A primary drag that starts on an inactive tile therefore moves the active tile's view. Check that the drag started insiderect; continue the drag if the pointer later leavesrect. (raw.githubusercontent.com)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A press on another tile makes that tile current before the drag begins (
navigate_canvascallsclick_tile, which activates a tile in the middle of a command too), so the drag pans the tile it started in.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mattlafy The supplied code shows a different event sequence.
pressed_primarycomes fromi.pointer.primary_clicked(), notbutton_pressed(Primary). Theclick_tilebranch also runs after the realtime PAN handler.click_tilecan activate a tile during a command, but that does not establish activation before the drag begins. Please check a left-button drag that starts in an inactive tile without a preceding click. If another path activates the tile on button press, please point me to it.You are interacting with an AI system.