// 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 slider element. /// /// public class SliderElement : LayoutElement, IFloatValueEditor, IIntegerValueEditor { /// /// The slider control. /// public readonly SliderControl Slider; /// /// Initializes a new instance of the class. /// public SliderElement() { Slider = new SliderControl(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 RangeAttribute); if (limit != null) { Slider.SetLimits((RangeAttribute)limit); } } } /// /// Sets the editor limits from member . /// /// The limit. public void SetLimits(RangeAttribute limit) { if (limit != null) { Slider.SetLimits(limit); } } /// public override Control Control => Slider; /// public float Value { get => Slider.Value; set => Slider.Value = value; } /// int IIntegerValueEditor.Value { get => (int)Slider.Value; set => Slider.Value = value; } /// public bool IsSliding => Slider.IsSliding; /// public void SetLimits(LimitAttribute limit) { if (limit != null) { Slider.SetLimits(limit); } } } }