namespace Sandbox.UI; public partial class Panel { /// /// 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. /// [Hide] public Styles ComputedStyle { get; internal set; } /// /// A importance sorted list of style blocks that are active on this panel /// [Hide] public IEnumerable ActiveStyleBlocks => Style?.LastActiveRules?.Select( x => x.Block ) ?? Enumerable.Empty(); /// /// 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. /// [Hide] public PanelStyle Style { get; private set; } /// /// Try to find @keyframes CSS rule with given name in . /// /// The name to search for. /// The keyframes, if any are found, or . /// if @keyframes with given name were found. public bool TryFindKeyframe( string name, out KeyFrames keyframes ) { // TODO: optimization - cache found keyframes? Clear on load? keyframes = null; foreach ( var sheet in AllStyleSheets ) { if ( sheet.KeyFrames.TryGetValue( name, out var keyframe ) ) { keyframes = keyframe; return true; } } return false; } internal void MarkStylesRebuilt() { inRebuildStyleRulesList = false; inRebuildStyleRulesList_Ancestors = false; inRebuildStyleRulesList_Children = false; } bool inRebuildStyleRulesList; bool inRebuildStyleRulesList_Ancestors; bool inRebuildStyleRulesList_Children; /// /// Should be called when something happens that means that this panel's stylesheets need to be /// re-evaluated. Like becoming hovered or classes changed. You don't call this when changing styles /// directly on the panel, just on anything that will change which stylesheets should get selected. /// /// Also re-evaluate all ancestor panels. (for :has()) /// Also re-evaluate all child panels. (for parent selectors) /// Root panel cache so we don't need to keep looking it up. protected void StyleSelectorsChanged( bool ancestors, bool descendants, RootPanel root = null ) { root ??= FindRootPanel(); if ( root == null ) return; if ( ancestors && !inRebuildStyleRulesList_Ancestors ) { inRebuildStyleRulesList_Ancestors = true; Parent?.StyleSelectorsChanged( true, false, root ); } if ( descendants && !inRebuildStyleRulesList_Children && HasChildren ) { inRebuildStyleRulesList_Children = true; foreach ( var child in Children ) { child.StyleSelectorsChanged( false, true, root ); } } if ( !inRebuildStyleRulesList ) { inRebuildStyleRulesList = true; root.AddToBuildStyleRulesList( this ); } } }