Files
sbox-public/game/addons/base/code/UI/Controls/VectorControl.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

42 lines
997 B
C#

namespace Sandbox.UI;
/// <summary>
/// Like TextEntry, except just for numbers
/// </summary>
[CustomEditor( typeof( Vector2 ) )]
[CustomEditor( typeof( Vector3 ) )]
[CustomEditor( typeof( Vector4 ) )]
public partial class VectorControl : BaseControl
{
NumberEntry _x;
NumberEntry _y;
NumberEntry _z;
NumberEntry _w;
public VectorControl()
{
_x = AddChild<NumberEntry>( "x" );
_y = AddChild<NumberEntry>( "y" );
_z = AddChild<NumberEntry>( "z" );
_w = AddChild<NumberEntry>( "w" );
}
public override void Rebuild()
{
if ( Property == null ) return;
// get the vector3 as a so
if ( Property.TryGetAsObject( out var so ) )
{
_x.Property = so.GetProperty( "x" );
_y.Property = so.GetProperty( "y" );
_z.Property = so.GetProperty( "z" );
_z.Style.Display = _z.Property is not null ? DisplayMode.Flex : DisplayMode.None;
_w.Property = so.GetProperty( "w" );
_w.Style.Display = _w.Property is not null ? DisplayMode.Flex : DisplayMode.None;
}
}
}