Class RichTextLabel

Namespace
Forma
Assembly
Forma.dll

Lightweight BBCode label with styled text runs. It intentionally concentrates on the common authoring tags (b, i, u, s/strike, color, and br) while preserving the retained Control model and plain-text Text projection.

[TemplatePart("PART_RichTextPresenter", typeof(Container), true)]
public class RichTextLabel : TemplatedControl, IAddChild<Control>, IAddChild, INotifyPropertyChanged, IDisposable
Inheritance
RichTextLabel
Implements
Derived
Inherited Members

Constructors

RichTextLabel()

public RichTextLabel()

Fields

RichTextPresenterPartName

public const string RichTextPresenterPartName = "PART_RichTextPresenter"

Field Value

string

Properties

AccessibilityName

public override string AccessibilityName { get; }

Property Value

string

AccessibilityRole

public override AccessibilityRole AccessibilityRole { get; }

Property Value

AccessibilityRole

Autowrap

public bool Autowrap { get; set; }

Property Value

bool

AutowrapMode

public LabelAutowrapMode AutowrapMode { get; set; }

Property Value

LabelAutowrapMode

BbcodeEnabled

public bool BbcodeEnabled { get; set; }

Property Value

bool

ContextMenuEnabled

Enables the retained Copy/Select All context menu, matching Godot's context_menu_enabled.

public bool ContextMenuEnabled { get; set; }

Property Value

bool

DeselectOnFocusLossEnabled

Whether selection is cleared when keyboard focus moves to another control, matching Godot's deselect_on_focus_loss_enabled.

public bool DeselectOnFocusLossEnabled { get; set; }

Property Value

bool

DragAndDropSelectionEnabled

Whether pressing inside an existing selection can provide its text through the Control drag/drop lifecycle.

public bool DragAndDropSelectionEnabled { get; set; }

Property Value

bool

FitContent

public bool FitContent { get; set; }

Property Value

bool

Font

public SpriteFont Font { get; set; }

Property Value

SpriteFont

FontColor

public Color? FontColor { get; set; }

Property Value

Color?

HasSelection

Whether this label currently owns a non-empty selection.

public bool HasSelection { get; }

Property Value

bool

HorizontalAlignment

public HorizontalAlignment HorizontalAlignment { get; set; }

Property Value

HorizontalAlignment

IsVerticalScrollBarVisible

Whether the retained vertical scrollbar is currently presented for overflowing, active document content.

public bool IsVerticalScrollBarVisible { get; }

Property Value

bool

LetterSpacing

public float LetterSpacing { get; set; }

Property Value

float

MetaColor

Color used for metadata links when the span has no explicit foreground color.

public Color MetaColor { get; set; }

Property Value

Color

MetaRegions

Current deterministic hit regions for spans carrying metadata.

public IReadOnlyList<RichTextMetaRegion> MetaRegions { get; }

Property Value

IReadOnlyList<RichTextMetaRegion>

MetaUnderline

Whether metadata spans use the conventional Godot link underline.

public bool MetaUnderline { get; set; }

Property Value

bool

MultiClickTimeout

Maximum interval between text clicks that belong to the same double/triple-click gesture.

public TimeSpan MultiClickTimeout { get; set; }

Property Value

TimeSpan

MultiClickTolerance

Maximum pointer displacement between text clicks that belong to the same double/triple-click gesture.

public int MultiClickTolerance { get; set; }

Property Value

int

Padding

public Thickness Padding { get; set; }

Property Value

Thickness

ScrollActive

Enables wheel scrolling and the retained scroll viewport, matching Godot's scroll_active.

public bool ScrollActive { get; set; }

Property Value

bool

ScrollFollowing

Automatically follows newly appended content to its end, matching Godot's scroll_following.

public bool ScrollFollowing { get; set; }

Property Value

bool

ScrollOffset

Current vertical document offset in pixels, clamped to the retained content range.

public int ScrollOffset { get; set; }

Property Value

int

ScrollStep

Pixels moved for one wheel notch. The default uses the document line height.

public int ScrollStep { get; set; }

Property Value

int

SelectionAutoScrollEnabled

Enables scrolling a document while a captured text-selection gesture is held beyond its vertical viewport.

public bool SelectionAutoScrollEnabled { get; set; }

Property Value

bool

SelectionAutoScrollSpeed

Base selection auto-scroll velocity in pixels per second. Godot's 2-pixel 50 ms timer step corresponds to 40.

public float SelectionAutoScrollSpeed { get; set; }

Property Value

float

SelectionColor

Theme-like background color drawn behind selected document characters.

public Color SelectionColor { get; set; }

Property Value

Color

SelectionEnabled

Enables Godot-style text selection for this read-only document.

public bool SelectionEnabled { get; set; }

Property Value

bool

ShortcutKeysEnabled

Enables focused select-all and copy shortcuts, matching Godot's shortcut_keys_enabled.

public bool ShortcutKeysEnabled { get; set; }

Property Value

bool

Spans

public IReadOnlyList<RichTextSpan> Spans { get; }

Property Value

IReadOnlyList<RichTextSpan>

TableCellWidth

Fallback width for one rendered RichText table cell when no full shaping/layout engine is installed.

public int TableCellWidth { get; set; }

Property Value

int

Text

public string Text { get; set; }

Property Value

string

TextDirection

public TextDirection TextDirection { get; set; }

Property Value

TextDirection

UIFont

public UIFont UIFont { get; set; }

Property Value

UIFont

VerticalAlignment

public VerticalAlignment VerticalAlignment { get; set; }

Property Value

VerticalAlignment

Methods

AddHorizontalRule(int, int, Color?, HorizontalAlignment, bool, bool)

Adds a Godot-style horizontal rule paragraph. Percentage dimensions use the content width.

public void AddHorizontalRule(int width = 90, int height = 2, Color? color = null, HorizontalAlignment alignment = HorizontalAlignment.Center, bool widthInPercent = true, bool heightInPercent = false)

Parameters

width int
height int
color Color?
alignment HorizontalAlignment
widthInPercent bool
heightInPercent bool

AddImage(Texture2D, float, float, Color?, object, string)

Adds an inline image, corresponding to Godot's add_image() API.

public void AddImage(Texture2D image, float width = 0, float height = 0, Color? modulate = null, object metadata = null, string altText = "")

Parameters

image Texture2D
width float
height float
modulate Color?
metadata object
altText string

AppendBbcode(string)

public virtual void AppendBbcode(string bbcode)

Parameters

bbcode string

AppendText(string)

public void AppendText(string text)

Parameters

text string

ArrangeChildren()

protected override void ArrangeChildren()

Clear()

public void Clear()

Deselect()

Clears the current selection, matching Godot's deselect().

public void Deselect()

GetAutowrapMode()

public LabelAutowrapMode GetAutowrapMode()

Returns

LabelAutowrapMode

GetContentHeight()

Returns the document's retained content height in pixels.

public int GetContentHeight()

Returns

int

GetContentWidth()

Returns the widest retained visual-line width in pixels.

public int GetContentWidth()

Returns

int

GetCurrentTableColumn()

public int GetCurrentTableColumn()

Returns

int

GetDragData(Point)

Returns the selected text when a retained drag begins from an existing selection.

public override object GetDragData(Point position)

Parameters

position Point

Returns

object

GetLineCount()

Returns the document's retained visual line count. Explicit and automatic wrapped lines are included.

public int GetLineCount()

Returns

int

GetLineHeight(int)

Returns the retained height of a visual line, or zero for an invalid line.

public int GetLineHeight(int line)

Parameters

line int

Returns

int

GetLineOffset(int)

Returns the content-space offset of a visual line, or zero for an invalid line.

public float GetLineOffset(int line)

Parameters

line int

Returns

float

GetLineRange(int)

Returns the retained plain-text range covered by a visual line, using Microsoft.Xna.Framework.Point.X for the inclusive start and Microsoft.Xna.Framework.Point.Y for the exclusive end.

public Point GetLineRange(int line)

Parameters

line int

Returns

Point

GetLineWidth(int)

Returns the retained width of a visual line, or zero for an invalid line.

public int GetLineWidth(int line)

Parameters

line int

Returns

int

GetMenu()

Returns the retained context popup, equivalent to Godot's get_menu().

public PopupMenu GetMenu()

Returns

PopupMenu

GetMetaUnderPosition(Point)

Returns metadata at the given screen-space position, equivalent to Godot's get_meta_under_mouse().

public object GetMetaUnderPosition(Point position)

Parameters

position Point

Returns

object

GetMinimumSize()

public override Vector2 GetMinimumSize()

Returns

Vector2

GetParagraphCount()

Returns the number of explicit newline-delimited document paragraphs.

public int GetParagraphCount()

Returns

int

GetParagraphOffset(int)

Returns the content-space offset of an explicit paragraph, or zero for an invalid paragraph.

public float GetParagraphOffset(int paragraph)

Parameters

paragraph int

Returns

float

GetScrollMaximum()

Returns the maximum available vertical offset for the current bounds.

public int GetScrollMaximum()

Returns

int

GetScrollOffset()

public int GetScrollOffset()

Returns

int

GetSelectedText()

Returns the selected plain-text projection, matching Godot's get_selected_text().

public string GetSelectedText()

Returns

string

GetSelectionFrom()

Zero-based inclusive selection start, or -1 when no selection is active.

public int GetSelectionFrom()

Returns

int

GetSelectionLineOffset()

Returns the retained visual-line offset of the selection start, or -1 when there is no selection.

public float GetSelectionLineOffset()

Returns

float

GetSelectionTo()

Zero-based exclusive selection end, or -1 when no selection is active.

public int GetSelectionTo()

Returns

int

GetText()

public string GetText()

Returns

string

GetVScrollBar()

Returns the retained vertical scrollbar, corresponding to Godot's get_v_scroll_bar().

public VScrollBar GetVScrollBar()

Returns

VScrollBar

GetVisibleContentRect()

Returns the screen-space clipped content viewport, corresponding to Godot's get_visible_content_rect().

public Rectangle GetVisibleContentRect()

Returns

Rectangle

GetVisibleLineCount()

Returns the number of visual lines intersecting the clipped document viewport.

public int GetVisibleLineCount()

Returns

int

GetVisibleParagraphCount()

Returns the number of explicit paragraphs intersecting the clipped document viewport.

public int GetVisibleParagraphCount()

Returns

int

IsDeselectOnFocusLossEnabled()

public bool IsDeselectOnFocusLossEnabled()

Returns

bool

IsDragAndDropSelectionEnabled()

public bool IsDragAndDropSelectionEnabled()

Returns

bool

IsScrollActive()

public bool IsScrollActive()

Returns

bool

IsScrollFollowing()

public bool IsScrollFollowing()

Returns

bool

ParseBbcode(string)

public void ParseBbcode(string bbcode)

Parameters

bbcode string

Pop()

public void Pop()

PushBgColor(Color)

public void PushBgColor(Color color)

Parameters

color Color

PushBold()

public void PushBold()

PushCell()

Starts the next cell in the active table, matching Godot's push_cell().

public void PushCell()

PushColor(Color)

public void PushColor(Color color)

Parameters

color Color

PushIndent(int)

Starts an indented rich-text block. Call Pop() after appending its content.

public void PushIndent(int level = 1)

Parameters

level int

PushItalics()

public void PushItalics()

PushList(int, RichTextListType, bool, string)

Starts a list item with a Godot-style marker. Call Pop() after appending its content.

public void PushList(int level = 1, RichTextListType type = RichTextListType.Dots, bool capitalize = false, string bullet = "•")

Parameters

level int
type RichTextListType
capitalize bool
bullet string

PushMeta(object)

Starts a Godot-style clickable metadata span. Call Pop() after appending its text.

public void PushMeta(object meta)

Parameters

meta object

PushStrikethrough()

public void PushStrikethrough()

PushTable(int, string)

Starts a Godot-style table. Call PushCell() for each cell and Pop() to close the table.

public void PushTable(int columns, string name = "")

Parameters

columns int
name string

PushUnderline()

public void PushUnderline()

ScrollToLine(int)

Scrolls the requested zero-based visual line to the top of the retained viewport.

public void ScrollToLine(int line)

Parameters

line int

ScrollToParagraph(int)

Scrolls the requested zero-based explicit paragraph to the top of the retained viewport.

public void ScrollToParagraph(int paragraph)

Parameters

paragraph int

ScrollToSelection()

Scrolls the visual line containing the selection start to the top of the document viewport.

public void ScrollToSelection()

Search(string, bool, bool)

Finds case-insensitive plain-text content, selects the match, and reveals its visual line; optionally continues from the active selection or searches backward.

public bool Search(string text, bool fromSelection = false, bool searchPrevious = false)

Parameters

text string
fromSelection bool
searchPrevious bool

Returns

bool

Select(int, int)

Sets a normalized plain-text selection. This retained-layer convenience is intended for selection gestures.

public void Select(int from, int to)

Parameters

from int
to int

SelectAll()

Selects the complete plain-text document when SelectionEnabled is enabled.

public void SelectAll()

SetAutowrapMode(LabelAutowrapMode)

public void SetAutowrapMode(LabelAutowrapMode mode)

Parameters

mode LabelAutowrapMode

SetDeselectOnFocusLossEnabled(bool)

public void SetDeselectOnFocusLossEnabled(bool enabled)

Parameters

enabled bool

SetDragAndDropSelectionEnabled(bool)

public void SetDragAndDropSelectionEnabled(bool enabled)

Parameters

enabled bool

SetScrollActive(bool)

public void SetScrollActive(bool active)

Parameters

active bool

SetScrollFollow(bool)

public void SetScrollFollow(bool following)

Parameters

following bool

SetScrollOffset(int)

public void SetScrollOffset(int offset)

Parameters

offset int

SetText(string)

public void SetText(string text)

Parameters

text string

Events

CopyRequested

Raised after a copy command submits text to Clipboard.

public event Action<RichTextLabel, string> CopyRequested

Event Type

Action<RichTextLabel, string>

MetaClicked

public event Action<RichTextLabel, object> MetaClicked

Event Type

Action<RichTextLabel, object>