From e7c470878c24a43879fd09f2a89444f790e4facc Mon Sep 17 00:00:00 2001 From: Tristan Genevet Date: Fri, 10 Feb 2023 15:35:50 +0100 Subject: [PATCH] Fix for mouse keeping dragging when right click menu appears on mac. --- .../GraphElements/Views/MainPreviewView.cs | 7 ++++++- .../Editor/GraphUI/Manipulators/Draggable.cs | 20 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/com.unity.sg2/Editor/GraphUI/GraphElements/Views/MainPreviewView.cs b/com.unity.sg2/Editor/GraphUI/GraphElements/Views/MainPreviewView.cs index 3ebb906bcbc..a83e1ad8dbe 100644 --- a/com.unity.sg2/Editor/GraphUI/GraphElements/Views/MainPreviewView.cs +++ b/com.unity.sg2/Editor/GraphUI/GraphElements/Views/MainPreviewView.cs @@ -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); diff --git a/com.unity.sg2/Editor/GraphUI/Manipulators/Draggable.cs b/com.unity.sg2/Editor/GraphUI/Manipulators/Draggable.cs index f115e5a92ab..0f6b80cb4c1 100644 --- a/com.unity.sg2/Editor/GraphUI/Manipulators/Draggable.cs +++ b/com.unity.sg2/Editor/GraphUI/Manipulators/Draggable.cs @@ -26,22 +26,29 @@ public Draggable(Action handler, bool outputDeltaMovement = false) protected override void RegisterCallbacksOnTarget() { - target.RegisterCallback(new EventCallback(OnMouseDown), TrickleDownEnum.NoTrickleDown); - target.RegisterCallback(new EventCallback(OnMouseMove), TrickleDownEnum.NoTrickleDown); - target.RegisterCallback(new EventCallback(OnMouseUp), TrickleDownEnum.NoTrickleDown); + target.RegisterCallback(OnMouseDown); + target.RegisterCallback(OnMouseUp); + target.RegisterCallback(OnCaptureLost); } protected override void UnregisterCallbacksFromTarget() { - target.UnregisterCallback(new EventCallback(OnMouseDown), TrickleDownEnum.NoTrickleDown); - target.UnregisterCallback(new EventCallback(OnMouseMove), TrickleDownEnum.NoTrickleDown); - target.UnregisterCallback(new EventCallback(OnMouseUp), TrickleDownEnum.NoTrickleDown); + target.UnregisterCallback(OnCaptureLost); + target.UnregisterCallback(OnMouseDown); + target.UnregisterCallback(OnMouseUp); + } + + void OnCaptureLost(MouseCaptureOutEvent e) + { + m_Active = false; + target.UnregisterCallback(OnMouseMove); } void OnMouseDown(MouseDownEvent evt) { target.CaptureMouse(); m_Active = true; + target.RegisterCallback(OnMouseMove); evt.StopPropagation(); } @@ -63,6 +70,7 @@ void OnMouseMove(MouseMoveEvent evt) void OnMouseUp(MouseUpEvent evt) { m_Active = false; + target.UnregisterCallback(OnMouseMove); if (target.HasMouseCapture()) {