Api Sandbox UI Panel
class

Panel

public class Panel

A simple User Interface panel. Can be styled with CSS.

Constructors

Panel()
Panel(Panel parent)
Panel(Panel parent, String classnames)

Properties

Name Type Description
Add PanelCreator Quickly add common panels with certain values as children.
Children IEnumerable<Panel> List of panels that are attached/parented directly to this one.
HasChildren Boolean Whether this panel has any child panels at all.
Parent Panel The panel we are directly attached to. This panel will be positioned relative to the given parent, and therefore move with it, typically also be hidden by the parents bounds.
SiblingIndex Int32 The index of this panel in its parent's child list.
AncestorsAndSelf IEnumerable<Panel> Returns this panel and all its ancestors, i.e. the Parent, parent of its parent, etc.
Ancestors IEnumerable<Panel> Returns all ancestors, i.e. the parent, parent of our parent, etc.
Descendants IEnumerable<Panel> List of all panels that are attached to this panel, recursively, i.e. all children of this panel, children of those children, etc.
Scene Scene Returns the scene that this panel belongs to
GameObject GameObject Returns the GameObject that this panel belongs to
ChildrenCount Int32 Amount of panels directly parented to this panel.
Class IEnumerable<String> A list of CSS classes applied to this panel.
Classes String All CSS classes applied to this panel, separated with spaces.
ElementName String The element name. If you've created this Panel via a template this will be whatever the element name is on there. If not then it'll be the name of the class (ie Panel, Button)
Id virtual String Works the same as the html id="" attribute. If you set Id to "poop", it'll match any styles that define #poop in their selector.
SourceFile virtual String If this was created by razor, this is the file in which it was created
SourceLine virtual Int32 If this was created by razor, this is the line number in the file
PseudoClass virtual PseudoClass Special flags used by the styling system for hover, active etc..
HasFocus Boolean Whether this panel has the :focus pseudo class active.
HasActive Boolean Whether this panel has the :active pseudo class active.
HasHovered Boolean Whether this panel has the :hover pseudo class active.
HasIntro Boolean Whether this panel has the :intro pseudo class active.
HasOutro Boolean Whether this panel has the :outro pseudo class active.
AllStyleSheets IEnumerable<StyleSheet> List of all StyleSheets applied to this panel and all its ancestors.
IsVisible Boolean Return true if this panel isn't hidden by opacity or displaymode.
IsVisibleSelf Boolean Return true if this panel isn't hidden by opacity or displaymode.
AllowChildSelection Boolean Allow selecting child text
IsValid virtual Boolean
StringValue virtual String Set via "value" property from HTML.
IsDeleting Boolean Whether Boolean) was called on this panel.
WantsDrag virtual Boolean Return true if this panel wants to be dragged
CanDragScroll Boolean Set this to false if you want to opt out of drag scrolling
HasScrollX Boolean Return true if this panel is scrollable on the X axis
HasScrollY Boolean Return true if this panel is scrollable on the Y axis
MousePosition Vector2 Current mouse position local to this panels top left corner.
AcceptsFocus Boolean False by default, can this element accept keyboard focus. If an element accepts focus it'll be able to receive keyboard input.
ButtonInput virtual PanelInputType Describe what to do with keyboard input. The default is InputMode.UI which means that when focused, this panel will receive Keys Typed and Button Events. If you set this to InputMode.Game, this panel will redirect its inputs to the game, which means for example that if you're focused on this panel and press space, it'll send the jump button to the game.
AcceptsImeInput virtual Boolean False by default. Anything that is capable of accepting IME input should return true. Which is probably just a TextEntry.
HasMouseCapture Boolean Whether this panel is capturing the mouse cursor. See Boolean).
Box Box Access to various bounding boxes of this panel.
HasContent virtual Boolean If true, calls RenderState@).
ScrollOffset Vector2 Offset of the panel's children position for scrolling purposes.
ScaleToScreen Single Scale of the panel on the screen.
ScaleFromScreen Single Inverse scale of ScaleToScreen.
LocalMatrix Matrix? If this panel has transforms, they'll be reflected here
GlobalMatrix Matrix? If this panel or its parents have transforms, they'll be compounded here.
Opacity Single The currently calculated opacity. This is set by multiplying our current style opacity with our parent's opacity.
PreferScrollToBottom Boolean If true, we'll try to stay scrolled to the bottom when the panel changes size
IsScrollAtBottom Boolean Whether the scrolling is currently pinned to the bottom of the panel as dictated by PreferScrollToBottom.
ScrollSize Vector2 The size of the scrollable area within this panel.
IsDragScrolling Boolean Is this panel currently being scrolled by dragging?
ChildContent RenderFragment
ComputedStyle Styles This is the style that we computed last. If you're looking to see which styles are set on this panel then this is what you're looking for.
ActiveStyleBlocks virtual IEnumerable<IStyleBlock> A importance sorted list of style blocks that are active on this panel
Style PanelStyle Allows you to set styles specifically on this panel. Setting the style will only affect this panel and no others and will override any other styles.
Tooltip String A string to show when hovering over this panel.
TooltipClass String The created tooltip element will have this class, if set.
HasTooltip virtual Boolean You should override and return true if you're overriding CreateTooltipPanel. Otherwise this will return true if Tooltip is not empty.
Transitions Transitions Handles the storage, progression and application of CSS transitions.
HasActiveTransitions Boolean Returns true if this panel has any active CSS transitions.
UserData Object Can be used to store random data without sub-classing the panel.
DeletionToken CancellationToken Get a token that is cancelled when the panel is deleted

Methods

Void DeleteChildren(Boolean immediate = False)

Deletes all child panels via Boolean).

T AddChild(T p)

Add given panel as a child to this panel.

Void SortChildren(Comparison<Panel> sorter)
Void SortChildren(Func<TargetType, Int32> sorter)
Void SortChildren(Func<Panel, Int32> sorter)
T AddChild(String classnames = null)

Creates a panel of given type and makes it our child.

classnames — Optional CSS class names to apply to the newly created panel.
returns — The created panel.
Boolean AddChild(T outPanel, String classnames = null)

Creates a panel of given type and makes it our child, returning it as an out argument.

outPanel — The created panel.
classnames — Optional CSS class names to apply to the newly created panel.
returns — Always returns .
Boolean IsAncestor(Panel panel)

Is the given panel a parent, grandparent, etc.

RootPanel FindRootPanel()

Returns the RootPanel we are ultimately attached to, if any.

virtual Panel FindPopupPanel()

Returns the first ancestor panel that has no parent.

Int32 GetChildIndex(Panel panel)

Returns the index at which the given panel is parented to this panel, or -1 if it is not.

Panel GetChild(Int32 index, Boolean loop = False)

Return a child at given index.

index — Index at which to look.
loop — Whether to loop indices when out of bounds, i.e. -1 becomes last child, 11 becomes second child in a list of 10, etc.
returns — Returns the requested child, or if it was not found.
IEnumerable<T> ChildrenOfType()

Returns a list of child panels of given type.

Void AddClass(String classname)

Adds CSS class(es) separated by spaces to this panel.

Void SetClass(String classname, Boolean active)

Sets a specific CSS class active or not.

Void FlashClass(String classname, Single seconds)

Add a class for a set amount of seconds. If called multiple times, we will stomp the earlier call.

Void ToggleClass(String classname)

Add a class if we don't have it, remove a class if we do have it

Void RemoveClass(String classname)

Removes given CSS class from this panel.

Boolean HasClass(String classname)

Whether we have the given CSS class or not.

Void BindClass(String className, Func<Boolean> func)
virtual Void OnHotloaded()

Called when a hotload happened. (Not necessarily on this panel)

Boolean Switch(PseudoClass c, Boolean state)

Switch a pseudo class on or off.

virtual Void Tick()

Called every frame. This is your "Think" function.

virtual Void OnParentChanged()

Called after the parent of this panel has changed.

virtual Boolean WantsMouseInput()

Returns true if this panel would like the mouse cursor to be visible.

Vector2 ScreenPositionToPanelDelta(Vector2 pos)

Convert a point from the screen to a point representing a delta on this panel where the top left is [0,0] and the bottom right is [1,1]

Vector2 ScreenPositionToPanelPosition(Vector2 pos)

Convert a point from the screen to a position relative to the top left of this panel

Vector2 PanelPositionToScreenPosition(Vector2 pos)

Convert a point from local space to screen space

IEnumerable<Panel> FindInRect(Rect box, Boolean fullyInside)

Find and return any children of this panel (including self) within the given rect.

box — The area to look for panels in, in screen-space coordinates.
fullyInside — Whether we want only the panels that are completely within the given bounds.
Void SelectAllInChildren()

If AllowChildSelection is enabled, we'll try to select all children text

Void UnselectAllInChildren()

Clear any selection in children

virtual Void LanguageChanged()

Called when the current language has changed. This allows you to rebuild anything that might need rebuilding. Tokenized text labels should automatically update.

Void Invoke(Single seconds, Action action)

Invoke a method after a delay. If the panel is deleted before this delay the method will not be called.

Void InvokeOnce(String name, Single seconds, Action action)

Invoke a method after a delay. If the panel is deleted before this delay the method will not be called. If the invoke is called while the old one is waiting, the old one will be cancelled.

Void CancelInvoke(String name)

Cancel a named invocation

virtual Void Delete(Boolean immediate = False)

Deletes the panel.

immediate — If , will skip any outros. (:outro CSS pseudo class)
virtual Void OnDeleted()

Called when the panel is about to be deleted.

Void AddEventListener(String eventName, Action<PanelEvent> e)
Void AddEventListener(String eventName, Action action)

Runs given callback when the given event is triggered, without access to the PanelEvent.

virtual Void CreateEvent(String name, Object value = null, Single? debounce = null)
virtual Void CreateEvent(PanelEvent evnt)

Pass given event to the event queue.

virtual Vector2 GetTransformPosition(Vector2 pos)

Called by Panel@) to transform the current mouse position using the panel's LocalMatrix (by default). This can be overriden for special cases.

pos
Boolean IsInside(Vector2 pos)

Whether given screen position is within this panel. This will accurately handle border radius as well.

pos — The position to test, in screen coordinates.
Boolean IsInside(Rect rect, Boolean fullyInside)

Whether the given rect is inside this panels bounds. (Rect)

rect — The rect to test, which should have screen-space coordinates.
fullyInside — to test if the given rect is completely inside the panel. to test for an intersection.
Boolean Focus()

Give input focus to this panel.

Boolean Blur()

Remove input focus from this panel.

virtual Void OnButtonEvent(ButtonEvent e)

Called when any button, mouse (except for mouse4/5) and keyboard, are pressed or depressed while hovering this panel.

virtual Void OnKeyTyped(Char k)

Called when a printable character has been typed (pressed) while this panel has input focus. (Focus)

virtual Void OnButtonTyped(ButtonEvent e)

Called when any keyboard button has been typed (pressed) while this panel has input focus. (Focus)

virtual Void OnPaste(String text)

Called when the user presses CTRL+V while this panel has input focus.

text
virtual String GetClipboardValue(Boolean cut)

If we have a value that can be copied to the clipboard, return it here.

virtual Void OnMouseWheel(Vector2 value)

Called when the player scrolls their mouse wheel while hovering this panel.

value — The scroll wheel delta. Positive values are scrolling down, negative - up.
Boolean TryScroll(Vector2 value)

Called from OnMouseWheel(Vector2) to try to scroll.

value — The scroll wheel delta. Positive values are scrolling down, negative - up.
returns — Return true to NOT propagate the event to the Parent.
Boolean TryScrollToBottom()

Scroll to the bottom, if the panel has scrolling enabled.

returns — Whether we scrolled to the bottom or not.
Void SetMouseCapture(Boolean b)

Captures the mouse cursor while active. The cursor will be hidden and will be stuck in place. You will want to use Delta in Tick while HasMouseCapture to read mouse movements.You can call this from ButtonEvent) for mouse clicks.

b — Whether to enable or disable the capture.
virtual Boolean RayToLocalPosition(Ray ray, Vector2 position, Single distance)

Transform a ray in 3D space to a position on the panel. This is used for world panel input.

ray — The ray in 3D world space to test against this panel.
position — Position on the panel where the intersection happened, local to the panel's top left corner.
distance — Distance from the ray's origin to the intersection in 3D space.
returns — Return true if a hit/intersection was detected.
virtual Void OnLayout(Rect layoutRect)

This panel has just been laid out. You can modify its position now and it will affect its children. This is a useful place to restrict shit to the screen etc.

virtual Void FinalLayout(Vector2 offset)

Takes a LayoutCascade and returns an outer rect

Void PlaySound(String sound)

Play a sound from this panel.

Void MoveAfterSibling(Panel previousSibling)

Move this panel to be after the given sibling.

Void SetChildIndex(Panel child, Int32 newIndex)

Move given child panel to be given index, where 0 is the first child.

virtual Void SetPropertyObject(String name, Object value)

Same as String), but first tries to set the property on the panel object, then process any special properties such as class.

virtual Void SetProperty(String name, String value)

Set a property on the panel, such as special properties (class, id, style and value, etc.) and properties of the panel's C# class.

name — name of the property to modify.
value — Value to assign to the property.
Void SetAttribute(String k, String v)

Used in templates, gets an attribute that was set in the template.

String GetAttribute(String k, String defaultIfNotFound = null)

Used in templates, try to get the attribute that was set in creation.

virtual Void SetContent(String value)

Called by the templating system when an element has content between its tags.

Void StateHasChanged()

For razor panels, call when the state of the render tree has changed such that it would be a good idea to re-render the tree. You would usually not need to call this manually.

Void OnRenderFragmentChanged(Panel upTo)

A RenderFragment has been set on us, so our tree has potential changes now. Lets update and see.

Void MarkRenderDirty()
virtual Void BuildContentCommandList(CommandList commandList, RenderState state)

Called when HasContent is set to to custom draw the panels content. You'll probably want to call MarkRenderDirty when your content changes to ensure the command list gets rebuilt.

virtual Void BuildCommandList(CommandList commandList)

You'll probably want to call MarkRenderDirty when your content changes to ensure the command list gets rebuilt.

virtual Void DrawBackground(RenderState state)

Called to draw the panels background.

virtual Void DrawContent(RenderState state)

Called when HasContent is set to to custom draw the panels content.

Boolean TryFindKeyframe(String name, KeyFrames keyframes)

Try to find @keyframes CSS rule with given name in AllStyleSheets.

name — The name to search for.
keyframes — The keyframes, if any are found, or .
returns — if @keyframes with given name were found.
virtual Void OnTemplateSlot(INode element, String slotName, Panel panel)

TODO: Obsolete this and instead maybe we have something like [PanelSlot( "slotname" )] that is applied on properties. Then when we find a slot="slotname" we chase up the heirachy and set the property.

Void SkipTransitions()

Any transitions running, or about to run, will jump straight to the end.

Fields

Name Type Description
Task TaskSource Quick access to timing events, for async/await.
StyleSheet StyleSheetCollection A collection of stylesheets applied to this panel directly.
ScrollVelocity Vector2 The velocity of the current scroll
Assembly: Sandbox.Engine Namespace: Sandbox.UI Full Name: Sandbox.UI.Panel