-
Notifications
You must be signed in to change notification settings - Fork 7
fix: preserve Linux IDE dragging across renderer rebuilds #40
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| // vfmt off | ||
| @[has_globals] | ||
| module ui2 | ||
|
|
||
| $if (android || linux || ((macos || windows) && ui2_custom_rendering ?)) && !ui2_headless ? { | ||
| import gg | ||
|
|
||
| __global pointer_capture_events = []string{} | ||
|
|
||
| fn capture_pointer_event(id string) { | ||
| pointer_capture_events << id | ||
| } | ||
|
|
||
| fn reset_pointer_capture_test() { | ||
| g_touch = TouchState{} | ||
| g_hit_targets = []HitTarget{} | ||
| g_event_handler = capture_pointer_event | ||
| g_scroll_handler = ScrollFn(unsafe { nil }) | ||
| pointer_capture_events = []string{} | ||
| reset_scroll_frame() | ||
| close_dropdown() | ||
| } | ||
|
|
||
| fn test_drag_keeps_original_target_after_resize_handle_moves_and_is_covered() { | ||
| reset_pointer_capture_test() | ||
| // The IDE's 9px resize handles move outside the original press almost | ||
| // immediately. They identify themselves by action_id, not an element id. | ||
| g_hit_targets = [HitTarget{action_id: 'resize_widget', w: 9, h: 9, draggable: true}] | ||
| handle_touch_down(4, 4) | ||
| handle_touch_move(20, 20) | ||
| // Simulate the next frame rebuilding the hit targets at new coordinates. | ||
| g_hit_targets = [ | ||
| HitTarget{action_id: 'resize_widget', x: 20, y: 20, w: 9, h: 9, draggable: true}, | ||
| HitTarget{action_id: 'unrelated', w: 9, h: 9, slider: true}, | ||
| ] | ||
| handle_touch_move(50, 60) | ||
| handle_touch_up(70, 80) | ||
| assert pointer_capture_events == [ | ||
| pointer_event_id('down', 'resize_widget', 4, 4), | ||
| pointer_event_id('drag', 'resize_widget', 20, 20), | ||
| pointer_event_id('drag', 'resize_widget', 50, 60), | ||
| pointer_event_id('up', 'resize_widget', 70, 80), | ||
| ] | ||
| assert !g_touch.down | ||
| handle_touch_move(90, 90) | ||
| handle_touch_up(90, 90) | ||
| assert pointer_capture_events.len == 4 | ||
| } | ||
|
|
||
| fn test_capture_is_released_and_the_next_press_uses_the_new_target() { | ||
| reset_pointer_capture_test() | ||
| g_hit_targets = [HitTarget{action_id: 'first', w: 20, h: 20, clickable: true}] | ||
| handle_touch_down(5, 5) | ||
| g_hit_targets = [HitTarget{action_id: 'second', w: 20, h: 20, clickable: true}] | ||
| handle_touch_up(5, 5) | ||
| handle_touch_down(5, 5) | ||
| handle_touch_up(5, 5) | ||
| assert pointer_capture_events == [ | ||
| pointer_event_id('down', 'first', 5, 5), | ||
| pointer_event_id('up', 'first', 5, 5), | ||
| pointer_event_id('down', 'second', 5, 5), | ||
| pointer_event_id('up', 'second', 5, 5), | ||
| ] | ||
| } | ||
|
|
||
| fn test_capture_survives_a_frame_with_no_hit_targets_and_cancels_on_focus_loss() { | ||
| reset_pointer_capture_test() | ||
| g_hit_targets = [HitTarget{action_id: 'drag', w: 20, h: 20, draggable: true}] | ||
| handle_touch_down(5, 5) | ||
| g_hit_targets = []HitTarget{} | ||
| on_event(&gg.Event{typ: .mouse_move, mouse_x: 40, mouse_y: 50}, &GgApp{}) | ||
| on_event(&gg.Event{typ: .unfocused}, &GgApp{}) | ||
| assert pointer_capture_events == [ | ||
| pointer_event_id('down', 'drag', 5, 5), | ||
| pointer_event_id('drag', 'drag', 40, 50), | ||
| pointer_event_id('up', 'drag', 40, 50), | ||
| ] | ||
| assert !g_touch.down | ||
| on_event(&gg.Event{typ: .mouse_up, mouse_x: 40, mouse_y: 50}, &GgApp{}) | ||
| assert pointer_capture_events.len == 3 | ||
| } | ||
|
|
||
| fn test_cancelling_an_ordinary_button_does_not_activate_it() { | ||
| reset_pointer_capture_test() | ||
| g_hit_targets = [HitTarget{action_id: 'button', w: 20, h: 20}] | ||
| handle_touch_down(5, 5) | ||
| on_event(&gg.Event{typ: .touches_cancelled}, &GgApp{}) | ||
| handle_touch_up(5, 5) | ||
| assert pointer_capture_events.len == 0 | ||
| assert !g_touch.down | ||
| } | ||
|
|
||
| fn test_scrollbar_drag_takes_precedence_over_view_capture() { | ||
| reset_pointer_capture_test() | ||
| frame := rect(0, 0, 100, 100) | ||
| register_scroll_view('pane', frame, frame, 400, true, true, true) | ||
| g_hit_targets = [HitTarget{action_id: 'view', w: 100, h: 100, draggable: true}] | ||
| bar := scrollbar_geometry(frame, 400, 0, true) | ||
| handle_touch_down(bar.thumb.x + 1, bar.thumb.y + 1) | ||
| assert g_touch.scrollbar_drag | ||
| handle_touch_move(bar.thumb.x + 1, 60) | ||
| handle_touch_up(bar.thumb.x + 1, 60) | ||
| assert pointer_capture_events.len == 0 | ||
| } | ||
| } |
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.
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.
When a captured custom view loses focus, is suspended, or receives
touches_cancelled, this emits the samepointer:upevent as a successful gesture. Consumers cannot distinguish cancellation and may commit user actions:examples/circle_drawer/main.vadds or selects a circle on every canvaspointer:up, andide/main.vplaces an armed component when the form surface receives one. Thus merely switching windows or an OS touch cancellation after pressing these views can activate them; cancellation needs a distinct abort path rather than a normal release event.Useful? React with 👍 / 👎.