Delete Visject surface node when press started over the close button

This commit is contained in:
Ari Vuollet
2026-08-18 02:42:02 +03:00
parent b81e52481e
commit 7e624da0a1
+16 -10
View File
@@ -76,6 +76,11 @@ namespace FlaxEditor.Surface
/// The footer rectangle (local space).
/// </summary>
protected Rectangle _footerRect;
/// <summary>
/// The last mouse down position.
/// </summary>
protected Float2 _mouseDownMousePosition;
/// <summary>
/// The node archetype.
@@ -163,8 +168,6 @@ namespace FlaxEditor.Surface
/// </summary>
protected virtual Color ArchetypeColor => GroupArchetype.Color;
private Float2 mouseDownMousePosition;
/// <summary>
/// Calculates the size of the node including header, footer, and margins.
/// </summary>
@@ -1166,10 +1169,9 @@ namespace FlaxEditor.Surface
if (base.OnMouseDown(location, button))
return true;
_mouseDownMousePosition = location;
if (button == MouseButton.Left && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 && _closeButtonRect.Contains(ref location))
return true;
if (button == MouseButton.Right)
mouseDownMousePosition = Input.Mouse.Position;
return false;
}
@@ -1180,18 +1182,22 @@ namespace FlaxEditor.Surface
if (base.OnMouseUp(location, button))
return true;
// Close/ delete
bool canDelete = !Surface.IsConnecting && !Surface.WasSelecting && !Surface.WasMovingSelection;
if (button == MouseButton.Left && canDelete && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 && _closeButtonRect.Contains(ref location))
if (button == MouseButton.Left)
{
Surface.Delete(this);
return true;
// Close/delete
bool canDelete = !Surface.IsConnecting && !Surface.WasSelecting && !Surface.WasMovingSelection;
if (canDelete && (Archetype.Flags & NodeFlags.NoCloseButton) == 0 &&
_closeButtonRect.Contains(ref location) && _closeButtonRect.Contains(ref _mouseDownMousePosition))
{
Surface.Delete(this);
return true;
}
}
// Secondary Context Menu
if (button == MouseButton.Right)
{
float distance = Float2.Distance(mouseDownMousePosition, Input.Mouse.Position);
float distance = Float2.Distance(_mouseDownMousePosition, location);
if (distance > 2.5f)
return true;