using Sandbox.Engine; namespace Sandbox.UI; public partial class Panel { /// /// Whether was called on this panel. /// [Hide] public bool IsDeleting { get; internal set; } private bool IsDeleted { get; set; } /// /// Deletes the panel. /// /// If , will skip any outros. (:outro CSS pseudo class) public virtual void Delete( bool immediate = false ) { if ( IsDeleted ) return; _deleteTokenSource?.Cancel(); if ( immediate ) { Parent = null; IsVisible = false; IsDeleting = true; OnDeleteRecursive(); return; } if ( IsDeleting ) return; IsDeleting = true; Transitions.Clear(); // stop any intros Switch( PseudoClass.Outro, true ); GlobalContext.Current.UISystem.AddDeferredDeletion( this ); } /// /// Called when the panel is about to be deleted. /// public virtual void OnDeleted() { } /// /// Called on delete. /// internal void OnDeleteRecursive() { IsDeleted = true; try { RemoveFromLists(); Task.Expire(); foreach ( var child in Children ) { child?.OnDeleteRecursive(); } try { OnDeleted(); } catch ( System.Exception ex ) { Log.Error( ex, "Error when calling OnDeleted" ); } // Clear any focus we may have // TODO: Ideally this would cascade to parents who accept focus, but we'd need to change how Panels are removed. if ( InputFocus.Current == this ) { InputFocus.Clear( this ); } if ( MouseCapture == this ) { SetMouseCapture( false ); } YogaNode?.Dispose(); YogaNode = null; _renderChildren = null; _childrenHash = null; _children = null; _parent = null; } catch ( System.Exception e ) { Log.Error( e ); } } }