InputText
See the InputText.cs.
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demo of <see cref="Gui.InputText(ref string, int)"/> demo.
/// </summary>
class InputTextDemo : ManualBase, IManual
{
string stringValue0 = "01234";
string stringValue1 = "01234";
string stringValue2 = "01234";
string tempStringValue2;
public InputTextDemo(ManualBaseResource p) : base(p)
{
tempStringValue2 = stringValue2;
}
public void Draw()
{
DrawAlwaysApply();
DrawEnterKey();
DrawUnfocused();
}
void DrawAlwaysApply()
{
Gui.Heading("Always Apply");
Gui.Text($"Current: {stringValue0}");
Gui.InputText(ref stringValue0);
}
void DrawEnterKey()
{
Gui.Heading("Apply on Enter Key Only");
Gui.Text($"Current: {stringValue1}");
var tempStringValue = stringValue1;
// Apply the change only when Enter was pressed
if (Gui.InputText(ref tempStringValue).IsNewLineEntered)
{
stringValue1 = tempStringValue;
}
}
void DrawUnfocused()
{
Gui.Heading("Apply on Focus Loss");
Gui.Text($"Current: {stringValue2}");
var isFocused = Ctx.GetFocusedWidgetInfo()?.Type == typeof(InputTextWidget);
Gui.InputText(ref tempStringValue2);
// When focus is lost
if (isFocused && !Ctx.IsFocused(Ctx.GetLastWidgetId()))
{
stringValue2 = tempStringValue2;
}
}
}
}