diff --git a/ScriptCore/Editor/EntityEditor.cs b/ScriptCore/Editor/EntityEditor.cs index eaa98bf..05ba826 100644 --- a/ScriptCore/Editor/EntityEditor.cs +++ b/ScriptCore/Editor/EntityEditor.cs @@ -216,6 +216,10 @@ internal class EntityEditor } } + NumberFormatAttribute? numberFormat = GetAttribute(attributes); + + string? format = numberFormat?.Format; + RangeAttribute? range = GetAttribute(attributes); // Get Min and Max Values from Type T @@ -255,14 +259,14 @@ internal class EntityEditor if (range?.Slider == true) { - if (ImGui.SliderScalar(fieldId, dataType, (IntPtr)(&value), (IntPtr)(&min), (IntPtr)(&max))) + if (ImGui.SliderScalar(fieldId, dataType, (IntPtr)(&value), (IntPtr)(&min), (IntPtr)(&max), format)) { newValue = value; } } else { - if (ImGui.DragScalar(fieldId, dataType, (IntPtr)(&value), dragSpeed, (IntPtr)(&min), (IntPtr)(&max))) + if (ImGui.DragScalar(fieldId, dataType, (IntPtr)(&value), dragSpeed, (IntPtr)(&min), (IntPtr)(&max), format)) { newValue = value; } diff --git a/ScriptCore/Editor/NumberFormatAttribute.cs b/ScriptCore/Editor/NumberFormatAttribute.cs new file mode 100644 index 0000000..ce786b8 --- /dev/null +++ b/ScriptCore/Editor/NumberFormatAttribute.cs @@ -0,0 +1,30 @@ +using System; + +namespace GlitchyEngine.Editor; + +/// +/// Specifies a custom number format for the input field in the editor. +/// +/// +/// This attribute is only applicable to numerical fields like , , etc. +/// +[AttributeUsage(AttributeTargets.Field)] +public sealed class NumberFormatAttribute : Attribute +{ + /// + /// The number format for the input field. + /// + /// + /// This doesn't use C# number formatting, but rather the C-style printf number formatting. + /// + public string Format { get; private set; } + + /// + /// Initializes a new instance of the with a custom number format. + /// + /// + public NumberFormatAttribute(string format) + { + Format = format; + } +}