Skip to content

Commit

Permalink
Fix for mouse keeping dragging when right click menu appears on mac.
Browse files Browse the repository at this point in the history
  • Loading branch information
iTris666 committed Feb 10, 2023
1 parent 76d06e7 commit e7c4708
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ void OnGeometryChangedEvent(GeometryChangedEvent evt)
{
// When the overlay containing this view is hidden, our size becomes 0. No need to resize in this case,
// because the preview won't be shown and can't have a size of 0 regardless.
if (evt.newRect == Rect.zero) return;
if (evt.newRect == Rect.zero ||
float.IsInfinity(evt.newRect.width) ||
float.IsInfinity(evt.newRect.height)||
float.IsNaN(evt.newRect.width)||
float.IsNaN(evt.newRect.height) )
return;

var targetWidth = new Length(evt.newRect.width, LengthUnit.Pixel);
var targetHeight = new Length(evt.newRect.height, LengthUnit.Pixel);
Expand Down
20 changes: 14 additions & 6 deletions com.unity.sg2/Editor/GraphUI/Manipulators/Draggable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,29 @@ public Draggable(Action<Vector2> handler, bool outputDeltaMovement = false)

protected override void RegisterCallbacksOnTarget()
{
target.RegisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDownEnum.NoTrickleDown);
target.RegisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDownEnum.NoTrickleDown);
target.RegisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDownEnum.NoTrickleDown);
target.RegisterCallback<MouseDownEvent>(OnMouseDown);
target.RegisterCallback<MouseUpEvent>(OnMouseUp);
target.RegisterCallback<MouseCaptureOutEvent>(OnCaptureLost);
}

protected override void UnregisterCallbacksFromTarget()
{
target.UnregisterCallback(new EventCallback<MouseDownEvent>(OnMouseDown), TrickleDownEnum.NoTrickleDown);
target.UnregisterCallback(new EventCallback<MouseMoveEvent>(OnMouseMove), TrickleDownEnum.NoTrickleDown);
target.UnregisterCallback(new EventCallback<MouseUpEvent>(OnMouseUp), TrickleDownEnum.NoTrickleDown);
target.UnregisterCallback<MouseCaptureOutEvent>(OnCaptureLost);
target.UnregisterCallback<MouseDownEvent>(OnMouseDown);
target.UnregisterCallback<MouseUpEvent>(OnMouseUp);
}

void OnCaptureLost(MouseCaptureOutEvent e)
{
m_Active = false;
target.UnregisterCallback<MouseMoveEvent>(OnMouseMove);
}

void OnMouseDown(MouseDownEvent evt)
{
target.CaptureMouse();
m_Active = true;
target.RegisterCallback<MouseMoveEvent>(OnMouseMove);
evt.StopPropagation();
}

Expand All @@ -63,6 +70,7 @@ void OnMouseMove(MouseMoveEvent evt)
void OnMouseUp(MouseUpEvent evt)
{
m_Active = false;
target.UnregisterCallback<MouseMoveEvent>(OnMouseMove);

if (target.HasMouseCapture())
{
Expand Down

0 comments on commit e7c4708

Please sign in to comment.