Input
See the InputDemo.cs.
using System.Runtime.CompilerServices;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demo of <see cref="Gui.InputText(ref string, int)"/> and
/// <see cref="Gui.InputNumeric{TNumeric}(ref TNumeric, int)"/>, etc.
/// </summary>
class InputDemo : ManualBase, IManual
{
int intValue = 1;
float floatValue = 1f;
double doubleValue = 1d;
uint uintValue = 1;
ulong ulongValue = 1;
byte byteValue = 1;
sbyte sbyteValue = 1;
short shortValue = 1;
ushort ushortValue = 1;
decimal decimalValue = 1m;
string stringValue = "ABCabc";
int formatIntValue = 1;
// Formatters for integer formatting examples
//
// General
readonly IntFormatter intFormatter_G = new("G");
// Uppercase hexadecimal
readonly IntFormatter intFormatter_X = new("X");
// Decimal format. Pads with leading zeros if the specified number of digits is not met
readonly IntFormatter intFormatter_D5 = new("D5");
// Lowercase hexadecimal
readonly IntFormatter intFormatter_x = new("x");
// Number format with thousand separators
readonly IntFormatter intFormatter_N = new("N");
public InputDemo(ManualBaseResource p) : base(p)
{
}
public void Draw()
{
// Draw numeric input fields for different types
Gui.Heading(nameof(Gui.InputNumeric));
DrawNumeric("int", ref intValue);
DrawNumeric("float", ref floatValue);
DrawNumeric("double", ref doubleValue);
DrawNumeric("uint", ref uintValue);
DrawNumeric("ulong", ref ulongValue);
DrawNumeric("byte", ref byteValue);
DrawNumeric("sbyte", ref sbyteValue);
DrawNumeric("short", ref shortValue);
DrawNumeric("ushort", ref ushortValue);
DrawNumeric("decimal", ref decimalValue);
// Draw integer formatting examples
Gui.Heading("Int format");
DrawFormat("G", ref formatIntValue, intFormatter_G);
DrawFormat("X", ref formatIntValue, intFormatter_X);
DrawFormat("x", ref formatIntValue, intFormatter_x);
DrawFormat("D5", ref formatIntValue, intFormatter_D5);
DrawFormat("N", ref formatIntValue, intFormatter_N);
// Draw string input text
Gui.Heading("InputText");
using var rects = LayoutBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(rects.R0).Text("text");
Gui.NextRect(rects.R1).InputText(ref stringValue);
}
void DrawFormat(string text, ref int v, IntFormatter intFormatter, [CallerLineNumber] int lineNumber = 0)
{
using var rects = LayoutBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(rects.R0).Text(text);
// Apply the integer formatter and draw the numeric input field.
using var s = Style.TypeFormatters.Begin(intFormatter);
Gui.NextRect(rects.R1).InputNumeric(ref v, lineNumber);
}
void DrawNumeric<T>(string text, ref T value, [CallerLineNumber] int lineNumber = 0)
{
using var rects = LayoutBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(rects.R0).Text(text);
Gui.NextRect(rects.R1).InputNumeric(ref value, lineNumber);
}
}
}