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;
}
}
}

View File

@@ -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);
}
}

View File

@@ -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<int> _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