Skip to main content

Text

See the TextDemo class.

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.TextStyle textStyle = new();

public TextDemo(ManualProperties p) : base(p)
{
// Applying color ranges to specific text positions
textStyle.Insert(new RangeColor(Color.Red, 1..2));
textStyle.Insert(new RangeColor(Color.Green, 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(Color.Green))
Gui.Text("Green");
using (Style.Text.Colors.Begin(Color.Red))
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 = CharFixedMap.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.LabelText("LabelText int", labelTextInt);

// Formatting a float label text with the specified formatter
using (Style.TypeFormatters.Begin(floatFormatter))
{
Gui.LabelText("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");
}
}