UI/Components/Vector3Field/Vector3Field.razor

A UI Razor component for a Vector3 field used in the editor. It renders a labeled row of three Vector3FieldCell components (X,Y,Z) and exposes properties for labels, values, min/max ranges, formatting, pixels-per-unit and setter actions.

@namespace Sunless.Libraries.UI
@using Sandbox
@using Sandbox.UI
@attribute [StyleSheet]
@inherits Panel

<root class="field v3-field">
	@if ( !string.IsNullOrEmpty( Label ) )
	{
		<div class="field-label">@Label</div>
	}

	<div class="v3-row">
		<Vector3FieldCell Axis="@LabelX" Value=@X Format="@Format" Min=@MinX Max=@MaxX Setter=@SetX PixelsPerUnit=@PixelsPerUnit FineScrubAction="@FineScrubAction" />
		<Vector3FieldCell Axis="@LabelY" Value=@Y Format="@Format" Min=@MinY Max=@MaxY Setter=@SetY PixelsPerUnit=@PixelsPerUnit FineScrubAction="@FineScrubAction" />
		<Vector3FieldCell Axis="@LabelZ" Value=@Z Format="@Format" Min=@MinZ Max=@MaxZ Setter=@SetZ PixelsPerUnit=@PixelsPerUnit FineScrubAction="@FineScrubAction" />
	</div>
</root>

@code
{
	public string Label { get; set; } = "";

	public string LabelX { get; set; } = "X";
	public string LabelY { get; set; } = "Y";
	public string LabelZ { get; set; } = "Z";

	public float X { get; set; }
	public float Y { get; set; }
	public float Z { get; set; }

	public float MinX { get; set; } = float.MinValue;
	public float MaxX { get; set; } = float.MaxValue;
	public float MinY { get; set; } = float.MinValue;
	public float MaxY { get; set; } = float.MaxValue;
	public float MinZ { get; set; } = float.MinValue;
	public float MaxZ { get; set; } = float.MaxValue;

	public string Format { get; set; } = "0.###";

	// Pixels of horizontal travel per 1.0 of value. Default fits integer
	// position ranges; pass ~400 for 0..1 normalized ranges.
	public float PixelsPerUnit { get; set; } = 4f;

	// Action name the project's input system has bound to "fine scrubbing"
	// (Shift / Walk in most s&box setups). Passed through to every cell.
	public string FineScrubAction { get; set; } = "Run";

	public Action<float> SetX { get; set; }
	public Action<float> SetY { get; set; }
	public Action<float> SetZ { get; set; }

	protected override int BuildHash() => HashCode.Combine( Label, X, Y, Z, Format, LabelX, LabelY, LabelZ );
}