// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
using System.Linq;
using System.Reflection;
using FlaxEditor.GUI.Input;
using FlaxEngine;
using FlaxEngine.GUI;
namespace FlaxEditor.CustomEditors.Elements
{
///
/// The integer value element.
///
///
public class IntegerValueElement : LayoutElement, IIntegerValueEditor
{
///
/// The integer value box.
///
public readonly IntValueBox IntValue;
///
/// Initializes a new instance of the class.
///
public IntegerValueElement()
{
IntValue = new IntValueBox(0);
}
///
/// Sets the editor limits from member .
///
/// The member.
public void SetLimits(MemberInfo member)
{
// Try get limit attribute for value min/max range setting and slider speed
if (member != null)
{
var attributes = member.GetCustomAttributes(true);
var limit = attributes.FirstOrDefault(x => x is LimitAttribute);
if (limit != null)
{
IntValue.SetLimits((LimitAttribute)limit);
}
}
}
///
/// Sets the editor limits from member .
///
/// The limit.
public void SetLimits(LimitAttribute limit)
{
if (limit != null)
{
IntValue.SetLimits(limit);
}
}
///
/// Sets the editor limits from the other .
///
/// The other.
public void SetLimits(IntegerValueElement other)
{
if (other != null)
{
IntValue.SetLimits(other.IntValue);
}
}
///
public override Control Control => IntValue;
///
public int Value
{
get => IntValue.Value;
set => IntValue.Value = value;
}
///
public bool IsSliding => IntValue.IsSliding;
}
///
/// The signed integer value element (maps to the full range of long type).
///
///
public class SignedIntegerValueElement : LayoutElement
{
///
/// The signed integer (long) value box.
///
public readonly LongValueBox LongValue;
///
/// Initializes a new instance of the class.
///
public SignedIntegerValueElement()
{
LongValue = new LongValueBox(0);
}
///
public override Control Control => LongValue;
///
/// Gets or sets the value.
///
public long Value
{
get => LongValue.Value;
set => LongValue.Value = value;
}
///
/// Gets a value indicating whether user is using a slider.
///
public bool IsSliding => LongValue.IsSliding;
}
///
/// The unsigned integer value element (maps to the full range of ulong type).
///
///
public class UnsignedIntegerValueElement : LayoutElement
{
///
/// The unsigned integer (ulong) value box.
///
public readonly ULongValueBox ULongValue;
///
/// Initializes a new instance of the class.
///
public UnsignedIntegerValueElement()
{
ULongValue = new ULongValueBox(0);
}
///
public override Control Control => ULongValue;
///
/// Gets or sets the value.
///
public ulong Value
{
get => ULongValue.Value;
set => ULongValue.Value = value;
}
///
/// Gets a value indicating whether user is using a slider.
///
public bool IsSliding => ULongValue.IsSliding;
}
}