Fix SNaBorderedWindow drag detection and resize coordinate space bugs#21
Closed
Copilot wants to merge 3 commits into
Closed
Fix SNaBorderedWindow drag detection and resize coordinate space bugs#21Copilot wants to merge 3 commits into
Copilot wants to merge 3 commits into
Conversation
…validation Co-authored-by: SodiumZH <46860829+SodiumZH@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix SNaBorderedWindow dragging issues
Fix SNaBorderedWindow drag detection and resize coordinate space bugs
Feb 24, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
After dragging the window, the hit-detection area for the top border stays at the original position, and the resize delta accumulates incorrectly because mouse coordinates were being compared against inner-canvas layout values without accounting for
WindowPositionoffset.Changes
OnMouseButtonDown: convert click position to inner-canvas space (LocalPos - WindowPosition) before passing toGetRegionAtPosition, and store the same offset position asDragStartPositionfor resizingOnMouseMove(resize): apply the sameWindowPositionoffset to the current mouse position before computing the resize delta, keeping it consistent withDragStartPositionOnMouseMove(drag): upgrade invalidation fromLayouttoLayoutAndVolatilityso the widget's cached geometry stays in sync withWindowPositionafter each updateOriginal prompt
Fix SNaBorderedWindow Dragging Issues
Problem Description
The SNaBorderedWindow widget has two critical bugs with dragging functionality:
Issue 1: Mouse Movement Speed Mismatch
When dragging the top border, the mouse cursor and window move at different speeds, causing relative movement between the cursor and window. The window doesn't follow the mouse cursor properly.
Issue 2: Detection Area Doesn't Move with Window
After dragging the window once, the clickable detection area for the top border remains at the original position. Subsequent drag attempts only work if you click where the top border used to be before the first drag, not where it currently is.
Root Cause Analysis
Issue 1 - Mouse Speed Mismatch
The problem is in
OnMouseMoveduring dragging. The code currently uses screen space coordinates for the delta calculation, but the geometry being invalidated is in local space. When usingTAttribute<FVector2D>::CreateSP(this, &SNaBorderedWindow::GetWindowPosition)for the outer canvas slot position, the position is applied directly but the geometry transform isn't being accounted for properly.Current broken code:
The issue is that
WindowPositionis being set in screen space but being used as a local canvas position. The fix is to ensure we're working consistently in the same coordinate space.Issue 2 - Detection Area Not Moving
The problem is in
GetRegionAtPosition(). This function receivesLocalPositionwhich is already in the widget's local space (relative toMyGeometry), but then compares it against absolute pixel coordinates fromParams(BorderLeft, BorderTop, BodySize.X, etc.) as ifLocalPositionwere in the inner canvas's coordinate system.However, when the window is dragged and
WindowPositionchanges, theMyGeometrypassed to mouse events is still relative to the outer canvas's coordinate system, not the inner canvas. The function should account for the window's position offset.Current broken logic:
Solution
Fix for Issue 1: Consistent Coordinate Space Handling
The dragging logic needs to work in the parent's coordinate space consistently. Since we're using a canvas slot position attribute, we should:
WindowPositionas the offset within the parent containerWindowPositionFixed code:
Actually, the current dragging logic looks correct for screen space. The real issue might be that the
TAttributeisn't triggering layout updates properly. We need to verify the outer canvas slot is using the attribute correctly.Fix for Issue 2: Account for Window Position in Region Detection
The
GetRegionAtPositionfunction needs to work with the geometry that accounts for the window's current position. TheLocalPositionparameter is already in the widget's local coordinate system, which should include the window position offset if the geometry is correct.The issue is that we're comparing
LocalPosition(which is relative to the widget's current painted position) against the static layout coordinates. We need to not adjust for WindowPosition becauseMyGeometry.AbsoluteToLocal()already gives us coordinates relative to the current widget position.Wait - let me re-analyze. Looking at the code:
The problem is:
MyGeometryrepresents the current widget's geometry, which changes when WindowPosition changes (via the TAttribute). SoMyGeometry.AbsoluteToLocal()already accounts for the window's screen position. TheLocalPosis correct relative to the ...This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.