Fix updating UI layout when adding control

Fixes #190
This commit is contained in:
Wojtek Figat
2021-02-03 21:59:21 +01:00
parent 6ffa497c0a
commit 85c219369d

View File

@@ -30,10 +30,11 @@ namespace FlaxEngine
return;
// Cleanup previous
if (_control != null)
var prevControl = _control;
if (prevControl != null)
{
_control.LocationChanged -= OnControlLocationChanged;
_control.Dispose();
prevControl.LocationChanged -= OnControlLocationChanged;
prevControl.Dispose();
}
// Set value
@@ -42,16 +43,17 @@ namespace FlaxEngine
// Link the new one (events and parent)
if (_control != null)
{
// Setup control
var containerControl = _control as ContainerControl;
if (containerControl != null)
containerControl.UnlockChildrenRecursive();
_control.Parent = GetParent();
_control.IndexInParent = OrderInParent;
_control.Location = new Vector2(LocalPosition);
// TODO: sync control order in parent with actor order in parent (think about special cases like Panel with scroll bars used as internal controls)
_control.LocationChanged += OnControlLocationChanged;
// Link children UI controls
if (containerControl != null && IsActiveInHierarchy)
{
var children = ChildrenCount;
@@ -64,6 +66,12 @@ namespace FlaxEngine
}
}
}
// Refresh
if (prevControl == null && _control.Parent != null)
_control.Parent.PerformLayout();
else
_control.PerformLayout();
}
}
}