Skip to content
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

Fix for right click menu in preview on Mac. #7814

Open
wants to merge 1 commit into
base: sg2/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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