Code cleanup, add tooltip and cache property option in layout #1140

This commit is contained in:
Wojtek Figat
2023-06-09 17:32:57 +02:00
parent 94abdfd734
commit 3bbfe9de8a
4 changed files with 25 additions and 27 deletions

View File

@@ -410,7 +410,6 @@ namespace FlaxEditor.CustomEditors.Dedicated
private bool _anchorDropDownClosed = true;
private Button _pivotRelativeButton;
/// <inheritdoc />
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>();
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)

View File

@@ -31,9 +31,9 @@ namespace FlaxEditor.Windows
public bool ScaleLinked = false;
/// <summary>
/// Indictation of if UI elements should size relative to the pivot point
/// Indication of if UI elements should size relative to the pivot point.
/// </summary>
public bool PivotRelativeSize = true;
public bool UIPivotRelative = true;
/// <summary>
/// Initializes a new instance of the <see cref="PropertiesWindow"/> class.
@@ -71,13 +71,16 @@ namespace FlaxEditor.Windows
public override void OnLayoutSerialize(XmlWriter writer)
{
writer.WriteAttributeString("ScaleLinked", ScaleLinked.ToString());
writer.WriteAttributeString("UIPivotRelative", UIPivotRelative.ToString());
}
/// <inheritdoc />
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;
}
}
}