Fixes for regression in tree UI layout after recent refactor
This commit is contained in:
@@ -333,30 +333,6 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates the tree size.
|
|
||||||
/// </summary>
|
|
||||||
public void UpdateSize()
|
|
||||||
{
|
|
||||||
if (!_autoSize)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Use max of parent clint area width and root node width
|
|
||||||
float width = 0;
|
|
||||||
if (HasParent)
|
|
||||||
width = Parent.GetClientArea().Width;
|
|
||||||
var rightBottom = Vector2.Zero;
|
|
||||||
for (int i = 0; i < _children.Count; i++)
|
|
||||||
{
|
|
||||||
if (_children[i] is TreeNode node && node.Visible)
|
|
||||||
{
|
|
||||||
width = Mathf.Max(width, node.MinimumWidth);
|
|
||||||
rightBottom = Vector2.Max(rightBottom, node.BottomRight);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Size = new Vector2(width + _margin.Width, rightBottom.Y + _margin.Bottom);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Update(float deltaTime)
|
public override void Update(float deltaTime)
|
||||||
{
|
{
|
||||||
@@ -521,25 +497,43 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
base.OnGotFocus();
|
base.OnGotFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void OnChildResized(Control control)
|
|
||||||
{
|
|
||||||
UpdateSize();
|
|
||||||
|
|
||||||
base.OnChildResized(control);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnParentResized()
|
public override void OnParentResized()
|
||||||
{
|
{
|
||||||
UpdateSize();
|
PerformLayout();
|
||||||
|
|
||||||
base.OnParentResized();
|
base.OnParentResized();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void PerformLayoutBeforeChildren()
|
||||||
|
{
|
||||||
|
if (_autoSize)
|
||||||
|
{
|
||||||
|
// Use max of parent clint area width and root node width
|
||||||
|
var parent = Parent;
|
||||||
|
var width = parent != null ? Mathf.Max(parent.GetClientArea().Width, 0) : 0.0f;
|
||||||
|
for (int i = 0; i < _children.Count; i++)
|
||||||
|
{
|
||||||
|
if (_children[i] is TreeNode node && node.Visible)
|
||||||
|
width = Mathf.Max(width, node.MinimumWidth);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < _children.Count; i++)
|
||||||
|
{
|
||||||
|
if (_children[i] is TreeNode node && node.Visible)
|
||||||
|
node.Width = width;
|
||||||
|
}
|
||||||
|
Width = width + _margin.Width;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.PerformLayoutBeforeChildren();
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void PerformLayoutAfterChildren()
|
protected override void PerformLayoutAfterChildren()
|
||||||
{
|
{
|
||||||
|
base.PerformLayoutAfterChildren();
|
||||||
|
|
||||||
// Arrange children
|
// Arrange children
|
||||||
float y = _margin.Top;
|
float y = _margin.Top;
|
||||||
for (int i = 0; i < _children.Count; i++)
|
for (int i = 0; i < _children.Count; i++)
|
||||||
@@ -551,7 +545,17 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSize();
|
if (_autoSize)
|
||||||
|
{
|
||||||
|
// Update height based on the nodes
|
||||||
|
var bottom = 0.0f;
|
||||||
|
for (int i = 0; i < _children.Count; i++)
|
||||||
|
{
|
||||||
|
if (_children[i] is TreeNode node && node.Visible)
|
||||||
|
bottom = Mathf.Max(bottom, node.Bottom);
|
||||||
|
}
|
||||||
|
Height = bottom + _margin.Bottom;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -325,23 +325,18 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
ExpandAllParents(noAnimation);
|
ExpandAllParents(noAnimation);
|
||||||
|
|
||||||
// Change state
|
// Change state
|
||||||
|
if (_opened && _animationProgress >= 1.0f)
|
||||||
|
return;
|
||||||
bool prevState = _opened;
|
bool prevState = _opened;
|
||||||
_opened = true;
|
_opened = true;
|
||||||
if (prevState != _opened)
|
|
||||||
_animationProgress = 1.0f - _animationProgress;
|
|
||||||
|
|
||||||
if (noAnimation)
|
if (noAnimation)
|
||||||
{
|
|
||||||
// Speed up an animation
|
|
||||||
_animationProgress = 1.0f;
|
_animationProgress = 1.0f;
|
||||||
}
|
else if (prevState != _opened)
|
||||||
|
_animationProgress = 1.0f - _animationProgress;
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
OnExpandedChanged();
|
OnExpandedChanged();
|
||||||
if (HasParent)
|
OnExpandAnimationChanged();
|
||||||
Parent.PerformLayout();
|
|
||||||
else
|
|
||||||
PerformLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -351,23 +346,18 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
public void Collapse(bool noAnimation = false)
|
public void Collapse(bool noAnimation = false)
|
||||||
{
|
{
|
||||||
// Change state
|
// Change state
|
||||||
|
if (!_opened && _animationProgress >= 1.0f)
|
||||||
|
return;
|
||||||
bool prevState = _opened;
|
bool prevState = _opened;
|
||||||
_opened = false;
|
_opened = false;
|
||||||
if (prevState != _opened)
|
|
||||||
_animationProgress = 1.0f - _animationProgress;
|
|
||||||
|
|
||||||
if (noAnimation)
|
if (noAnimation)
|
||||||
{
|
|
||||||
// Speed up an animation
|
|
||||||
_animationProgress = 1.0f;
|
_animationProgress = 1.0f;
|
||||||
}
|
else if (prevState != _opened)
|
||||||
|
_animationProgress = 1.0f - _animationProgress;
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
OnExpandedChanged();
|
OnExpandedChanged();
|
||||||
if (HasParent)
|
OnExpandAnimationChanged();
|
||||||
Parent.PerformLayout();
|
|
||||||
else
|
|
||||||
PerformLayout();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -433,7 +423,7 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
if (_animationProgress < 1.0f)
|
if (_animationProgress < 1.0f)
|
||||||
{
|
{
|
||||||
_animationProgress = 1.0f;
|
_animationProgress = 1.0f;
|
||||||
PerformLayout();
|
OnExpandAnimationChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -521,6 +511,19 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Called when expand/collapse animation progress changes.
|
||||||
|
/// </summary>
|
||||||
|
protected virtual void OnExpandAnimationChanged()
|
||||||
|
{
|
||||||
|
if (ParentTree != null)
|
||||||
|
ParentTree.PerformLayout();
|
||||||
|
else if (Parent != null)
|
||||||
|
Parent.PerformLayout();
|
||||||
|
else
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests the header hit.
|
/// Tests the header hit.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -595,7 +598,7 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Arrange controls
|
// Arrange controls
|
||||||
PerformLayout();
|
OnExpandAnimationChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for long press
|
// Check for long press
|
||||||
@@ -894,7 +897,6 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
ParentTree.UpdateSize();
|
|
||||||
|
|
||||||
base.OnChildResized(control);
|
base.OnChildResized(control);
|
||||||
}
|
}
|
||||||
@@ -1022,9 +1024,14 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
if (!wasLocked)
|
if (!wasLocked)
|
||||||
LockChildrenRecursive();
|
LockChildrenRecursive();
|
||||||
|
|
||||||
|
// Auto-size tree nodes to match the parent size
|
||||||
|
var parent = Parent;
|
||||||
|
var width = parent is TreeNode ? parent.Width : Width;
|
||||||
|
|
||||||
// Optimize layout logic if node is collapsed
|
// Optimize layout logic if node is collapsed
|
||||||
if (_opened || _animationProgress < 1.0f)
|
if (_opened || _animationProgress < 1.0f)
|
||||||
{
|
{
|
||||||
|
Width = width;
|
||||||
PerformLayoutBeforeChildren();
|
PerformLayoutBeforeChildren();
|
||||||
for (int i = 0; i < _children.Count; i++)
|
for (int i = 0; i < _children.Count; i++)
|
||||||
_children[i].PerformLayout(true);
|
_children[i].PerformLayout(true);
|
||||||
@@ -1035,7 +1042,7 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
// TODO: perform layout for any non-TreeNode controls
|
// TODO: perform layout for any non-TreeNode controls
|
||||||
_cachedHeight = _headerHeight;
|
_cachedHeight = _headerHeight;
|
||||||
_cachedTextColor = CacheTextColor();
|
_cachedTextColor = CacheTextColor();
|
||||||
Size = new Vector2(Parent?.Width ?? Width, _headerHeight);
|
Size = new Vector2(width, _headerHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wasLocked)
|
if (!wasLocked)
|
||||||
@@ -1070,8 +1077,6 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
if (_opened || _animationProgress < 1.0f)
|
if (_opened || _animationProgress < 1.0f)
|
||||||
{
|
{
|
||||||
y -= _cachedHeight * (_opened ? 1.0f - _animationProgress : _animationProgress);
|
y -= _cachedHeight * (_opened ? 1.0f - _animationProgress : _animationProgress);
|
||||||
|
|
||||||
// Arrange children
|
|
||||||
for (int i = 0; i < _children.Count; i++)
|
for (int i = 0; i < _children.Count; i++)
|
||||||
{
|
{
|
||||||
if (_children[i] is TreeNode node && node.Visible)
|
if (_children[i] is TreeNode node && node.Visible)
|
||||||
@@ -1085,21 +1090,15 @@ namespace FlaxEditor.GUI.Tree
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cache data
|
|
||||||
_cachedHeight = height;
|
_cachedHeight = height;
|
||||||
_cachedTextColor = CacheTextColor();
|
_cachedTextColor = CacheTextColor();
|
||||||
|
Height = Mathf.Max(_headerHeight, y);
|
||||||
// Set bounds
|
|
||||||
Size = new Vector2(Parent?.Width ?? Width, Mathf.Max(_headerHeight, y));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void OnParentChangedInternal()
|
protected override void OnParentChangedInternal()
|
||||||
{
|
{
|
||||||
// Clear cached tree
|
|
||||||
_tree = null;
|
_tree = null;
|
||||||
if (Parent != null)
|
|
||||||
Width = Parent.Width;
|
|
||||||
|
|
||||||
base.OnParentChangedInternal();
|
base.OnParentChangedInternal();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -412,11 +412,8 @@ namespace FlaxEditor.Modules
|
|||||||
// Add to the tree
|
// Add to the tree
|
||||||
var rootNode = Root.TreeNode;
|
var rootNode = Root.TreeNode;
|
||||||
rootNode.IsLayoutLocked = true;
|
rootNode.IsLayoutLocked = true;
|
||||||
//
|
|
||||||
sceneNode.ParentNode = Root;
|
sceneNode.ParentNode = Root;
|
||||||
rootNode.SortChildren();
|
rootNode.SortChildren();
|
||||||
//
|
|
||||||
treeNode.UnlockChildrenRecursive();
|
|
||||||
rootNode.IsLayoutLocked = false;
|
rootNode.IsLayoutLocked = false;
|
||||||
rootNode.Parent.PerformLayout();
|
rootNode.Parent.PerformLayout();
|
||||||
|
|
||||||
|
|||||||
@@ -350,7 +350,7 @@ namespace FlaxEditor.Modules
|
|||||||
{
|
{
|
||||||
// Perform layout
|
// Perform layout
|
||||||
var windowGUI = window.GUI;
|
var windowGUI = window.GUI;
|
||||||
windowGUI.UnlockChildrenRecursive();
|
windowGUI.IsLayoutLocked = false;
|
||||||
windowGUI.PerformLayout();
|
windowGUI.PerformLayout();
|
||||||
|
|
||||||
// Show
|
// Show
|
||||||
@@ -379,6 +379,10 @@ namespace FlaxEditor.Modules
|
|||||||
Editor.LogWarning(ex);
|
Editor.LogWarning(ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
masterPanel.PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -803,7 +803,7 @@ namespace FlaxEditor.Windows
|
|||||||
NavigationClearHistory();
|
NavigationClearHistory();
|
||||||
|
|
||||||
// Update UI layout
|
// Update UI layout
|
||||||
UnlockChildrenRecursive();
|
_isLayoutLocked = false;
|
||||||
PerformLayout();
|
PerformLayout();
|
||||||
|
|
||||||
// Load last viewed folder
|
// Load last viewed folder
|
||||||
|
|||||||
Reference in New Issue
Block a user