internal void ApplyRule(StyleSheet registry, int specificity, StyleRule rule, StylePropertyID[] propertyIDs, LoadResourceFunction loadResourceFunc)
        {
            for (int i = 0; i < rule.properties.Length; i++)
            {
                StyleProperty    styleProperty   = rule.properties[i];
                StylePropertyID  stylePropertyID = propertyIDs[i];
                StyleValueHandle handle          = styleProperty.values[0];
                switch (stylePropertyID)
                {
                case StylePropertyID.MarginLeft:
                    registry.Apply(handle, specificity, ref this.marginLeft);
                    break;

                case StylePropertyID.MarginTop:
                    registry.Apply(handle, specificity, ref this.marginTop);
                    break;

                case StylePropertyID.MarginRight:
                    registry.Apply(handle, specificity, ref this.marginRight);
                    break;

                case StylePropertyID.MarginBottom:
                    registry.Apply(handle, specificity, ref this.marginBottom);
                    break;

                case StylePropertyID.PaddingLeft:
                    registry.Apply(handle, specificity, ref this.paddingLeft);
                    break;

                case StylePropertyID.PaddingTop:
                    registry.Apply(handle, specificity, ref this.paddingTop);
                    break;

                case StylePropertyID.PaddingRight:
                    registry.Apply(handle, specificity, ref this.paddingRight);
                    break;

                case StylePropertyID.PaddingBottom:
                    registry.Apply(handle, specificity, ref this.paddingBottom);
                    break;

                case StylePropertyID.BorderLeft:
                    registry.Apply(handle, specificity, ref this.borderLeft);
                    break;

                case StylePropertyID.BorderTop:
                    registry.Apply(handle, specificity, ref this.borderTop);
                    break;

                case StylePropertyID.BorderRight:
                    registry.Apply(handle, specificity, ref this.borderRight);
                    break;

                case StylePropertyID.BorderBottom:
                    registry.Apply(handle, specificity, ref this.borderBottom);
                    break;

                case StylePropertyID.PositionType:
                    registry.Apply(handle, specificity, ref this.positionType);
                    break;

                case StylePropertyID.PositionLeft:
                    registry.Apply(handle, specificity, ref this.positionLeft);
                    break;

                case StylePropertyID.PositionTop:
                    registry.Apply(handle, specificity, ref this.positionTop);
                    break;

                case StylePropertyID.PositionRight:
                    registry.Apply(handle, specificity, ref this.positionRight);
                    break;

                case StylePropertyID.PositionBottom:
                    registry.Apply(handle, specificity, ref this.positionBottom);
                    break;

                case StylePropertyID.Width:
                    registry.Apply(handle, specificity, ref this.width);
                    break;

                case StylePropertyID.Height:
                    registry.Apply(handle, specificity, ref this.height);
                    break;

                case StylePropertyID.MinWidth:
                    registry.Apply(handle, specificity, ref this.minWidth);
                    break;

                case StylePropertyID.MinHeight:
                    registry.Apply(handle, specificity, ref this.minHeight);
                    break;

                case StylePropertyID.MaxWidth:
                    registry.Apply(handle, specificity, ref this.maxWidth);
                    break;

                case StylePropertyID.MaxHeight:
                    registry.Apply(handle, specificity, ref this.maxHeight);
                    break;

                case StylePropertyID.Flex:
                    registry.Apply(handle, specificity, ref this.flex);
                    break;

                case StylePropertyID.BorderWidth:
                    registry.Apply(handle, specificity, ref this.borderWidth);
                    break;

                case StylePropertyID.BorderRadius:
                    registry.Apply(handle, specificity, ref this.borderRadius);
                    break;

                case StylePropertyID.FlexDirection:
                    registry.Apply(handle, specificity, ref this.flexDirection);
                    break;

                case StylePropertyID.FlexWrap:
                    registry.Apply(handle, specificity, ref this.flexWrap);
                    break;

                case StylePropertyID.JustifyContent:
                    registry.Apply(handle, specificity, ref this.justifyContent);
                    break;

                case StylePropertyID.AlignContent:
                    registry.Apply(handle, specificity, ref this.alignContent);
                    break;

                case StylePropertyID.AlignSelf:
                    registry.Apply(handle, specificity, ref this.alignSelf);
                    break;

                case StylePropertyID.AlignItems:
                    registry.Apply(handle, specificity, ref this.alignItems);
                    break;

                case StylePropertyID.TextAlignment:
                    registry.Apply(handle, specificity, ref this.textAlignment);
                    break;

                case StylePropertyID.TextClipping:
                    registry.Apply(handle, specificity, ref this.textClipping);
                    break;

                case StylePropertyID.Font:
                    registry.Apply(handle, specificity, loadResourceFunc, ref this.font);
                    break;

                case StylePropertyID.FontSize:
                    registry.Apply(handle, specificity, ref this.fontSize);
                    break;

                case StylePropertyID.FontStyle:
                    registry.Apply(handle, specificity, ref this.fontStyle);
                    break;

                case StylePropertyID.BackgroundSize:
                    registry.Apply(handle, specificity, ref this.backgroundSize);
                    break;

                case StylePropertyID.WordWrap:
                    registry.Apply(handle, specificity, ref this.wordWrap);
                    break;

                case StylePropertyID.BackgroundImage:
                    registry.Apply(handle, specificity, loadResourceFunc, ref this.backgroundImage);
                    break;

                case StylePropertyID.TextColor:
                    registry.Apply(handle, specificity, ref this.textColor);
                    break;

                case StylePropertyID.BackgroundColor:
                    registry.Apply(handle, specificity, ref this.backgroundColor);
                    break;

                case StylePropertyID.BorderColor:
                    registry.Apply(handle, specificity, ref this.borderColor);
                    break;

                case StylePropertyID.Overflow:
                    registry.Apply(handle, specificity, ref this.overflow);
                    break;

                case StylePropertyID.SliceLeft:
                    registry.Apply(handle, specificity, ref this.sliceLeft);
                    break;

                case StylePropertyID.SliceTop:
                    registry.Apply(handle, specificity, ref this.sliceTop);
                    break;

                case StylePropertyID.SliceRight:
                    registry.Apply(handle, specificity, ref this.sliceRight);
                    break;

                case StylePropertyID.SliceBottom:
                    registry.Apply(handle, specificity, ref this.sliceBottom);
                    break;

                case StylePropertyID.Opacity:
                    registry.Apply(handle, specificity, ref this.opacity);
                    break;

                case StylePropertyID.Custom:
                {
                    if (this.m_CustomProperties == null)
                    {
                        this.m_CustomProperties = new Dictionary <string, CustomProperty>();
                    }
                    CustomProperty value = default(CustomProperty);
                    if (!this.m_CustomProperties.TryGetValue(styleProperty.name, out value) || specificity >= value.specificity)
                    {
                        value.handle      = handle;
                        value.data        = registry;
                        value.specificity = specificity;
                        this.m_CustomProperties[styleProperty.name] = value;
                    }
                    break;
                }

                default:
                    throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", stylePropertyID));
                }
            }
        }
Exemple #2
0
        internal void ApplyRule(StyleSheet registry, int specificity, StyleRule rule, StylePropertyID[] propertyIDs)
        {
            for (int i = 0; i < rule.properties.Length; i++)
            {
                UnityEngine.StyleSheets.StyleProperty styleProperty = rule.properties[i];
                StylePropertyID propertyID = propertyIDs[i];

                var handles = styleProperty.values;
                switch (propertyID)
                {
                case StylePropertyID.AlignContent:
                    registry.Apply(handles, specificity, ref alignContent, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.AlignItems:
                    registry.Apply(handles, specificity, ref alignItems, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.AlignSelf:
                    registry.Apply(handles, specificity, ref alignSelf, StyleSheetApplicator.ApplyEnum <Align>);
                    break;

                case StylePropertyID.BackgroundImage:
                    registry.Apply(handles, specificity, ref backgroundImage, StyleSheetApplicator.ApplyResource);
                    break;

                case StylePropertyID.BorderLeft:
                    registry.Apply(handles, specificity, ref borderLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTop:
                    registry.Apply(handles, specificity, ref borderTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderRight:
                    registry.Apply(handles, specificity, ref borderRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottom:
                    registry.Apply(handles, specificity, ref borderBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Flex:
                    registry.Apply(handles, specificity, ref flex, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexBasis:
                    registry.Apply(handles, specificity, ref flexBasis, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexGrow:
                    registry.Apply(handles, specificity, ref flexGrow, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.FlexShrink:
                    registry.Apply(handles, specificity, ref flexShrink, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Font:
                    registry.Apply(handles, specificity, ref font, StyleSheetApplicator.ApplyResource);
                    break;

                case StylePropertyID.FontSize:
                    registry.Apply(handles, specificity, ref fontSize, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.FontStyle:
                    registry.Apply(handles, specificity, ref fontStyle, StyleSheetApplicator.ApplyEnum <FontStyle>);
                    break;

                case StylePropertyID.FlexDirection:
                    registry.Apply(handles, specificity, ref flexDirection, StyleSheetApplicator.ApplyEnum <FlexDirection>);
                    break;

                case StylePropertyID.FlexWrap:
                    registry.Apply(handles, specificity, ref flexWrap, StyleSheetApplicator.ApplyEnum <Wrap>);
                    break;

                case StylePropertyID.Height:
                    registry.Apply(handles, specificity, ref height, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.JustifyContent:
                    registry.Apply(handles, specificity, ref justifyContent, StyleSheetApplicator.ApplyEnum <Justify>);
                    break;

                case StylePropertyID.MarginLeft:
                    registry.Apply(handles, specificity, ref marginLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginTop:
                    registry.Apply(handles, specificity, ref marginTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginRight:
                    registry.Apply(handles, specificity, ref marginRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MarginBottom:
                    registry.Apply(handles, specificity, ref marginBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MaxHeight:
                    registry.Apply(handles, specificity, ref maxHeight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MaxWidth:
                    registry.Apply(handles, specificity, ref maxWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MinHeight:
                    registry.Apply(handles, specificity, ref minHeight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.MinWidth:
                    registry.Apply(handles, specificity, ref minWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Overflow:
                    registry.Apply(handles, specificity, ref overflow, StyleSheetApplicator.ApplyEnum <Overflow>);
                    break;

                case StylePropertyID.PaddingLeft:
                    registry.Apply(handles, specificity, ref paddingLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingTop:
                    registry.Apply(handles, specificity, ref paddingTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingRight:
                    registry.Apply(handles, specificity, ref paddingRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PaddingBottom:
                    registry.Apply(handles, specificity, ref paddingBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionType:
                    registry.Apply(handles, specificity, ref positionType, StyleSheetApplicator.ApplyEnum <PositionType>);
                    break;

                case StylePropertyID.PositionTop:
                    registry.Apply(handles, specificity, ref positionTop, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionBottom:
                    registry.Apply(handles, specificity, ref positionBottom, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionLeft:
                    registry.Apply(handles, specificity, ref positionLeft, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.PositionRight:
                    registry.Apply(handles, specificity, ref positionRight, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.TextAlignment:
                    registry.Apply(handles, specificity, ref textAlignment, StyleSheetApplicator.ApplyEnum <TextAnchor>);
                    break;

                case StylePropertyID.TextClipping:
                    registry.Apply(handles, specificity, ref textClipping, StyleSheetApplicator.ApplyEnum <TextClipping>);
                    break;

                case StylePropertyID.TextColor:
                    registry.Apply(handles, specificity, ref textColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.Width:
                    registry.Apply(handles, specificity, ref width, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.WordWrap:
                    registry.Apply(handles, specificity, ref wordWrap, StyleSheetApplicator.ApplyBool);
                    break;

                case StylePropertyID.BackgroundColor:
                    registry.Apply(handles, specificity, ref backgroundColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.BackgroundSize:
                    registry.Apply(handles, specificity, ref backgroundSize, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.BorderColor:
                    registry.Apply(handles, specificity, ref borderColor, StyleSheetApplicator.ApplyColor);
                    break;

                case StylePropertyID.BorderLeftWidth:
                    registry.Apply(handles, specificity, ref borderLeftWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopWidth:
                    registry.Apply(handles, specificity, ref borderTopWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderRightWidth:
                    registry.Apply(handles, specificity, ref borderRightWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomWidth:
                    registry.Apply(handles, specificity, ref borderBottomWidth, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopLeftRadius:
                    registry.Apply(handles, specificity, ref borderTopLeftRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderTopRightRadius:
                    registry.Apply(handles, specificity, ref borderTopRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomRightRadius:
                    registry.Apply(handles, specificity, ref borderBottomRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.BorderBottomLeftRadius:
                    registry.Apply(handles, specificity, ref borderBottomLeftRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Cursor:
                    registry.Apply(handles, specificity, ref cursor, StyleSheetApplicator.ApplyCursor);
                    break;

                case StylePropertyID.SliceLeft:
                    registry.Apply(handles, specificity, ref sliceLeft, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceTop:
                    registry.Apply(handles, specificity, ref sliceTop, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceRight:
                    registry.Apply(handles, specificity, ref sliceRight, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.SliceBottom:
                    registry.Apply(handles, specificity, ref sliceBottom, StyleSheetApplicator.ApplyInt);
                    break;

                case StylePropertyID.Opacity:
                    registry.Apply(handles, specificity, ref opacity, StyleSheetApplicator.ApplyFloat);
                    break;

                // Shorthand values
                case StylePropertyID.BorderRadius:
                    registry.Apply(handles, specificity, ref borderTopLeftRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderTopRightRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderBottomLeftRadius, StyleSheetApplicator.ApplyFloat);
                    registry.Apply(handles, specificity, ref borderBottomRightRadius, StyleSheetApplicator.ApplyFloat);
                    break;

                case StylePropertyID.Custom:
                    if (m_CustomProperties == null)
                    {
                        m_CustomProperties = new Dictionary <string, CustomProperty>();
                    }
                    CustomProperty customProp = default(CustomProperty);
                    if (!m_CustomProperties.TryGetValue(styleProperty.name, out customProp) || specificity >= customProp.specificity)
                    {
                        customProp.handles     = handles;
                        customProp.data        = registry;
                        customProp.specificity = specificity;
                        m_CustomProperties[styleProperty.name] = customProp;
                    }
                    break;

                default:
                    throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", propertyID));
                }
            }
        }