DragInput
See the DragInputDemo.cs.
using Gridrand.Contracts;
using Gridrand.RimGui.Manual;
namespace Gridrand.RimGui.Extensions.Manual
{
/// <summary>
/// <see cref="GuiUtil.DragInputNumeric{TNumeric}(Gui, ref TNumeric, int)"/>,
/// <see cref="GuiUtil.DragInput(Gui, Contracts.Bounds, int)"/> etc.
/// </summary>
class DragInputDemo : ManualBase, IManual
{
// Ratio for label size in label-input UI widgets
float labelRatio = 0.3f;
byte byteValue;
sbyte sbyteValue;
short shortValue;
ushort ushortValue;
int intValue;
uint uintValue;
long longValue;
ulong ulongValue;
nint nintValue;
nuint nuintValue;
float floatValue;
double doubleValue;
decimal decimalValue;
int intValue1 = 1;
int intValue2 = 50;
int intValue3 = 5000;
float rangeFloatValue0 = 50f;
float rangeFloatValue1 = 10000f;
double rangeDoubleValue = 500d;
float ratioFloat = 0.5f;
int percentageInt = 50;
readonly FloatFormatter ratioFormatter = new("ratio = 0.00");
readonly IntFormatter percentageFormatter = new("0px");
Color32 color32 = Color32.Red;
Color color = Color.Red;
Vector2 v2 = new(10f, 10f);
Vector3 v3 = new(10f, 10f, 10f);
Vector4 v4 = new(10f, 10f, 10f, 10f);
Vector2Int v2Int = new(10, 10);
Vector3Int v3Int = new(10, 10, 10);
Rect rect = new(10, 10, 10, 10);
RectInt rectInt = new(10, 10, 10, 10);
Bounds bounds = new(Vector3.One, Vector3.One);
BoundsInt boundsInt = new(Vector3Int.One, Vector3Int.One);
float IManual.InitialWidth => 600f;
public DragInputDemo(ManualBaseResource p) : base(p)
{
}
public void Draw()
{
Gui.Heading("Settings");
// Input for adjusting the label-to-input ratio
using (Ranges.BeginFloat(0.1f, 0.9f))
Gui.LabelNext("Label Ratio").DragInputNumeric(ref labelRatio);
// Apply label size ratio to all labeled inputs
using var s = ExStyle.LabelSizes.Begin(Size.Ratio(labelRatio));
Gui.Separator();
Gui.Heading("DragInputNumeric");
{
Gui.LabelNext("byte").DragInputNumeric(ref byteValue);
Gui.LabelNext("sbyte").DragInputNumeric(ref sbyteValue);
Gui.LabelNext("short").DragInputNumeric(ref shortValue);
Gui.LabelNext("ushort").DragInputNumeric(ref ushortValue);
Gui.LabelNext("int").DragInputNumeric(ref intValue);
Gui.LabelNext("uint").DragInputNumeric(ref uintValue);
Gui.LabelNext("long").DragInputNumeric(ref longValue);
Gui.LabelNext("ulong").DragInputNumeric(ref ulongValue);
Gui.LabelNext("nint").DragInputNumeric(ref nintValue);
Gui.LabelNext("nuint").DragInputNumeric(ref nuintValue);
Gui.LabelNext("float").DragInputNumeric(ref floatValue);
Gui.LabelNext("double").DragInputNumeric(ref doubleValue);
Gui.LabelNext("decimal").DragInputNumeric(ref decimalValue);
// If you want to specify a range, use scope.
using (Ranges.BeginInt(0, 1))
Gui.LabelNext("int 0-1").DragInputNumeric(ref intValue1);
using (Ranges.BeginInt(0, 100))
Gui.LabelNext("int 0-100").DragInputNumeric(ref intValue2);
using (Ranges.BeginInt(0, 10000))
Gui.LabelNext("int 0-10000").DragInputNumeric(ref intValue3);
using (Ranges.BeginFloat(0f, 100f))
Gui.LabelNext("float 0f-100f").DragInputNumeric(ref rangeFloatValue0);
using (Ranges.BeginFloat(0f, 100_000_000_000f))
Gui.LabelNext("float 0f-100_000_000_000f").DragInputNumeric(ref rangeFloatValue1);
using (Ranges.BeginDouble(0d, 1000d))
Gui.LabelNext("double 0d-1000d").DragInputNumeric(ref rangeDoubleValue);
using (Ranges.BeginInt(0, 100))
using (Formatters.Begin(percentageFormatter))
{
Gui.LabelNext("Int 0px").DragInputNumeric(ref percentageInt);
}
using (Ranges.BeginFloat(0f, 1f))
using (Formatters.Begin(ratioFormatter))
{
Gui.LabelNext("Float ratio = 0.00").DragInputNumeric(ref ratioFloat);
}
}
Gui.Heading("DragInput");
{
v2 = Gui.LabelNext("Vector2").DragInput(v2);
v3 = Gui.LabelNext("Vector3").DragInput(v3);
v4 = Gui.LabelNext("Vector4").DragInput(v4);
v2Int = Gui.LabelNext("Vector2Int").DragInput(v2Int);
v3Int = Gui.LabelNext("Vector3Int").DragInput(v3Int);
rect = Gui.LabelNext("Rect").DragInput(rect);
rectInt = Gui.LabelNext("RectInt").DragInput(rectInt);
bounds = Gui.LabelNext("Bounds").DragInput(bounds);
boundsInt = Gui.LabelNext("BoundsInt").DragInput(boundsInt);
color = Gui.LabelNext("InputColor").DragInput(color);
color32 = Gui.LabelNext("InputColor32").DragInput(color32);
}
}
}
}