Add surface nodes size snapping when using grid

#1456
This commit is contained in:
Wojtek Figat
2024-09-11 20:24:19 +02:00
parent 9bbeec5105
commit 12c9ae1490
3 changed files with 27 additions and 3 deletions

View File

@@ -1,7 +1,6 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
using FlaxEditor.GUI;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Input;
using FlaxEngine;
@@ -86,7 +85,10 @@ namespace FlaxEditor.Surface
// Read node data
Title = TitleValue;
Color = ColorValue;
Size = SizeValue;
var size = SizeValue;
if (Surface.GridSnappingEnabled)
size = Surface.SnapToGrid(size, true);
Size = size;
// Order
// Backwards compatibility - When opening with an older version send the old comments to the back
@@ -299,7 +301,10 @@ namespace FlaxEditor.Surface
if (_isResizing)
{
// Update size
Size = Float2.Max(location, new Float2(140.0f, _headerRect.Bottom));
var size = Float2.Max(location, new Float2(140.0f, _headerRect.Bottom));
if (Surface.GridSnappingEnabled)
size = Surface.SnapToGrid(size, true);
Size = size;
}
else
{

View File

@@ -131,6 +131,15 @@ namespace FlaxEditor.Surface
/// </summary>
public virtual void OnSurfaceLoaded(SurfaceNodeActions action)
{
// Snap bounds (with ceil) when using grid snapping
if (Surface.GridSnappingEnabled)
{
var bounds = Bounds;
bounds.Location = Surface.SnapToGrid(bounds.Location, false);
bounds.Size = Surface.SnapToGrid(bounds.Size, true);
Bounds = bounds;
}
UpdateRectangles();
}

View File

@@ -167,6 +167,15 @@ namespace FlaxEditor.Surface
if (Surface == null)
return;
// Snap bounds (with ceil) when using grid snapping
if (Surface.GridSnappingEnabled)
{
var size = Surface.SnapToGrid(new Float2(width, height), true);
width = size.X;
height = size.Y;
}
// Arrange output boxes on the right edge
for (int i = 0; i < Elements.Count; i++)
{
if (Elements[i] is OutputBox box)
@@ -175,6 +184,7 @@ namespace FlaxEditor.Surface
}
}
// Resize
Size = CalculateNodeSize(width, height);
}