Text
See the TextDemo.cs.
using Gridrand.Contracts;
namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demonstrates various text-related GUI widgets.
/// </summary>
class TextDemo : ManualBase, IManual
{
int labelTextInt = 123;
float labelTextFloat = 0.12345f;
string editableText = "01234";
// Formatter for floating point numbers to display them with 5 decimal places
readonly FloatFormatter floatFormatter = new("F5");
// Custom text style
readonly Gridrand.Contracts.Rendering.TextStyle textStyle = new();
public TextDemo(ManualBaseResource p) : base(p)
{
// Applying color ranges to specific text positions
textStyle.Insert(new RangeColor(Color32.DarkRed, 1..2));
textStyle.Insert(new RangeColor(Color32.DarkGreen, 3..5));
}
public void Draw()
{
Gui.Heading("Text");
Gui.Text("ABCDE");
using (Ctx.Horizontal())
{
// The default text width spans the entire horizontal space,
// so the width of the next text is set to match the length of the string "Left".
Gui.NextTextWidth("Left").Text("Left");
Gui.Text("Right");
}
// Specifies the text color within the scope.
using (Style.Text.Colors.Begin(Color32.DarkGreen))
Gui.Text("Green");
using (Style.Text.Colors.Begin(Color32.DarkRed))
Gui.Text("Red");
// Specifies the text style within the scope.
using (Style.Text.Styles.Begin(textStyle))
Gui.Text("0123456789");
// Highlighting specific parts of text
var text = "Highlight";
var rect = Ctx.AllocateRect();
var highlightRect = CharInfosHelper.GetMatchedTextRect(rect, text, "ghlig");
if (highlightRect != null)
Gui.NextRect(highlightRect.Value).Color(Color.Gray);
Gui.NextRect(rect).Text(text);
Gui.Heading("MultiLineText");
Gui.MultiLineText("1.MultiLine\n2.MultiLine\n3.MultiLine");
Gui.Heading("LabelText");
Gui.LabelTextNumeric("LabelText int", labelTextInt);
// Formatting a float label text with the specified formatter
using (Style.TypeFormatters.Begin(floatFormatter))
{
Gui.LabelTextNumeric("LabelText float", labelTextFloat);
}
// A text that becomes editable on double-click.
Gui.Heading("EditableText");
Gui.EditableText(ref editableText);
Gui.Heading("Heading");
Gui.Heading("Hyperlink");
// Hyperlink example, with a range specified for clickable text
if (Gui.Hyperlink("Hyperlink", 3..7))
{
Logger.Debug("Pressed Hyperlink");
}
}
}
}