Improve Margin editing
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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)),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
35
Source/Editor/CustomEditors/Editors/MarginEditor.cs
Normal file
35
Source/Editor/CustomEditors/Editors/MarginEditor.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user