diff --git a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs
index 0a78240f2..6cbaa0ca0 100644
--- a/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs
+++ b/Source/Editor/CustomEditors/Dedicated/UIControlEditor.cs
@@ -410,7 +410,6 @@ namespace FlaxEditor.CustomEditors.Dedicated
private bool _anchorDropDownClosed = true;
private Button _pivotRelativeButton;
-
///
public override void Initialize(LayoutElementsContainer layout)
{
@@ -486,9 +485,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
horDown.CustomControl.Height = TextBoxBase.DefaultHeight;
GetAnchorEquality(out _cachedXEq, out _cachedYEq, valueTypes);
-
BuildLocationSizeOffsets(horUp, horDown, _cachedXEq, _cachedYEq, valueTypes);
-
BuildExtraButtons(group);
main.Space(10);
@@ -497,35 +494,36 @@ namespace FlaxEditor.CustomEditors.Dedicated
private void BuildExtraButtons(VerticalPanelElement group)
{
- (Values[0] as Control).PivotRelative = Editor.Instance.Windows.PropertiesWin.PivotRelativeSize;
-
- var current = Editor.Instance.Windows.PropertiesWin.PivotRelativeSize;
+ var control = (Control)Values[0];
+ var pivotRelative = Editor.Instance.Windows.PropertiesWin.UIPivotRelative;
+ control.PivotRelative = pivotRelative;
var panel = group.CustomContainer();
panel.CustomControl.Height = TextBoxBase.DefaultHeight;
panel.CustomControl.ClipChildren = false;
panel.CustomControl.Parent = group.ContainerControl;
- _pivotRelativeButton = new Button()
+ _pivotRelativeButton = new Button
{
+ TooltipText = "Toggles UI control resizing based on where the pivot is rather than just the top-left.",
+ Size = new Float2(18),
Parent = panel.ContainerControl,
- Width = 18,
- Height = 18,
BackgroundBrush = new SpriteBrush(Editor.Instance.Icons.Scale32),
AnchorPreset = AnchorPresets.TopRight,
X = 77,
};
- SetStyle(current);
+ SetStyle(pivotRelative);
_pivotRelativeButton.Clicked += PivotRelativeClicked;
}
private void PivotRelativeClicked()
{
- var current = (Values[0] as Control).PivotRelative;
- (Values[0] as Control).PivotRelative = !current;
- Editor.Instance.Windows.PropertiesWin.PivotRelativeSize = !current;
- SetStyle((Values[0] as Control).PivotRelative);
+ var control = (Control)Values[0];
+ var pivotRelative = control.PivotRelative;
+ control.PivotRelative = !pivotRelative;
+ Editor.Instance.Windows.PropertiesWin.UIPivotRelative = !pivotRelative;
+ SetStyle(control.PivotRelative);
}
private void SetStyle(bool current)
diff --git a/Source/Editor/Windows/PropertiesWindow.cs b/Source/Editor/Windows/PropertiesWindow.cs
index 69fac31d7..baa10f8b9 100644
--- a/Source/Editor/Windows/PropertiesWindow.cs
+++ b/Source/Editor/Windows/PropertiesWindow.cs
@@ -31,9 +31,9 @@ namespace FlaxEditor.Windows
public bool ScaleLinked = false;
///
- /// Indictation of if UI elements should size relative to the pivot point
+ /// Indication of if UI elements should size relative to the pivot point.
///
- public bool PivotRelativeSize = true;
+ public bool UIPivotRelative = true;
///
/// Initializes a new instance of the class.
@@ -71,13 +71,16 @@ namespace FlaxEditor.Windows
public override void OnLayoutSerialize(XmlWriter writer)
{
writer.WriteAttributeString("ScaleLinked", ScaleLinked.ToString());
+ writer.WriteAttributeString("UIPivotRelative", UIPivotRelative.ToString());
}
-
+
///
public override void OnLayoutDeserialize(XmlElement node)
{
if (bool.TryParse(node.GetAttribute("ScaleLinked"), out bool value1))
ScaleLinked = value1;
+ if (bool.TryParse(node.GetAttribute("UIPivotRelative"), out value1))
+ UIPivotRelative = value1;
}
}
}
diff --git a/Source/Engine/UI/GUI/Control.Bounds.cs b/Source/Engine/UI/GUI/Control.Bounds.cs
index bdef1c8ac..c6260b648 100644
--- a/Source/Engine/UI/GUI/Control.Bounds.cs
+++ b/Source/Engine/UI/GUI/Control.Bounds.cs
@@ -1,7 +1,6 @@
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System;
-using System.Runtime.Remoting.Messaging;
namespace FlaxEngine.GUI
{
@@ -191,13 +190,12 @@ namespace FlaxEngine.GUI
{
if (Mathf.NearEqual(_bounds.Size.X, value))
return;
- var rectLocation = _bounds.Location;
- if (PivotRelative)
+ var bounds = new Rectangle(_bounds.Location, value, _bounds.Size.Y);
+ if (_pivotRelativeSizing)
{
var delta = _bounds.Size.X - value;
- rectLocation.X += delta * Pivot.X;
+ bounds.Location.X += delta * Pivot.X;
}
- var bounds = new Rectangle(rectLocation, value, _bounds.Size.Y);
SetBounds(ref bounds);
}
}
@@ -213,13 +211,12 @@ namespace FlaxEngine.GUI
{
if (Mathf.NearEqual(_bounds.Size.Y, value))
return;
- var rectLocation = _bounds.Location;
- if (PivotRelative)
+ var bounds = new Rectangle(_bounds.Location, _bounds.Size.X, value);
+ if (_pivotRelativeSizing)
{
var delta = _bounds.Size.Y - value;
- rectLocation.Y += delta * Pivot.Y;
+ bounds.Location.Y += delta * Pivot.Y;
}
- var bounds = new Rectangle(rectLocation, _bounds.Size.X, value);
SetBounds(ref bounds);
}
}
diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs
index b3e0dc990..3bc2610a4 100644
--- a/Source/Engine/UI/GUI/Control.cs
+++ b/Source/Engine/UI/GUI/Control.cs
@@ -61,6 +61,7 @@ namespace FlaxEngine.GUI
private bool _isVisible = true;
private bool _isEnabled = true;
private bool _autoFocus = true;
+ private bool _pivotRelativeSizing = false;
private List _touchOvers;
private RootControl.UpdateDelegate _tooltipUpdate;
@@ -76,7 +77,6 @@ namespace FlaxEngine.GUI
private float _rotation;
internal Matrix3x3 _cachedTransform;
internal Matrix3x3 _cachedTransformInv;
- private bool _pivotRelativeSizing = false;
// Style