Skip to content
This repository has been archived by the owner on Apr 24, 2019. It is now read-only.

Restore normalized position on undock #1

Open
dustinlacewell opened this issue Apr 21, 2019 · 0 comments
Open

Restore normalized position on undock #1

dustinlacewell opened this issue Apr 21, 2019 · 0 comments

Comments

@dustinlacewell
Copy link
Collaborator

Current docking process:

  • User drags window to side

  • UIElementDocker remembers current window size and mouse offset from window position

  • UIElementDocker resizes window to docking size and adjusts position to the side

  • User clicks the window to undock

  • UIElementDocker restores the original window size and moves the window so that it has the original offset from the mouse

This is pretty good, but it's a little jarring since the window jumps to a different position relative to where on the window you clicked to undock it. A better undocking process looks like this:

  • User clicks the window to undock
  • UIElementDocker calculates the mouse's normalized position within the rect of the Dock-sized window. That means any point/mouse-position within the window becomes a Vector2 between 0,0 and 1,1.
  • UIElementDocker restores the original window size
  • UIElementDocker moves the window under the mouse such that the mouse occupies the same normalized position as when the docked window was initially clicked.

Unity has the following function to find the mouse's current local position within a given rectTransform:

RectTransformUtility.ScreenPointToLocalPointInRectangle(windowRectTransform, Input.mousePosition, GetComponentInParent<Canvas>().worldCamera, out mouseLocalPosition);

Unity also has the following to let us normalize that localPosition within the rectTransform:

Rect.PointToNormalized(windowRectTransform.rect, mouseLocalPosition);

So that gets us the normalized position on the initial click to undock, when the window is still dock-sized. After resizing, how do we move the window under the mouse, so the mouse occupies the same normalized position as before?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant