Input
See the InputDemo class.
// 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 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 intValue, intFormatter_G);
DrawFormat("X", ref intValue, intFormatter_X);
DrawFormat("x", ref intValue, intFormatter_x);
DrawFormat("D5", ref intValue, intFormatter_D5);
DrawFormat("N", ref intValue, intFormatter_N);
// Draw string input text
Gui.Heading("InputText");
using var rects = RectsBuilder.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 = RectsBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(rects.R0).Text(text);
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 = RectsBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(rects.R0).Text(text);
Gui.NextRect(rects.R1).InputNumeric(ref value, lineNumber);
}