private void ResolveRules(StyleSheet sheet)
        {
            foreach (var complexSelector in sheet.complexSelectors)
            {
                if (complexSelector.rule == null)
                {
                    continue;
                }

                var  selectorName = StyleSheetToUss.ToUssSelector(complexSelector);
                Rule aggregateRule;
                if (!Rules.TryGetValue(selectorName, out aggregateRule))
                {
                    aggregateRule = new Rule(selectorName, complexSelector, complexSelector.rule.line);
                    Rules.Add(selectorName, aggregateRule);
                }

                // Override existing properties and append new ones:
                foreach (var property in complexSelector.rule.properties)
                {
                    Property dstProp;
                    if (aggregateRule.Properties.TryGetValue(property.name, out dstProp))
                    {
                        dstProp.Values = ToValues(property, sheet);
                    }
                    else
                    {
                        dstProp = AddProperty(aggregateRule, property, sheet);
                    }
                    if (dstProp.Name.StartsWith("--"))
                    {
                        Variables.Set(dstProp.Name, dstProp);
                    }
                }

                Property derivationProperty;
                if (aggregateRule.Properties.TryGetValue(ConverterUtils.k_Extend, out derivationProperty))
                {
                    var        parentName = derivationProperty.Values[0].AsString();
                    ExtendData derivationData;
                    if (!ParentToChildren.TryGetValue(parentName, out derivationData))
                    {
                        derivationData = new ExtendData(parentName);
                        ParentToChildren.Add(parentName, derivationData);
                    }
                    derivationData.ChildrenRules.Add(aggregateRule);
                    if (!ChildToParent.ContainsKey(aggregateRule.SelectorName))
                    {
                        ChildToParent.Add(aggregateRule.SelectorName, parentName);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void AddSelector(StyleComplexSelector selector)
        {
            var selectorStr = StyleSheetToUss.ToUssSelector(selector);

            if (ConverterUtils.IsCustomStyleSelector(selectorStr))
            {
                customStyleSelectors.TryAdd(selectorStr, selector);
            }
            else if (ConverterUtils.IsTypeStyleSelector(selectorStr))
            {
                typeStyleSelectors.TryAdd(selectorStr, selector);
            }
            else if (ConverterUtils.IsAbstractStyleSelector(selectorStr))
            {
                abstractStyleSelectors.TryAdd(selectorStr, selector);
            }

            selectors.TryAdd(selectorStr, selector);
        }
Exemplo n.º 3
0
        private static void PopulateStyle(StyleSheetCache cache, StyleComplexSelector complexSelector, GUIStyle style, bool throwIfIncomplete = false)
        {
            var rule = complexSelector.rule;
            var complexSelectorStr = StyleSheetToUss.ToUssSelector(complexSelector);
            var sheet = cache.sheet;

            // GUIStyle.alignment
            GetProperty(rule, ConverterUtils.k_TextAlignment, throwIfIncomplete, property =>
            {
                style.alignment = ConverterUtils.ToTextAnchor(sheet.ReadEnum(property.values[0]));
            });

            // GUIStyle.border
            ReadRectOffset(cache, rule, ConverterUtils.k_Border, "", throwIfIncomplete, style.border);

            // GUIStyle.clipping
            GetProperty(rule, ConverterUtils.k_Clipping, throwIfIncomplete, property =>
            {
                style.clipping = ConverterUtils.ToTextClipping(sheet.ReadEnum(property.values[0]));
            });

            // GUIStyle.contentOffset
            GetProperty(rule, ConverterUtils.k_ContentOffset, throwIfIncomplete, property =>
            {
                style.contentOffset = StyleSheetBuilderHelper.ReadVector2(sheet, property);
            });

            // GUIStyle.fixedHeight
            GetProperty(rule, ConverterUtils.k_Height, throwIfIncomplete, property =>
            {
                style.fixedHeight = sheet.ReadFloat(property.values[0]);
            });

            // GUIStyle.fixedWidth
            GetProperty(rule, ConverterUtils.k_Width, throwIfIncomplete, property =>
            {
                style.fixedWidth = sheet.ReadFloat(property.values[0]);
            });

            // GUIStyle.font
            GetProperty(rule, ConverterUtils.k_Font, false, property =>
            {
                style.font = ReadResource <Font>(sheet, property);
            });

            // GUIStyle.fixedWidth
            GetProperty(rule, ConverterUtils.k_FontSize, throwIfIncomplete, property =>
            {
                style.fontSize = (int)sheet.ReadFloat(property.values[0]);
            });

            // GUIStyle.fontStyle
            ReadFontStyle(sheet, rule, throwIfIncomplete, style);

            // GUIStyle.imagePosition
            GetProperty(rule, ConverterUtils.k_ImagePosition, throwIfIncomplete, property =>
            {
                style.imagePosition = ConverterUtils.ToImagePosition(sheet.ReadEnum(property.values[0]));
            });

            // GUIStyle.margin
            ReadRectOffset(cache, rule, ConverterUtils.k_Margin, null, throwIfIncomplete, style.margin);

            // GUIStyle.name
            GetProperty(rule, ConverterUtils.k_Name, throwIfIncomplete, property =>
            {
                style.name = sheet.ReadString(property.values[0]);
            });

            // GUIStyle.overflow
            ReadRectOffset(cache, rule, ConverterUtils.k_Overflow, null, throwIfIncomplete, style.overflow);

            // GUIStyle.padding
            ReadRectOffset(cache, rule, ConverterUtils.k_Padding, null, throwIfIncomplete, style.padding);

            // GUIStyle.richText
            GetProperty(rule, ConverterUtils.k_RichText, throwIfIncomplete, property =>
            {
                style.richText = ReadBool(sheet, property);
            });

            // GUIStyle.stretchHeight
            GetProperty(rule, ConverterUtils.k_StretchHeight, throwIfIncomplete, property =>
            {
                style.stretchHeight = ReadBool(sheet, property);
            });

            // GUIStyle.stretchWidth
            GetProperty(rule, ConverterUtils.k_StretchWidth, throwIfIncomplete, property =>
            {
                style.stretchWidth = ReadBool(sheet, property);
            });

            // GUIStyle.wordWrap
            GetProperty(rule, ConverterUtils.k_WordWrap, throwIfIncomplete, property =>
            {
                style.wordWrap = ReadBool(sheet, property);
            });

            ReadState(cache, rule, style.normal, throwIfIncomplete);

            ReadState(cache, complexSelectorStr, style.active, "active", throwIfIncomplete);
            ReadState(cache, complexSelectorStr, style.focused, "focused", throwIfIncomplete);
            ReadState(cache, complexSelectorStr, style.hover, "hover", throwIfIncomplete);
            ReadState(cache, complexSelectorStr, style.onActive, "onActive", throwIfIncomplete);
            ReadState(cache, complexSelectorStr, style.onFocused, "onFocused", throwIfIncomplete);
            ReadState(cache, complexSelectorStr, style.onHover, "onHover", throwIfIncomplete);
            ReadState(cache, complexSelectorStr, style.onNormal, "onNormal", throwIfIncomplete);
        }