class Panel

in global :: Sandbox . UI

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


public PanelCreator Add { get; }

Quickly add common panels with certain values as children.

public IEnumerable<Panel> Children { get; }

List of panels that are attached/parented directly to this one.

public bool HasChildren { get; }

Whether this panel has any child panels at all.

public Panel Parent { get; set; }

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.

public void DeleteChildren( bool immediate = False )

🤡 Doc inheritance is not yet supported.

Deletes all child panels via .

public void AddChild( Panel p )

Add given panel as a child to this panel.

public int SiblingIndex { get; }

The index of this panel in its parent's child list.

public IEnumerable<Panel> AncestorsAndSelf { get; }

Returns this panel and all its ancestors, i.e. the Parent, parent of its parent, etc.

public IEnumerable<Panel> Ancestors { get; }

Returns all ancestors, i.e. the parent, parent of our parent, etc.

public IEnumerable<Panel> Descendants { get; }

List of all panels that are attached to this panel, recursively, i.e. all children of this panel, children of those children, etc.

public bool IsAncestor( Panel panel )

Is the given panel a parent, grandparent, etc.

public Scene Scene { get; set; }

Returns the scene that this panel belongs to

public int GetChildIndex( Panel panel )

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

public Panel GetChild( int index, bool 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.

public int ChildrenCount { get; }

Amount of panels directly parented to this panel.

public IEnumerable<string> Class { get; }

A list of CSS classes applied to this panel.

public string Classes { get; set; }

All CSS classes applied to this panel, separated with spaces.

public void AddClass( string classname )

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

public void SetClass( string classname, bool active )

Sets a specific CSS class active or not.

public void FlashClass( string classname, float seconds )

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

public void ToggleClass( string classname )

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

public void RemoveClass( string classname )

Removes given CSS class from this panel.

public bool HasClass( string classname )

Whether we have the given CSS class or not.

public string ElementName { get; set; }

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)

public string Id { get; set; }

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.

public string SourceFile { get; set; }

If this was created by razor, this is the file in which it was created

public int SourceLine { get; set; }

If this was created by razor, this is the line number in the file

public TaskSource Task

Quick access to timing events, for async/await.

public StyleSheetCollection StyleSheet

A collection of stylesheets applied to this panel directly.

public PseudoClass PseudoClass { get; set; }

Special flags used by the styling system for hover, active etc..

public bool HasFocus { get; }

Whether this panel has the :focus pseudo class active.

public bool HasActive { get; }

Whether this panel has the :active pseudo class active.

public bool HasHovered { get; }

Whether this panel has the :hover pseudo class active.

public bool HasIntro { get; }

Whether this panel has the :intro pseudo class active.

public bool HasOutro { get; }

Whether this panel has the :outro pseudo class active.

public IEnumerable<StyleSheet> AllStyleSheets { get; }

List of all s applied to this panel and all its ancestors.

public bool Switch( PseudoClass c, bool state )

Switch a pseudo class on or off.

public bool IsVisible { get; }

Return true if this panel isn't hidden by opacity or displaymode.

public bool IsVisibleSelf { get; }

Return true if this panel isn't hidden by opacity or displaymode.

public 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]

public Vector2 ScreenPositionToPanelPosition( Vector2 pos )

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

public Vector2 PanelPositionToScreenPosition( Vector2 pos )

Convert a point from local space to screen space

public IEnumerable<Panel> FindInRect( Rect box, bool 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.

public bool AllowChildSelection { get; set; }

Allow selecting child text

public void Invoke( float seconds, Action action )

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

public void InvokeOnce( string name, float 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.

public void CancelInvoke( string name )

Cancel a named invocation

public string StringValue { get; set; }

Set via "value" property from HTML.

public bool IsDeleting { get; }

Whether was called on this panel.

public void Delete( bool immediate = False )

Deletes the panel.

  • immediate If , will skip any outros. (:outro CSS pseudo class)

public bool WantsDrag { get; }

Return true if this panel wants to be dragged

public bool CanDragScroll { get; set; }

Set this to false if you want to opt out of drag scrolling

public bool HasScrollX { get; }

Return true if this panel is scrollable on the X axis

public bool HasScrollY { get; }

Return true if this panel is scrollable on the Y axis

public void AddEventListener( string eventName, Action action )

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

public void CreateEvent( PanelEvent evnt )

Pass given event to the event queue.

public Vector2 MousePosition { get; }

Current mouse position local to this panels top left corner.

public Vector2 GetTransformPosition( Vector2 pos )

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

public bool 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.

public bool IsInside( Rect rect, bool fullyInside )

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

  • 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.

public bool AcceptsFocus { get; set; }

False by default, can this element accept keyboard focus. If an element accepts focus it'll be able to receive keyboard input.

public PanelInputType ButtonInput { get; set; }

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.

public bool AcceptsImeInput { get; }

False by default. Anything that is capable of accepting IME input should return true. Which is probably just a TextEntry.

public void OnButtonEvent( ButtonEvent e )

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

public void OnKeyTyped( char k )

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

public void OnButtonTyped( ButtonEvent e )

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

public void OnPaste( string text )

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

public string GetClipboardValue( bool cut )

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

public 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.

public bool TryScroll( Vector2 value )

Called from 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 .

public void SetMouseCapture( bool b )

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

  • b Whether to enable or disable the capture.

public bool HasMouseCapture { get; }

Whether this panel is capturing the mouse cursor. See .

public bool RayToLocalPosition( Ray ray, ref Vector2 position, ref float 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.

public Box Box { get; set; }

Access to various bounding boxes of this panel.

public bool HasContent { get; }

If true, calls .

public Vector2 ScrollVelocity

The velocity of the current scroll

public Vector2 ScrollOffset { get; set; }

Offset of the panel's children position for scrolling purposes.

public float ScaleToScreen { get; }

Scale of the panel on the screen.

public float ScaleFromScreen { get; }

Inverse scale of .

public Nullable<Matrix> LocalMatrix { get; }

If this panel has transforms, they'll be reflected here

public Nullable<Matrix> GlobalMatrix { get; }

If this panel or its parents have transforms, they'll be compounded here.

public float Opacity { get; }

The currently calculated opacity. This is set by multiplying our current style opacity with our parent's opacity.

public void OnLayout( ref 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.

public void FinalLayout( Vector2 offset )

Takes a and returns an outer rect

public bool PreferScrollToBottom { get; set; }

If true, we'll try to stay scrolled to the bottom when the panel changes size

public bool IsScrollAtBottom { get; }

Whether the scrolling is currently pinned to the bottom of the panel as dictated by .

public Vector2 ScrollSize { get; }

The size of the scrollable area within this panel.

public void PlaySound( string sound )

Play a sound from this panel.

public void MoveAfterSibling( Panel previousSibling )

Move this panel to be after the given sibling.

public void SetChildIndex( Panel child, int newIndex )

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

public void SetPropertyObject( string name, object value )

🤡 Doc inheritance is not yet supported.

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

public 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.

public void SetAttribute( string k, string v )

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

public string GetAttribute( string k, string defaultIfNotFound = null )

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

public void Bind( string ourPropertyName, object targetObject, string theirPropertyName )

Bind property of this panel to the value of a property of a given panel. When our property changes due to the bind, will be called.

public void SetContent( string value )

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

public void OnRenderFragmentChanged( Panel upTo )

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

public void DrawContent( ref RenderState state )

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

public void DrawBackground( ref RenderState state )

Called to draw the panels background.

public Styles ComputedStyle { get; }

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.

public IEnumerable<IStyleBlock> ActiveStyleBlocks { get; }

A importance sorted list of style blocks that are active on this panel

public PanelStyle Style { get; }

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.

public bool TryFindKeyframe( string name, ref KeyFrames keyframes )

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

  • name The name to search for.
  • keyframes The keyframes, if any are found, or .
  • Returns if @keyframes with given name were found.

public 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.

public string Tooltip { get; set; }

A string to show when hovering over this panel.

public string TooltipClass { get; set; }

The created tooltip element will have this class, if set.

public bool HasTooltip { get; }

You should override and return true if you're overriding . Otherwise this will return true if is not empty.

public Transitions Transitions { get; }

Handles the storage, progression and application of CSS transitions.

public bool HasActiveTransitions { get; }

Returns true if this panel has any active CSS transitions.

public object UserData { get; set; }

Can be used to store random data without sub-classing the panel.

public CancellationToken DeletionToken { get; }

Get a token that is cancelled when the panel is deleted

public bool Equals( object obj )

😔 No documentation found.

public int GetHashCode( )

😔 No documentation found.

public Panel( )

😔 No documentation found.

public Panel( Panel parent )

😔 No documentation found.

public Panel( Panel parent, string classnames )

😔 No documentation found.

public void SortChildren( Comparison<Panel> sorter )

😔 No documentation found.

public void SkipTransitions( )

😔 No documentation found.

public Type GetType( )

😔 No documentation found.

public string ToString( )

😔 No documentation found.

public bool IsValid { get; }

😔 No documentation found.

public void SortChildren( Func<TargetType,int> sorter )

😔 No documentation found.

public bool Focus( )

😔 No documentation found.

public bool Blur( )

😔 No documentation found.

public void AddEventListener( string eventName, Action<PanelEvent> e )

😔 No documentation found.

public void SortChildren( Func<Panel,int> sorter )

😔 No documentation found.

public T AddChild( string classnames = null )

😔 No documentation found.

public bool AddChild( ref T outPanel, string classnames = null )

😔 No documentation found.

public RootPanel FindRootPanel( )

😔 No documentation found.

public void OnDeleted( )

😔 No documentation found.

public Panel FindPopupPanel( )

😔 No documentation found.

public void StateHasChanged( )

😔 No documentation found.

public bool TryScrollToBottom( )

😔 No documentation found.

public void BindClass( string className, Func<bool> func )

😔 No documentation found.

public void OnHotloaded( )

😔 No documentation found.

public void Tick( )

😔 No documentation found.

public void OnParentChanged( )

😔 No documentation found.

public void LanguageChanged( )

😔 No documentation found.

public void UnselectAllInChildren( )

😔 No documentation found.

public void SelectAllInChildren( )

😔 No documentation found.

public bool WantsMouseInput( )

😔 No documentation found.

public void CreateEvent( string name, object value = null, Nullable<float> debounce = null )

😔 No documentation found.

public IEnumerable<T> ChildrenOfType( )

😔 No documentation found.

public RenderFragment ChildContent { get; set; }

😔 No documentation found.