public class Sandbox.UI.Label : Sandbox.UI.Panel
A generic text label. Can be made editable.
Related Guides
Broader workflow and conceptual references connected to this API.
When creating your own Classes/Structs/Assets/ect, you'll sometimes want custom editors that pair with them. For example, a Gradient Editor so you can visually see what the Gradient looks like instead of editing the Gradient as if it were a Struct with a list of Colours.
Editor UI is built entirely out of Widgets. Widgets are different from Panels, which are used for in-game UI. Widgets can be various elements or components, such as labels, buttons, text boxes, trees, or images.
When displaying text such as Hello World, you should instead use a localization token like #menu.helloworld. This will automatically replace the text with the corresponding language set by the user when set on a Label, allowing you to easily support multiple languages.
Razor Component allow you to define some content to show inside another razor file. This makes it easy to create Panels that are more agile and reusable.
UI can also be created using Razor, which allows you to use web-like HTML/CSS to create and style each Panel while also being able to leverage C#.
It is common to have a file system like this:
Constructors
Showing 2 constructors
No results match this filter.
Methods
Showing 29 methods
protected void CaretSantity()
Ensure the text caret and selection are in sane positions, that is, not outside of the text bounds.
public virtual void FinalLayout(Vector2 offset)
public Sandbox.Rect GetCaretRect(int i)
public virtual string GetClipboardValue(bool cut)
public int GetLetterAt(Vector2 pos)
public int GetLetterAtScreenPosition(Vector2 pos)
public string GetSelectedText()
Returns the selected text.
public System.Collections.Generic.List`1<int> GetWordBoundaryIndices()
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.
public bool HasSelection()
public void InsertText(string text, int pos, System.Nullable`1<int> endpos = null)
Parameters
endpos: Default: null
public virtual void LanguageChanged()
When the language changes, if we're token based we need to update to the new phrase.
public void MoveCaretLine(int offset_line, bool select)
Move the text caret to next or previous line.
Parameters
offset_line: How many lines to offset. Negative values move up.select: Whether to also add the characters we passed by to the selection.
public void MoveCaretPos(int delta, bool select = False)
Move the text caret by given amount.
Parameters
delta: How many characters to the right to move. Negative values move left.select: Whether to also add the characters we passed by to the selection. Default: False
public void MoveToLineEnd(bool select = False)
Move the text caret to the end of the current line.
Parameters
select: Whether to also add the characters we passed by to the selection. Default: False
public void MoveToLineStart(bool select = False)
Move the text caret to the start of the current line.
Parameters
select: Whether to also add the characters we passed by to the selection. Default: False
public void MoveToWordBoundaryLeft(bool select)
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.
Parameters
select: Whether to also add the characters we passed by to the selection.
public void MoveToWordBoundaryRight(bool select)
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.
Parameters
select: Whether to also add the characters we passed by to the selection.
protected virtual void OnClick(Sandbox.UI.MousePanelEvent e)
public virtual void OnDeleted()
public virtual void OnDraw()
protected virtual void OnMouseMove(Sandbox.UI.MousePanelEvent e)
public virtual void RemoveText(int start, int count)
Remove given amount of characters from the label at given `start` position.
public void ReplaceSelection(string str)
Replace the currently selected text with given text.
public void ScrollToCaret()
Put the caret within the visible region.
public void SelectWord(int wordPos)
Select a work at given word position.
public void SetCaretPosition(int pos, bool select = False)
Set the text caret position to the given index.
Parameters
pos: Where to move the text caret to within the text.select: Whether to also add the characters we passed by to the selection. Default: False
public virtual void SetContent(string value)
public virtual void SetProperty(string name, string value)
public void SetSelection(int start, int end)
Sets the text selection.
No results match this filter.
Properties
Showing 11 properties
public int Sandbox.UI.Label.CaretPosition { get; set; }
Position of the text cursor/caret within the text, at which newly typed characters are inserted.
public bool Sandbox.UI.Label.IsRich { get; set; }
Set to true if this is rich text. This means it can support some inline html elements.
public bool Sandbox.UI.Label.Multiline { get; set; }
Enables multi-line support for editing purposes.
public bool Sandbox.UI.Label.Selectable { get; set; }
Can be selected
public Color Sandbox.UI.Label.SelectionColor { get; set; }
The color used for text selection highlight
public int Sandbox.UI.Label.SelectionEnd { get; set; }
public int Sandbox.UI.Label.SelectionStart { get; set; }
public bool Sandbox.UI.Label.ShouldDrawSelection { get; set; }
public virtual string Sandbox.UI.Label.Text { get; set; }
Text to display on the label.
public int Sandbox.UI.Label.TextLength { get; set; }
Amount of characters in the text of the text entry. Not bytes.
public bool Sandbox.UI.Label.Tokenize { get; set; }
If true and the text starts with #, it will be treated as a language token.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox.UI |
| Type | class |
| Assembly | Sandbox.Engine |
| Doc ID | T:Sandbox.UI.Label |