Exemplo n.º 1
0
            public override void ProcessMatchedRules(VisualElement element)
            {
                VisualElementStylesData visualElementStylesData;

                if (StyleContext.s_StyleCache.TryGetValue(this.m_MatchingRulesHash, out visualElementStylesData))
                {
                    element.SetSharedStyles(visualElementStylesData);
                }
                else
                {
                    visualElementStylesData = new VisualElementStylesData(true);
                    int i     = 0;
                    int count = this.m_MatchedRules.Count;
                    while (i < count)
                    {
                        StyleContext.RuleRef ruleRef     = this.m_MatchedRules[i];
                        StylePropertyID[]    propertyIDs = StyleSheetCache.GetPropertyIDs(ruleRef.sheet, ruleRef.selector.ruleIndex);
                        visualElementStylesData.ApplyRule(ruleRef.sheet, ruleRef.selector.specificity, ruleRef.selector.rule, propertyIDs);
                        i++;
                    }
                    StyleContext.s_StyleCache[this.m_MatchingRulesHash] = visualElementStylesData;
                    element.SetSharedStyles(visualElementStylesData);
                }
            }
Exemplo n.º 2
0
 private void UpdateStyles(VisualElement element, int depth)
 {
     if (element.IsDirty(ChangeType.Styles) || element.IsDirty(ChangeType.StylesPath))
     {
         VisualContainer visualContainer = element as VisualContainer;
         int             count           = this.m_Matchers.Count;
         if (visualContainer != null && visualContainer.styleSheets != null)
         {
             this.AddMatchersFromSheet(visualContainer.styleSheets);
         }
         string fullTypeName = element.fullTypeName;
         long   num          = (long)fullTypeName.GetHashCode();
         num = (num * 397L ^ (long)this.currentPixelsPerPoint.GetHashCode());
         this.m_MatchedRules.Clear();
         int count2 = this.m_Matchers.Count;
         for (int i = 0; i < count2; i++)
         {
             RuleMatcher ruleMatcher = this.m_Matchers[i];
             if (ruleMatcher.depth >= depth && StyleContext.Match(element, ref ruleMatcher))
             {
                 StyleSelector[] selectors = ruleMatcher.complexSelector.selectors;
                 int             num2      = ruleMatcher.simpleSelectorIndex + 1;
                 int             num3      = selectors.Length;
                 if (num2 < num3)
                 {
                     RuleMatcher item = new RuleMatcher
                     {
                         complexSelector     = ruleMatcher.complexSelector,
                         depth               = ((selectors[num2].previousRelationship != StyleSelectorRelationship.Child) ? 2147483647 : (depth + 1)),
                         simpleSelectorIndex = num2,
                         sheet               = ruleMatcher.sheet
                     };
                     this.m_Matchers.Add(item);
                 }
                 else
                 {
                     StyleRule rule        = ruleMatcher.complexSelector.rule;
                     int       specificity = ruleMatcher.complexSelector.specificity;
                     num = (num * 397L ^ (long)rule.GetHashCode());
                     num = (num * 397L ^ (long)specificity);
                     this.m_MatchedRules.Add(new StyleContext.RuleRef
                     {
                         selector = ruleMatcher.complexSelector,
                         sheet    = ruleMatcher.sheet
                     });
                 }
             }
         }
         VisualElementStyles visualElementStyles;
         if (StyleContext.s_StyleCache.TryGetValue(num, out visualElementStyles))
         {
             element.SetSharedStyles(visualElementStyles);
         }
         else
         {
             visualElementStyles = new VisualElementStyles(true);
             int j      = 0;
             int count3 = this.m_MatchedRules.Count;
             while (j < count3)
             {
                 StyleContext.RuleRef ruleRef     = this.m_MatchedRules[j];
                 StylePropertyID[]    propertyIDs = StyleSheetCache.GetPropertyIDs(ruleRef.sheet, ruleRef.selector.ruleIndex);
                 visualElementStyles.ApplyRule(ruleRef.sheet, ruleRef.selector.specificity, ruleRef.selector.rule, propertyIDs, this.m_VisualTree.elementPanel.loadResourceFunc);
                 j++;
             }
             StyleContext.s_StyleCache[num] = visualElementStyles;
             element.SetSharedStyles(visualElementStyles);
         }
         if (visualContainer != null)
         {
             for (int k = 0; k < visualContainer.childrenCount; k++)
             {
                 VisualElement childAt = visualContainer.GetChildAt(k);
                 this.UpdateStyles(childAt, depth + 1);
             }
         }
         if (this.m_Matchers.Count > count)
         {
             this.m_Matchers.RemoveRange(count, this.m_Matchers.Count - count);
         }
     }
 }
Exemplo n.º 3
0
        public static void ApplyEnum <T>(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <int> property)
        {
            var value = StyleSheetCache.GetEnumValue <T>(sheet, handles[0]);

            Apply(value, specificity, ref property);
        }
Exemplo n.º 4
0
        public static void ApplyEnum <T>(StyleSheet sheet, StyleValueHandle[] handles, int specificity, ref StyleValue <int> property)
        {
            int enumValue = StyleSheetCache.GetEnumValue <T>(sheet, handles[0]);

            StyleSheetApplicator.Apply <int>(enumValue, specificity, ref property);
        }