API ReferenceSandbox.UI

Labelclass

A generic text label. Can be made editable.

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

Constructors2

Showing 2 constructors

Methods29

Showing 29 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 virtual void FinalLayout(Vector2 offset)PUBLICVIRTUAL

ParameterTypeDescription
offsetVector2
Returns:void

public Sandbox.Rect GetCaretRect(int i)PUBLIC

ParameterTypeDescription
iint
Returns:Rect

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()PUBLICVIRTUAL

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.

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.

ParameterTypeDescription
startint
endint
Returns:void

Properties11

Showing 11 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.

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 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 virtual System.Void FinalLayout(Vector2 offset)public Sandbox.Rect GetCaretRect(System.Int32 i)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()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)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.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