From 9c348b284fe38c33942155afe871f8e235a6d5a4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 3 Feb 2021 22:00:12 +0100 Subject: [PATCH] Fixes for UI control sync --- Source/Engine/UI/UIControl.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Source/Engine/UI/UIControl.cs b/Source/Engine/UI/UIControl.cs index e4a6b4e33..b31d9cab0 100644 --- a/Source/Engine/UI/UIControl.cs +++ b/Source/Engine/UI/UIControl.cs @@ -13,6 +13,7 @@ namespace FlaxEngine partial class UIControl { private Control _control; + private static bool _blockEvents; // Used to ignore internal events from C++ UIControl impl when performing state sync with C# UI /// /// Gets or sets the GUI control used by this actor. @@ -44,6 +45,7 @@ namespace FlaxEngine if (_control != null) { // Setup control + _blockEvents = true; var containerControl = _control as ContainerControl; if (containerControl != null) containerControl.UnlockChildrenRecursive(); @@ -68,6 +70,7 @@ namespace FlaxEngine } // Refresh + _blockEvents = false; if (prevControl == null && _control.Parent != null) _control.Parent.PerformLayout(); else @@ -178,7 +181,9 @@ namespace FlaxEngine private void OnControlLocationChanged(Control control) { + _blockEvents = true; LocalPosition = new Vector3(control.Location, LocalPosition.Z); + _blockEvents = false; } /// @@ -293,7 +298,7 @@ namespace FlaxEngine internal void ParentChanged() { - if (_control != null) + if (_control != null && !_blockEvents) { _control.Parent = GetParent(); _control.IndexInParent = OrderInParent; @@ -302,13 +307,15 @@ namespace FlaxEngine internal void TransformChanged() { - if (_control != null) + if (_control != null && !_blockEvents) + { _control.Location = new Vector2(LocalPosition); + } } internal void ActiveInTreeChanged() { - if (_control != null) + if (_control != null && !_blockEvents) { // Link or unlink control (won't modify Enable/Visible state) _control.Parent = GetParent(); @@ -318,8 +325,10 @@ namespace FlaxEngine internal void OrderInParentChanged() { - if (_control != null) + if (_control != null && !_blockEvents) + { _control.IndexInParent = OrderInParent; + } } internal void BeginPlay()