mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
ScriptCore: Added NumberFormatAttribute
This commit is contained in:
@@ -216,6 +216,10 @@ internal class EntityEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NumberFormatAttribute? numberFormat = GetAttribute<NumberFormatAttribute>(attributes);
|
||||||
|
|
||||||
|
string? format = numberFormat?.Format;
|
||||||
|
|
||||||
RangeAttribute? range = GetAttribute<RangeAttribute>(attributes);
|
RangeAttribute? range = GetAttribute<RangeAttribute>(attributes);
|
||||||
|
|
||||||
// Get Min and Max Values from Type T
|
// Get Min and Max Values from Type T
|
||||||
@@ -255,14 +259,14 @@ internal class EntityEditor
|
|||||||
|
|
||||||
if (range?.Slider == true)
|
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;
|
newValue = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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;
|
newValue = value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace GlitchyEngine.Editor;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Specifies a custom number format for the input field in the editor.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This attribute is only applicable to numerical fields like <see cref="float"/>, <see cref="int"/>, etc.
|
||||||
|
/// </remarks>
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public sealed class NumberFormatAttribute : Attribute
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The number format for the input field.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This doesn't use C# number formatting, but rather the C-style printf number formatting.
|
||||||
|
/// </remarks>
|
||||||
|
public string Format { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="NumberFormatAttribute"/> with a custom number format.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="format"><inheritdoc cref="Format"/></param>
|
||||||
|
public NumberFormatAttribute(string format)
|
||||||
|
{
|
||||||
|
Format = format;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user