API ReferenceSandbox.UI

Labelclass

A generic text label. Can be made editable.

object→Panel→Label
Namespace
Sandbox.UI
Assembly
Sandbox.Engine
Declaration
public class Sandbox.UI.Label : Sandbox.UI.Panel

Constructors2

Showing 2 constructors

Methods32

Showing 32 methods

protected void CaretSantity()PROTECTED

Ensure the text caret and selection are in sane positions, that is, not outside of the text bounds.

Returns:void—

public void ClearStyleSpans()PUBLIC

Removes all style spans, retaining the buffer for reuse. Does not change text or selection.

Returns:void—

public virtual void FinalLayout(Vector2 offset)PUBLICVIRTUAL

ParameterTypeDescription
offsetVector2—
Returns:void—

public Sandbox.Rect GetCaretRect(int i)PUBLIC

ParameterTypeDescription
iint—
Returns:Rect—

public int GetCharacterAtScreenPosition(Vector2 pos)PUBLIC

Returns the text element under a screen position, or -1 outside the text. Unlike caret hit testing, both halves of a character return the same index.

ParameterTypeDescription
posVector2—
Returns:int—

public virtual string GetClipboardValue(bool cut)PUBLICVIRTUAL

ParameterTypeDescription
cutbool—
Returns:string—

public int GetLetterAt(Vector2 pos)PUBLIC

ParameterTypeDescription
posVector2—
Returns:int—

public int GetLetterAtScreenPosition(Vector2 pos)PUBLIC

ParameterTypeDescription
posVector2—
Returns:int—

public string GetSelectedText()PUBLIC

Returns the selected text.

Returns:string—

public System.Collections.Generic.List`1<int> GetWordBoundaryIndices()PUBLIC

Returns a list of positions in the text of each side of each word within the `Sandbox.UI.Label.Text`. This is used for Control + Arrow Key navigation.

Returns:List<int>—

public bool HasSelection()PUBLIC

Returns:bool—

public void InsertText(string text, int pos, System.Nullable`1<int> endpos = null)PUBLIC

ParameterTypeDescription
textstring—
posint—
endpos = nullNullable<int>—
Returns:void—

public virtual void LanguageChanged()PUBLICVIRTUAL

When the language changes, if we're token based we need to update to the new phrase.

Returns:void—

public void MoveCaretLine(int offset_line, bool select)PUBLIC

Move the text caret to next or previous line.

ParameterTypeDescription
offset_lineintHow many lines to offset. Negative values move up.
selectboolWhether to also add the characters we passed by to the selection.
Returns:void—

public void MoveCaretPos(int delta, bool select = False)PUBLIC

Move the text caret by given amount.

ParameterTypeDescription
deltaintHow many characters to the right to move. Negative values move left.
select = FalseboolWhether to also add the characters we passed by to the selection.
Returns:void—

public void MoveToLineEnd(bool select = False)PUBLIC

Move the text caret to the end of the current line.

ParameterTypeDescription
select = FalseboolWhether to also add the characters we passed by to the selection.
Returns:void—

public void MoveToLineStart(bool select = False)PUBLIC

Move the text caret to the start of the current line.

ParameterTypeDescription
select = FalseboolWhether to also add the characters we passed by to the selection.
Returns:void—

public void MoveToWordBoundaryLeft(bool select)PUBLIC

Move the text caret to the closest word start or end to the left of current position. This simulates holding Control key while pressing left arrow key.

ParameterTypeDescription
selectboolWhether to also add the characters we passed by to the selection.
Returns:void—

public void MoveToWordBoundaryRight(bool select)PUBLIC

Move the text caret to the closest word start or end to the right of current position. This simulates holding Control key while pressing right arrow key.

ParameterTypeDescription
selectboolWhether to also add the characters we passed by to the selection.
Returns:void—

public virtual void OnDeleted()PUBLICVIRTUAL

Returns:void—

public virtual void OnDraw(Sandbox.Painter painter)PUBLICVIRTUAL

ParameterTypeDescription
painterPainter—
Returns:void—

public virtual void RemoveText(int start, int count)PUBLICVIRTUAL

Remove given amount of characters from the label at given `start` position.

ParameterTypeDescription
startint—
countint—
Returns:void—

public void ReplaceSelection(string str)PUBLIC

Replace the currently selected text with given text. The caret ends up after the replacement.

ParameterTypeDescription
strstring—
Returns:void—

public void ScrollToCaret()PUBLIC

Put the caret within the visible region.

Returns:void—

public void SelectWord(int wordPos)PUBLIC

Select a work at given word position.

ParameterTypeDescription
wordPosint—
Returns:void—

public void SetCaretPosition(int pos, bool select = False)PUBLIC

Set the text caret position to the given index.

ParameterTypeDescription
posintWhere to move the text caret to within the text.
select = FalseboolWhether to also add the characters we passed by to the selection.
Returns:void—

public virtual void SetContent(string value)PUBLICVIRTUAL

ParameterTypeDescription
valuestring—
Returns:void—

public virtual void SetProperty(string name, string value)PUBLICVIRTUAL

ParameterTypeDescription
namestring—
valuestring—
Returns:void—

public void SetSelection(int start, int end)PUBLIC

Sets the text selection, preserving its anchor and direction.

ParameterTypeDescription
startint—
endint—
Returns:void—

public void SetStyleSpan(int start, int end, Sandbox.UI.Styles style)PUBLIC

Styles a range of displayed plain text. Start is inclusive and end is exclusive, in UTF-16 units after whitespace normalization and text-transform. Supply spans in order without overlaps. Supported properties match rich text: font, color, background, spacing and text decorations. Reuse styles between spans; after changing a style, clear and resubmit the spans. Spans are cleared when Text changes, and are not used for HTML or inline paragraphs.

ParameterTypeDescription
startint—
endint—
styleStyles—
Returns:void—

Properties12

Showing 12 properties

public int Sandbox.UI.Label.CaretPosition { get; set; }PUBLICGETSET

Position of the text cursor/caret within the text, at which newly typed characters are inserted. Setting it keeps it inside the text and scrolls to put it on screen - everything that moves the caret goes through here, so nothing has to remember to do either.

Returns:int—

public bool Sandbox.UI.Label.IsRich { get; set; }PUBLICGETSET

Set to true if this is rich text. This means it can support some inline html elements.

Returns:bool—

public bool Sandbox.UI.Label.Multiline { get; set; }PUBLICGETSET

Enables multi-line support for editing purposes.

Returns:bool—

public System.Action`1<Sandbox.Html.INode> Sandbox.UI.Label.OnNodeClicked { get; set; }PUBLICGETSET

Called when a node within rich text (`Sandbox.UI.Label.IsRich`) is clicked, with the clicked node. When set, this replaces the default behaviour - which opens a valid http/https `href` on an anchor in the user's browser - letting you inspect the node and handle custom anchor schemes or open in-game popups.

Returns:Action<INode>—

public bool Sandbox.UI.Label.Selectable { get; set; }PUBLICGETSET

Can be selected

Returns:bool—

public Color Sandbox.UI.Label.SelectionColor { get; set; }PUBLICGETSET

The color used for text selection highlight

Returns:Color—

public int Sandbox.UI.Label.SelectionEnd { get; set; }PUBLICGETSET

Returns:int—

public int Sandbox.UI.Label.SelectionStart { get; set; }PUBLICGETSET

Returns:int—

public bool Sandbox.UI.Label.ShouldDrawSelection { get; set; }PUBLICGETSET

Returns:bool—

public virtual string Sandbox.UI.Label.Text { get; set; }PUBLICVIRTUALGETSET

Text to display on the label.

Returns:string—

public int Sandbox.UI.Label.TextLength { get; set; }PUBLICGETSET

Amount of characters in the text of the text entry. Not bytes.

Returns:int—

public bool Sandbox.UI.Label.Tokenize { get; set; }PUBLICGETSET

If true and the text starts with #, it will be treated as a language token.

Returns:bool—

On this page

Constructorspublic Label()public Label(System.String text, System.String classname = null)Methodsprotected System.Void CaretSantity()public System.Void ClearStyleSpans()public virtual System.Void FinalLayout(Vector2 offset)public Sandbox.Rect GetCaretRect(System.Int32 i)public System.Int32 GetCharacterAtScreenPosition(Vector2 pos)public virtual System.String GetClipboardValue(System.Boolean cut)public System.Int32 GetLetterAt(Vector2 pos)public System.Int32 GetLetterAtScreenPosition(Vector2 pos)public System.String GetSelectedText()public System.Collections.Generic.List`1<System.Int32> GetWordBoundaryIndices()public System.Boolean HasSelection()public System.Void InsertText(System.String text, System.Int32 pos, System.Nullable`1<System.Int32> endpos = null)public virtual System.Void LanguageChanged()public System.Void MoveCaretLine(System.Int32 offset_line, System.Boolean select)public System.Void MoveCaretPos(System.Int32 delta, System.Boolean select = False)public System.Void MoveToLineEnd(System.Boolean select = False)public System.Void MoveToLineStart(System.Boolean select = False)public System.Void MoveToWordBoundaryLeft(System.Boolean select)public System.Void MoveToWordBoundaryRight(System.Boolean select)protected virtual System.Void OnClick(Sandbox.UI.MousePanelEvent e)public virtual System.Void OnDeleted()public virtual System.Void OnDraw(Sandbox.Painter painter)protected virtual System.Void OnMouseMove(Sandbox.UI.MousePanelEvent e)public virtual System.Void RemoveText(System.Int32 start, System.Int32 count)public System.Void ReplaceSelection(System.String str)public System.Void ScrollToCaret()public System.Void SelectWord(System.Int32 wordPos)public System.Void SetCaretPosition(System.Int32 pos, System.Boolean select = False)public virtual System.Void SetContent(System.String value)public virtual System.Void SetProperty(System.String name, System.String value)public System.Void SetSelection(System.Int32 start, System.Int32 end)public System.Void SetStyleSpan(System.Int32 start, System.Int32 end, Sandbox.UI.Styles style)Propertiespublic System.Int32 Sandbox.UI.Label.CaretPosition { get; set; }public System.Boolean Sandbox.UI.Label.IsRich { get; set; }public System.Boolean Sandbox.UI.Label.Multiline { get; set; }public System.Action`1<Sandbox.Html.INode> Sandbox.UI.Label.OnNodeClicked { get; set; }public System.Boolean Sandbox.UI.Label.Selectable { get; set; }public Color Sandbox.UI.Label.SelectionColor { get; set; }public System.Int32 Sandbox.UI.Label.SelectionEnd { get; set; }public System.Int32 Sandbox.UI.Label.SelectionStart { get; set; }public System.Boolean Sandbox.UI.Label.ShouldDrawSelection { get; set; }public virtual System.String Sandbox.UI.Label.Text { get; set; }public System.Int32 Sandbox.UI.Label.TextLength { get; set; }public System.Boolean Sandbox.UI.Label.Tokenize { get; set; }Metadata