Files
sbox-public/engine/Sandbox.Tools/ControlWidget/IntegerControlWidget.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

37 lines
1.1 KiB
C#

using System;
namespace Editor;
[CustomEditor( typeof( char ) )]
[CustomEditor( typeof( byte ) )]
[CustomEditor( typeof( sbyte ) )]
[CustomEditor( typeof( short ) )]
[CustomEditor( typeof( ushort ) )]
[CustomEditor( typeof( int ) )]
[CustomEditor( typeof( uint ) )]
[CustomEditor( typeof( long ) )]
[CustomEditor( typeof( ulong ) )]
public class IntegerControlWidget : FloatControlWidget
{
public IntegerControlWidget( SerializedProperty property ) : base( property )
{
Label = "i";
HighlightColor = Theme.Blue;
}
internal new static string ValueToStringImpl( SerializedProperty property )
{
return property.GetValue<long>().ToString( "0" );
}
internal new static object StringToValueImpl( string text, SerializedProperty property )
{
Type underlyingType = Nullable.GetUnderlyingType( property.PropertyType ) ?? property.PropertyType;
return Convert.ChangeType( text.ToLongEval( property.As.Long ), underlyingType );
}
protected override string ValueToString() => ValueToStringImpl( SerializedProperty );
protected override object StringToValue( string text ) => StringToValueImpl( text, SerializedProperty );
}