Revert auto-resize feature to put in a different branch.
This commit is contained in:
@@ -19,7 +19,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Description = desc,
|
Description = desc,
|
||||||
AlternativeTitles = altTitles,
|
AlternativeTitles = altTitles,
|
||||||
Flags = NodeFlags.AllGraphs,
|
Flags = NodeFlags.AllGraphs,
|
||||||
Size = new Float2(160, 20),
|
Size = new Float2(140, 20),
|
||||||
Elements = new[]
|
Elements = new[]
|
||||||
{
|
{
|
||||||
NodeElementArchetype.Factory.Input(0, "A", true, typeof(int), 0),
|
NodeElementArchetype.Factory.Input(0, "A", true, typeof(int), 0),
|
||||||
@@ -37,7 +37,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Description = desc,
|
Description = desc,
|
||||||
AlternativeTitles = altTitles,
|
AlternativeTitles = altTitles,
|
||||||
Flags = NodeFlags.AllGraphs,
|
Flags = NodeFlags.AllGraphs,
|
||||||
Size = new Float2(160, 40),
|
Size = new Float2(140, 40),
|
||||||
DefaultValues = new object[]
|
DefaultValues = new object[]
|
||||||
{
|
{
|
||||||
0,
|
0,
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ namespace FlaxEditor.Surface.Archetypes
|
|||||||
Title = "Material",
|
Title = "Material",
|
||||||
Description = "Main material node",
|
Description = "Main material node",
|
||||||
Flags = NodeFlags.MaterialGraph | NodeFlags.NoRemove | NodeFlags.NoSpawnViaGUI | NodeFlags.NoSpawnViaPaste | NodeFlags.NoCloseButton,
|
Flags = NodeFlags.MaterialGraph | NodeFlags.NoRemove | NodeFlags.NoSpawnViaGUI | NodeFlags.NoSpawnViaPaste | NodeFlags.NoCloseButton,
|
||||||
Size = new Float2(180, 300),
|
Size = new Float2(150, 300),
|
||||||
Elements = new[]
|
Elements = new[]
|
||||||
{
|
{
|
||||||
NodeElementArchetype.Factory.Input(0, "", true, typeof(void), 0),
|
NodeElementArchetype.Factory.Input(0, "", true, typeof(void), 0),
|
||||||
|
|||||||
@@ -177,45 +177,6 @@ namespace FlaxEditor.Surface
|
|||||||
Size = CalculateNodeSize(width, height);
|
Size = CalculateNodeSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Float2 GetBoxControlWidthHeight(Control control, Font boxLabelFont)
|
|
||||||
{
|
|
||||||
float boxWidth = 0;
|
|
||||||
float boxHeight = 0;
|
|
||||||
|
|
||||||
if (control is InputBox inputBox)
|
|
||||||
{
|
|
||||||
boxWidth = boxLabelFont.MeasureText(inputBox.Text).X + 24;
|
|
||||||
boxWidth += inputBox.GetValueEditorSize().X + 8;
|
|
||||||
boxHeight = inputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderSize + 20.0f;
|
|
||||||
Debug.Log($"InputBox {control.GetType().Name}: {boxWidth}, {boxHeight}");
|
|
||||||
}
|
|
||||||
else if (control is OutputBox outputBox)
|
|
||||||
{
|
|
||||||
boxWidth = boxLabelFont.MeasureText(outputBox.Text).X + 24;
|
|
||||||
boxHeight = outputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderSize + 20.0f;
|
|
||||||
Debug.Log($"OutputBox {control.GetType().Name}: {boxWidth}, {boxHeight}");
|
|
||||||
}
|
|
||||||
else if (control is Control defaultControl)
|
|
||||||
{
|
|
||||||
if (defaultControl.AnchorPreset == AnchorPresets.TopLeft)
|
|
||||||
{
|
|
||||||
boxWidth = defaultControl.Right + 4 - Constants.NodeMarginX;
|
|
||||||
boxHeight = defaultControl.Bottom + 4 - Constants.NodeMarginY - Constants.NodeHeaderSize;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
boxWidth = defaultControl.Width + 4;
|
|
||||||
boxHeight = defaultControl.Height + 4;
|
|
||||||
}
|
|
||||||
Debug.Log($"Control {control.GetType().Name}: {boxWidth}, {boxHeight}");
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
Debug.Log($"Control (filtered) {control.GetType().Name}: {boxWidth}, {boxHeight}");
|
|
||||||
}
|
|
||||||
|
|
||||||
return new Float2(boxWidth, boxHeight);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions.
|
/// Automatically resizes the node to match the title size and all the elements for best fit of the node dimensions.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -234,44 +195,39 @@ namespace FlaxEditor.Surface
|
|||||||
for (int i = 0; i < Children.Count; i++)
|
for (int i = 0; i < Children.Count; i++)
|
||||||
{
|
{
|
||||||
var child = Children[i];
|
var child = Children[i];
|
||||||
if (child is Panel panel)
|
|
||||||
{
|
|
||||||
panel.Visible = false;
|
|
||||||
}
|
|
||||||
if (!child.Visible)
|
if (!child.Visible)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Float2 boxSize = GetBoxControlWidthHeight(child, boxLabelFont);
|
|
||||||
if (child is InputBox inputBox)
|
if (child is InputBox inputBox)
|
||||||
{
|
{
|
||||||
leftWidth = Mathf.Max(leftWidth, boxSize.X);
|
var boxWidth = boxLabelFont.MeasureText(inputBox.Text).X + 20;
|
||||||
leftHeight = Mathf.Max(leftHeight, boxSize.Y);
|
if (inputBox.DefaultValueEditor != null)
|
||||||
|
boxWidth += inputBox.DefaultValueEditor.Width + 4;
|
||||||
|
leftWidth = Mathf.Max(leftWidth, boxWidth);
|
||||||
|
leftHeight = Mathf.Max(leftHeight, inputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderSize + 20.0f);
|
||||||
}
|
}
|
||||||
else if (child is OutputBox outputBox)
|
else if (child is OutputBox outputBox)
|
||||||
{
|
{
|
||||||
rightWidth = Mathf.Max(rightWidth, boxSize.X);
|
rightWidth = Mathf.Max(rightWidth, boxLabelFont.MeasureText(outputBox.Text).X + 20);
|
||||||
rightHeight = Mathf.Max(rightHeight, boxSize.Y);
|
rightHeight = Mathf.Max(rightHeight, outputBox.Archetype.Position.Y - Constants.NodeMarginY - Constants.NodeHeaderSize + 20.0f);
|
||||||
}
|
}
|
||||||
else
|
else if (child is Control control)
|
||||||
{
|
{
|
||||||
if (child.AnchorPreset == AnchorPresets.TopLeft)
|
if (control.AnchorPreset == AnchorPresets.TopLeft)
|
||||||
{
|
{
|
||||||
width = Mathf.Max(width, boxSize.X);
|
width = Mathf.Max(width, control.Right + 4 - Constants.NodeMarginX);
|
||||||
height = Mathf.Max(height, boxSize.Y);
|
height = Mathf.Max(height, control.Bottom + 4 - Constants.NodeMarginY - Constants.NodeHeaderSize);
|
||||||
}
|
}
|
||||||
else if (!_headerRect.Intersects(child.Bounds))
|
else if (!_headerRect.Intersects(control.Bounds))
|
||||||
{
|
{
|
||||||
width = Mathf.Max(width, boxSize.X);
|
width = Mathf.Max(width, control.Width + 4);
|
||||||
height = Mathf.Max(height, boxSize.Y);
|
height = Mathf.Max(height, control.Height + 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
width = Mathf.Max(width, leftWidth + rightWidth + 10);
|
width = Mathf.Max(width, leftWidth + rightWidth + 10);
|
||||||
width = Mathf.Max(width, titleLabelFont.MeasureText(Title).X + 30);
|
width = Mathf.Max(width, titleLabelFont.MeasureText(Title).X + 30);
|
||||||
height = Mathf.Max(height, Mathf.Max(leftHeight, rightHeight));
|
height = Mathf.Max(height, Mathf.Max(leftHeight, rightHeight));
|
||||||
Float2 roundedSize = VisjectSurface.RoundToGrid(new Float2(width, height), ceil: true);
|
Resize(width, height);
|
||||||
Resize(roundedSize.X, roundedSize.Y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -349,11 +305,8 @@ namespace FlaxEditor.Surface
|
|||||||
public void AddElement(ISurfaceNodeElement element)
|
public void AddElement(ISurfaceNodeElement element)
|
||||||
{
|
{
|
||||||
Elements.Add(element);
|
Elements.Add(element);
|
||||||
Debug.Log($"Element: {element.Archetype.Type}");
|
|
||||||
if (element is Control control)
|
if (element is Control control)
|
||||||
AddChild(control);
|
AddChild(control);
|
||||||
|
|
||||||
ResizeAuto(); // Resize when an element is added to avoid hardcoded sizes.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -935,7 +888,7 @@ namespace FlaxEditor.Surface
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool CanSelect(ref Float2 location)
|
public override bool CanSelect(ref Float2 location)
|
||||||
{
|
{
|
||||||
return _headerRect.MakeOffsetted(Location).Contains(ref location) || new Rectangle(Float2.Zero, Size).MakeOffsetted(Location).Contains(ref location);
|
return _headerRect.MakeOffsetted(Location).Contains(ref location);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
Reference in New Issue
Block a user