Skip to main content

Text

text

See the TextDemo.cs.

using Gridrand.RimGui.Manual;

namespace Gridrand.RimGui.Extensions.Manual
{
/// <summary>
/// <see cref="GuiUtil.Text(Gui, bool, int)"/>,
/// <see cref="GuiUtil.Text(Gui, char, int)"/>,
/// <see cref="GuiUtil.TextNumeric{TNumeric}(Gui, TNumeric, int)"/>,
/// <see cref="GuiUtil.EditableText(Gui, ref string, int)"/>,
/// <see cref="GuiUtil.Hyperlink(Gui, System.ReadOnlySpan{char}, System.Range, int)"/> demo.
/// </summary>
class TextDemo : ManualBase, IManual
{
string editableText = "01234";

public TextDemo(ManualBaseResource p) : base(p)
{
}

public void Draw()
{
Gui.Heading("Text");
// Layout for displaying a boolean value.
using var boolRects = LayoutBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(boolRects.R0).Text("bool");
Gui.NextRect(boolRects.R1).Text(true);

// Layout for displaying a character value.
using var charRects = LayoutBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(charRects.R0).Text("char");
Gui.NextRect(charRects.R1).Text('a');

Gui.Heading("TextNumeric");
DrawLabelTextNumeric("int", 12345);
DrawLabelTextNumeric("float", 123.45f);
DrawLabelTextNumeric("double", 123.45d);
DrawLabelTextNumeric("uint", (uint)12345);
DrawLabelTextNumeric("ulong", (ulong)12345);
DrawLabelTextNumeric("byte", (byte)123);
DrawLabelTextNumeric("sbyte", (sbyte)123);
DrawLabelTextNumeric("short", (short)12345);
DrawLabelTextNumeric("ushort", (ushort)12345);
DrawLabelTextNumeric("decimal", (decimal)123.45);

// A text that becomes editable on double-click.
Gui.Heading("EditableText");
Gui.EditableText(ref editableText);

Gui.Heading("Hyperlink");
// Hyperlink example, with a range specified for clickable text
if (Gui.Hyperlink("Hyperlink", 3..7))
{
Logger.Debug("Clicked Hyperlink");
}
}

// Helper method to draw a label and a numeric value using `TextNumeric`.
void DrawLabelTextNumeric<TNumeric>(string text, TNumeric v)
{
using var rects = LayoutBuilder.Ratio(0.3f).Ratio(0.7f).BuildAllocatedHorizontal();
Gui.NextRect(rects.R0).Text(text);
Gui.NextRect(rects.R1).TextNumeric(v);
}
}
}