From 73e92e33fd56bd70e67ca04a41180090fe7639f3 Mon Sep 17 00:00:00 2001 From: honzapatCZ Date: Fri, 2 Apr 2021 17:38:30 +0200 Subject: [PATCH 1/3] local positions --- .../Dedicated/UIControlEditor.cs | 4 +-- Source/Engine/UI/GUI/Control.Bounds.cs | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index e176f2b70..bb9da0936 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -423,9 +423,9 @@ namespace FlaxEditor.CustomEditors.Dedicated private void BuildLocationSizeOffsets(LayoutElementsContainer horUp, LayoutElementsContainer horDown, bool xEq, bool yEq, ScriptType[] valueTypes) { - ScriptMemberInfo xInfo = valueTypes[0].GetProperty("X"); + ScriptMemberInfo xInfo = valueTypes[0].GetProperty("LocalX"); ItemInfo xItem = new ItemInfo(xInfo); - ScriptMemberInfo yInfo = valueTypes[0].GetProperty("Y"); + ScriptMemberInfo yInfo = valueTypes[0].GetProperty("LocalY"); ItemInfo yItem = new ItemInfo(yInfo); ScriptMemberInfo widthInfo = valueTypes[0].GetProperty("Width"); ItemInfo widthItem = new ItemInfo(widthInfo); diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs index e4e2eafcc..05214b498 100644 --- a/Source/Engine/UI/GUI/Control.Bounds.cs +++ b/Source/Engine/UI/GUI/Control.Bounds.cs @@ -26,6 +26,26 @@ namespace FlaxEngine.GUI set => Bounds = new Rectangle(X, value, _bounds.Size); } + /// + /// Gets or sets the local X coordinate of the pivot of the control relative to the anchor in parent of its container. + /// + [HideInEditor, NoSerialize] + public float LocalX + { + get => LocalLocation.X; + set => LocalLocation = new Vector2(value, LocalLocation.Y); + } + + /// + /// Gets or sets the local Y coordinate of the pivot of the control relative to the anchor in parent of its container. + /// + [HideInEditor, NoSerialize] + public float LocalY + { + get => LocalLocation.Y; + set => LocalLocation = new Vector2(LocalLocation.X, value); + } + /// /// Gets or sets the normalized position in the parent control that the upper left corner is anchored to (range 0-1). /// @@ -137,6 +157,17 @@ namespace FlaxEngine.GUI set => Bounds = new Rectangle(value, _bounds.Size); } + /// + /// The local position of the pivot of the control relative to the anchor in parent of its container. + /// + [NoSerialize] + [HideInEditor, ExpandGroups, EditorDisplay("Transform"), EditorOrder(1000), Tooltip("The local position of the pivot of the control relative to the anchor in parent of its container.")] + public Vector2 LocalLocation + { + get => _bounds.Location - (Parent.Size * (AnchorMax + AnchorMin) / 2) + Size * Pivot; + set => Bounds = new Rectangle(value + (Parent.Size * (AnchorMax + AnchorMin) / 2) - Size * Pivot, _bounds.Size); + } + /// /// Gets or sets width of the control. /// From dff1374378012b89d6ae2eae04d43dcbbea4c767 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 10:57:17 +0200 Subject: [PATCH 2/3] Post-merge tweaks #417 --- .../Dedicated/UIControlEditor.cs | 7 +--- Source/Engine/UI/GUI/Control.Bounds.cs | 40 ++++++++----------- 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs index bb9da0936..833d7d7d3 100644 --- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs +++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs @@ -32,18 +32,13 @@ namespace FlaxEditor.CustomEditors.Dedicated if (_presets != value) { _presets = value; - OnPresetsChanged(); + TooltipText = CustomEditorsUtil.GetPropertyNameUI(_presets.ToString()); } } } public bool IsSelected; - private void OnPresetsChanged() - { - TooltipText = CustomEditorsUtil.GetPropertyNameUI(_presets.ToString()); - } - /// public override void Draw() { diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs index 05214b498..0fdad2fd5 100644 --- a/Source/Engine/UI/GUI/Control.Bounds.cs +++ b/Source/Engine/UI/GUI/Control.Bounds.cs @@ -49,8 +49,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the normalized position in the parent control that the upper left corner is anchored to (range 0-1). /// - [Serialize] - [HideInEditor, ExpandGroups, Limit(0.0f, 1.0f, 0.01f), EditorDisplay("Transform"), EditorOrder(990), Tooltip("The normalized position in the parent control that the upper left corner is anchored to (range 0-1).")] + [HideInEditor] public Vector2 AnchorMin { get => _anchorMin; @@ -69,8 +68,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the normalized position in the parent control that the bottom right corner is anchored to (range 0-1). /// - [Serialize] - [HideInEditor, ExpandGroups, Limit(0.0f, 1.0f, 0.01f), EditorDisplay("Transform"), EditorOrder(991), Tooltip("The normalized position in the parent control that the bottom right corner is anchored to (range 0-1).")] + [Serialize, HideInEditor] public Vector2 AnchorMax { get => _anchorMax; @@ -89,8 +87,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the offsets of the corners of the control relative to its anchors. /// - [Serialize] - [HideInEditor, ExpandGroups, EditorDisplay("Transform"), EditorOrder(992), Tooltip("The offsets of the corners of the control relative to its anchors.")] + [Serialize, HideInEditor] public Margin Offsets { get => _offsets; @@ -111,8 +108,8 @@ namespace FlaxEngine.GUI [NoSerialize, HideInEditor] internal float Proxy_Offset_Left { - get => Offsets.Left; - set => Offsets = new Margin(value, Offsets.Right, Offsets.Top, Offsets.Bottom); + get => _offsets.Left; + set => Offsets = new Margin(value, _offsets.Right, _offsets.Top, _offsets.Bottom); } /// @@ -121,8 +118,8 @@ namespace FlaxEngine.GUI [NoSerialize, HideInEditor] internal float Proxy_Offset_Right { - get => Offsets.Right; - set => Offsets = new Margin(Offsets.Left, value, Offsets.Top, Offsets.Bottom); + get => _offsets.Right; + set => Offsets = new Margin(_offsets.Left, value, _offsets.Top, _offsets.Bottom); } /// @@ -131,8 +128,8 @@ namespace FlaxEngine.GUI [NoSerialize, HideInEditor] internal float Proxy_Offset_Top { - get => Offsets.Top; - set => Offsets = new Margin(Offsets.Left, Offsets.Right, value, Offsets.Bottom); + get => _offsets.Top; + set => Offsets = new Margin(_offsets.Left, _offsets.Right, value, _offsets.Bottom); } /// @@ -141,16 +138,15 @@ namespace FlaxEngine.GUI [NoSerialize, HideInEditor] internal float Proxy_Offset_Bottom { - get => Offsets.Bottom; - set => Offsets = new Margin(Offsets.Left, Offsets.Right, Offsets.Top, value); + get => _offsets.Bottom; + set => Offsets = new Margin(_offsets.Left, _offsets.Right, _offsets.Top, value); } #endif /// /// Gets or sets coordinates of the upper-left corner of the control relative to the upper-left corner of its container. /// - [NoSerialize] - [HideInEditor, ExpandGroups, EditorDisplay("Transform"), EditorOrder(1000), Tooltip("The location of the upper-left corner of the control relative to he upper-left corner of its container.")] + [NoSerialize, HideInEditor] public Vector2 Location { get => _bounds.Location; @@ -158,14 +154,13 @@ namespace FlaxEngine.GUI } /// - /// The local position of the pivot of the control relative to the anchor in parent of its container. + /// Gets or sets the local position of the pivot of the control relative to the anchor in parent of its container. /// - [NoSerialize] - [HideInEditor, ExpandGroups, EditorDisplay("Transform"), EditorOrder(1000), Tooltip("The local position of the pivot of the control relative to the anchor in parent of its container.")] + [NoSerialize, HideInEditor] public Vector2 LocalLocation { - get => _bounds.Location - (Parent.Size * (AnchorMax + AnchorMin) / 2) + Size * Pivot; - set => Bounds = new Rectangle(value + (Parent.Size * (AnchorMax + AnchorMin) / 2) - Size * Pivot, _bounds.Size); + get => _bounds.Location - (_parent != null ? _parent._bounds.Size * (_anchorMax + _anchorMin) * 0.5f : Vector2.Zero) + _bounds.Size * _pivot; + set => Bounds = new Rectangle(value + (_parent != null ? _parent.Bounds.Size * (_anchorMax + _anchorMin) * 0.5f : Vector2.Zero) - _bounds.Size * _pivot, _bounds.Size); } /// @@ -191,8 +186,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets control's size. /// - [NoSerialize] - [HideInEditor, EditorDisplay("Transform"), EditorOrder(1010), Tooltip("The size of the control bounds.")] + [NoSerialize, HideInEditor] public Vector2 Size { get => _bounds.Size; From 772af752d2a6e8a9456de14664df21a7152daa76 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 7 Apr 2021 11:10:51 +0200 Subject: [PATCH 3/3] Fix regression from dff1374378012b89d6ae2eae04d43dcbbea4c767 --- Source/Engine/UI/GUI/Control.Bounds.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs index 0fdad2fd5..91f377c91 100644 --- a/Source/Engine/UI/GUI/Control.Bounds.cs +++ b/Source/Engine/UI/GUI/Control.Bounds.cs @@ -49,7 +49,7 @@ namespace FlaxEngine.GUI /// /// Gets or sets the normalized position in the parent control that the upper left corner is anchored to (range 0-1). /// - [HideInEditor] + [Serialize, HideInEditor] public Vector2 AnchorMin { get => _anchorMin;