InputValue
See the InputValueDemo.cs.
using Gridrand.Contracts;
using Gridrand.RimGui.Manual;
namespace Gridrand.RimGui.Extensions.Manual
{
/// <summary>
/// <see cref="GuiUtil.Input(Gui, bool, int)"/>,
/// <see cref="GuiUtil.InputNumeric{TNumeric}(Gui, ref TNumeric, int)"/>,
/// <see cref="GuiUtil.SliderInputNumeric{TNumeric}(Gui, ref TNumeric, TNumeric, TNumeric, int)"/> etc.
/// </summary>
class InputValueDemo : 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;
bool boolValue;
int sliderIntValue = 100;
int intValue1 = 1;
int intValue2 = 50;
int intValue3 = 5000;
float rangeFloatValue0 = 50f;
float rangeFloatValue1 = 10000f;
double rangeDoubleValue = 500d;
char charValue = 'a';
string stringValue = "0123456789";
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 => 450f;
public InputValueDemo(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").InputNumeric(ref labelRatio);
// Apply label size ratio to all labeled inputs
using var s = ExStyle.LabelSizes.Begin(Size.Ratio(labelRatio));
Gui.Separator();
Gui.Heading("InputNumeric");
{
Gui.LabelNext("byte").InputNumeric(ref byteValue);
Gui.LabelNext("sbyte").InputNumeric(ref sbyteValue);
Gui.LabelNext("short").InputNumeric(ref shortValue);
Gui.LabelNext("ushort").InputNumeric(ref ushortValue);
Gui.LabelNext("int").InputNumeric(ref intValue);
Gui.LabelNext("uint").InputNumeric(ref uintValue);
Gui.LabelNext("long").InputNumeric(ref longValue);
Gui.LabelNext("ulong").InputNumeric(ref ulongValue);
Gui.LabelNext("nint").InputNumeric(ref nintValue);
Gui.LabelNext("nuint").InputNumeric(ref nuintValue);
Gui.LabelNext("float").InputNumeric(ref floatValue);
Gui.LabelNext("double").InputNumeric(ref doubleValue);
Gui.LabelNext("decimal").InputNumeric(ref decimalValue);
// If you want to specify a range, use scope.
using (Ranges.BeginInt(0, 1))
Gui.LabelNext("int 0-1").InputNumeric(ref intValue1);
using (Ranges.BeginInt(0, 100))
Gui.LabelNext("int 0-100").InputNumeric(ref intValue2);
using (Ranges.BeginInt(0, 10000))
Gui.LabelNext("int 0-10000").InputNumeric(ref intValue3);
using (Ranges.BeginFloat(0f, 100f))
Gui.LabelNext("float 0f-100f").InputNumeric(ref rangeFloatValue0);
using (Ranges.BeginFloat(0f, 100_000_000_000f))
Gui.LabelNext("float 0f-100_000_000_000f").InputNumeric(ref rangeFloatValue1);
using (Ranges.BeginDouble(0d, 1000d))
Gui.LabelNext("double 0d-1000d").InputNumeric(ref rangeDoubleValue);
}
Gui.Heading("SliderInputNumeric");
{
Gui.LabelNext("Slider 0-100").SliderInputNumeric(ref sliderIntValue, 0, 100);
}
Gui.Heading("Input");
{
Gui.LabelNext("bool").Input(ref boolValue);
Gui.LabelNext("char").Input(ref charValue);
Gui.LabelNext("string").InputText(ref stringValue);
v2 = Gui.LabelNext("Vector2").Input(v2);
v3 = Gui.LabelNext("Vector3").Input(v3);
v4 = Gui.LabelNext("Vector4").Input(v4);
v2Int = Gui.LabelNext("Vector2Int").Input(v2Int);
v3Int = Gui.LabelNext("Vector3Int").Input(v3Int);
rect = Gui.LabelNext("Rect").Input(rect);
rectInt = Gui.LabelNext("RectInt").Input(rectInt);
bounds = Gui.LabelNext("Bounds").Input(bounds);
boundsInt = Gui.LabelNext("BoundsInt").Input(boundsInt);
color = Gui.LabelNext("InputColor").Input(color);
color32 = Gui.LabelNext("InputColor32").Input(color32);
}
}
}
}