Skip to main content

Text

text

See the TextDemo.cs.

using Gridrand.Contracts;

namespace Gridrand.RimGui.Manual
{
/// <summary>
/// Demonstrates various text-related GUI widgets.
/// </summary>
class TextDemo : ManualBase, IManual
{
// 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.BeginHorizontal())
{
// 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).ColorPreview(Color.Gray);
Gui.NextRect(rect).Text(text);

Gui.Heading("MultiLineText");
Gui.MultiLineText("1.MultiLine\n2.MultiLine\n3.MultiLine");

Gui.Heading("Heading");

}
}
}