Improve Margin editing

This commit is contained in:
Wojtek Figat
2021-05-29 13:48:26 +02:00
parent 44433bf3b4
commit 2bdebdb2ef
6 changed files with 69 additions and 0 deletions

View File

@@ -15,6 +15,11 @@ namespace FlaxEditor.CustomEditors.Editors
{
private IFloatValueEditor _element;
/// <summary>
/// Gets the element.
/// </summary>
public IFloatValueEditor Element => _element;
/// <inheritdoc />
public override DisplayStyle Style => DisplayStyle.Inline;

View File

@@ -23,6 +23,7 @@ namespace FlaxEditor.CustomEditors.Editors
new OptionType("Solid Color", typeof(SolidColorBrush)),
new OptionType("Linear Gradient", typeof(LinearGradientBrush)),
new OptionType("Texture 9-Slicing", typeof(Texture9SlicingBrush)),
new OptionType("Sprite 9-Slicing", typeof(Sprite9SlicingBrush)),
};
}
}

View File

@@ -0,0 +1,35 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using System.Linq;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.CustomEditors.Editors
{
/// <summary>
/// Default implementation of the inspector used to edit Version value type properties.
/// </summary>
[CustomEditor(typeof(Margin)), DefaultEditor]
public class MarginEditor : GenericEditor
{
/// <inheritdoc />
public override void Initialize(LayoutElementsContainer layout)
{
base.Initialize(layout);
var attributes = Values.GetAttributes();
if (attributes != null)
{
var limit = (LimitAttribute)attributes.FirstOrDefault(x => x is LimitAttribute);
if (limit != null)
{
for (var i = 0; i < ChildrenEditors.Count; i++)
{
if (ChildrenEditors[i] is FloatEditor floatEditor)
floatEditor.Element.SetLimits(limit);
}
}
}
}
}
}

View File

@@ -1,5 +1,7 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
using FlaxEngine;
namespace FlaxEditor.CustomEditors.Elements
{
/// <summary>
@@ -16,5 +18,11 @@ namespace FlaxEditor.CustomEditors.Elements
/// Gets a value indicating whether user is using a slider.
/// </summary>
bool IsSliding { get; }
/// <summary>
/// Sets the editor limits from member <see cref="LimitAttribute"/>.
/// </summary>
/// <param name="limit">The limit.</param>
void SetLimits(LimitAttribute limit);
}
}

View File

@@ -76,5 +76,14 @@ namespace FlaxEditor.CustomEditors.Elements
/// <inheritdoc cref="IFloatValueEditor.IsSliding" />
public bool IsSliding => Slider.IsSliding;
/// <inheritdoc />
public void SetLimits(LimitAttribute limit)
{
if (limit != null)
{
Slider.SetLimits(limit);
}
}
}
}

View File

@@ -410,6 +410,17 @@ namespace FlaxEditor.GUI.Input
Value = Value;
}
/// <summary>
/// Sets the limits from the attribute.
/// </summary>
/// <param name="limits">The limits.</param>
public void SetLimits(LimitAttribute limits)
{
_min = limits.Min;
_max = Mathf.Max(_min, limits.Max);
Value = Value;
}
/// <summary>
/// Updates the text of the textbox.
/// </summary>