Esempio n. 1
0
 public static StyleValue Create(StylePropertyID id, int number)
 {
     return(new StyleValue()
     {
         id = id, number = number
     });
 }
Esempio n. 2
0
 public static StyleValue Create(StylePropertyID id, StyleKeyword keyword)
 {
     return(new StyleValue()
     {
         id = id, keyword = keyword
     });
 }
Esempio n. 3
0
 public static StyleValue Create(StylePropertyID id, Color color)
 {
     return(new StyleValue()
     {
         id = id, color = color
     });
 }
        private bool SetInlineStyle <T>(StylePropertyID id, StyleEnum <T> inlineValue, StyleInt sharedValue) where T : struct, IConvertible
        {
            var sv       = new StyleValue();
            int intValue = inlineValue.value.ToInt32(CultureInfo.InvariantCulture);

            if (TryGetInlineStyleValue(id, ref sv))
            {
                if (sv.number == intValue && sv.keyword == inlineValue.keyword)
                {
                    return(false);
                }
            }

            sv.id      = id;
            sv.keyword = inlineValue.keyword;
            sv.number  = intValue;

            SetInlineStyle(sv);

            int specificity = StyleValueExtensions.InlineSpecificity;

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                specificity = sharedValue.specificity;
                sv.keyword  = sharedValue.keyword;
                sv.number   = sharedValue.value;
            }

            ApplyStyleValue(sv, specificity);
            return(true);
        }
        private bool SetInlineStyle(StylePropertyID id, StyleColor inlineValue, StyleColor sharedValue)
        {
            var sv = new StyleValue();

            if (TryGetInlineStyleValue(id, ref sv))
            {
                if (sv.color == inlineValue.value && sv.keyword == inlineValue.keyword)
                {
                    return(false);
                }
            }

            sv.id      = id;
            sv.keyword = inlineValue.keyword;
            sv.color   = inlineValue.value;

            SetInlineStyle(sv);

            int specificity = StyleValueExtensions.InlineSpecificity;

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                specificity = sharedValue.specificity;
                sv.keyword  = sharedValue.keyword;
                sv.color    = sharedValue.value;
            }

            ApplyStyleValue(sv, specificity);
            return(true);
        }
Esempio n. 6
0
        internal void ApplyShorthandProperty(StyleSheet sheet, StylePropertyID propertyID, StyleValueHandle[] handles, int specificity)
        {
            switch (propertyID)
            {
            case StylePropertyID.BorderColor:
                ShorthandApplicator.ApplyBorderColor(sheet, handles, specificity, this);
                break;

            case StylePropertyID.BorderRadius:
                ShorthandApplicator.ApplyBorderRadius(sheet, handles, specificity, this);
                break;

            case StylePropertyID.BorderWidth:
                ShorthandApplicator.ApplyBorderWidth(sheet, handles, specificity, this);
                break;

            case StylePropertyID.Flex:
                ShorthandApplicator.ApplyFlex(sheet, handles, specificity, this);
                break;

            case StylePropertyID.Margin:
                ShorthandApplicator.ApplyMargin(sheet, handles, specificity, this);
                break;

            case StylePropertyID.Padding:
                ShorthandApplicator.ApplyPadding(sheet, handles, specificity, this);
                break;

            default:
                throw new ArgumentException(string.Format("Non exhaustive switch statement (value={0})", propertyID));
            }
        }
Esempio n. 7
0
 public static StyleValue Create(StylePropertyID id)
 {
     return(new StyleValue()
     {
         id = id
     });
 }
Esempio n. 8
0
        private bool SetStyleValue(StylePropertyID id, StyleBackground inlineValue, StyleBackground sharedValue)
        {
            var sv = new StyleValue();

            if (TryGetStyleValue(id, ref sv))
            {
                var vectorImage = sv.resource.IsAllocated ? sv.resource.Target as VectorImage : null;
                var texture     = sv.resource.IsAllocated ? sv.resource.Target as Texture2D : null;
                if ((vectorImage == inlineValue.value.vectorImage && texture == inlineValue.value.texture) && sv.keyword == inlineValue.keyword)
                {
                    return(false);
                }

                if (sv.resource.IsAllocated)
                {
                    sv.resource.Free();
                }
            }

            sv.id      = id;
            sv.keyword = inlineValue.keyword;
            if (inlineValue.value.vectorImage != null)
            {
                sv.resource = GCHandle.Alloc(inlineValue.value.vectorImage);
            }
            else if (inlineValue.value.texture != null)
            {
                sv.resource = GCHandle.Alloc(inlineValue.value.texture);
            }
            else
            {
                sv.resource = new GCHandle();
            }

            SetStyleValue(sv);

            int specificity = StyleValueExtensions.InlineSpecificity;

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                specificity = sharedValue.specificity;
                sv.keyword  = sharedValue.keyword;
                if (sharedValue.value.texture != null)
                {
                    sv.resource = GCHandle.Alloc(sharedValue.value.texture);
                }
                else if (sharedValue.value.vectorImage != null)
                {
                    sv.resource = GCHandle.Alloc(sharedValue.value.vectorImage);
                }
                else
                {
                    sv.resource = new GCHandle();
                }
            }

            ApplyStyleValue(sv, specificity);
            return(true);
        }
Esempio n. 9
0
        internal void SetValue(StylePropertyID id, float value)
        {
            var sv = new StyleValue();

            sv.id     = id;
            sv.number = value;
            Values().SetStyleValue(sv);
        }
Esempio n. 10
0
        internal void SetValue(StylePropertyID id, Color value)
        {
            var sv = new StyleValue();

            sv.id    = id;
            sv.color = value;
            Values().SetStyleValue(sv);
        }
        private StyleInt GetInlineStyleInt(StylePropertyID id)
        {
            var inline = new StyleValue();

            if (TryGetInlineStyleValue(id, ref inline))
            {
                return(new StyleInt((int)inline.number, inline.keyword));
            }
            return(StyleKeyword.Null);
        }
        private StyleColor GetInlineStyleColor(StylePropertyID id)
        {
            var inline = new StyleValue();

            if (TryGetInlineStyleValue(id, ref inline))
            {
                return(new StyleColor(inline.color, inline.keyword));
            }
            return(StyleKeyword.Null);
        }
Esempio n. 13
0
        public StyleFloat GetStyleFloat(StylePropertyID id)
        {
            var inline = new StyleValue();

            if (TryGetStyleValue(id, ref inline))
            {
                return(new StyleFloat(inline.number, inline.keyword));
            }
            return(StyleKeyword.Null);
        }
        private StyleBackground GetInlineStyleBackground(StylePropertyID id)
        {
            var inline = new StyleValue();

            if (TryGetInlineStyleValue(id, ref inline))
            {
                var texture = inline.resource.IsAllocated ? inline.resource.Target as Texture2D : null;
                return(new StyleBackground(texture, inline.keyword));
            }
            return(StyleKeyword.Null);
        }
        private StyleFont GetInlineStyleFont(StylePropertyID id)
        {
            var inline = new StyleValue();

            if (TryGetInlineStyleValue(id, ref inline))
            {
                var font = inline.resource.IsAllocated ? inline.resource.Target as Font : null;
                return(new StyleFont(font, inline.keyword));
            }
            return(StyleKeyword.Null);
        }
Esempio n. 16
0
 internal void ApplyStyleValue(StylePropertyID propertyID, StyleValue value, int specificity)
 {
     if (value.keyword == StyleKeyword.Initial)
     {
         ApplyInitialStyleValue(propertyID, specificity);
     }
     else
     {
         s_StyleValueApplicator.currentStyleValue = value;
         ApplyStyleProperty(s_StyleValueApplicator, null, propertyID, null, specificity);
     }
 }
Esempio n. 17
0
        // Used by tests
        internal static string GetPropertyIDUssName(StylePropertyID propertyId)
        {
            foreach (var kvp in s_NameToIDCache)
            {
                if (propertyId == kvp.Value)
                {
                    return(kvp.Key);
                }
            }

            return(string.Empty);
        }
 internal void ApplyStyleValue(StylePropertyID propertyID, StyleValue value, int specificity)
 {
     if (value.keyword == StyleKeyword.Initial)
     {
         ApplyInitialStyleValue(propertyID, specificity);
     }
     else
     {
         s_StyleValuePropertyReader.Set(propertyID, value, specificity);
         ApplyStyleProperty(s_StyleValuePropertyReader);
     }
 }
 public bool TryGetInlineStyleValue(StylePropertyID id, ref StyleValue value)
 {
     value.id = StylePropertyID.Unknown;
     foreach (var inlineStyle in m_InlineStyleValues)
     {
         if (inlineStyle.id == id)
         {
             value = inlineStyle;
             return(true);
         }
     }
     return(false);
 }
 internal static StylePropertyID[] GetPropertyIDs(StyleSheet sheet, int ruleIndex)
 {
     StyleSheetCache.SheetHandleKey key = new StyleSheetCache.SheetHandleKey(sheet, ruleIndex);
     StylePropertyID[] array;
     if (!StyleSheetCache.s_RulePropertyIDsCache.TryGetValue(key, out array))
     {
         StyleRule styleRule = sheet.rules[ruleIndex];
         array = new StylePropertyID[styleRule.properties.Length];
         for (int i = 0; i < array.Length; i++)
         {
             array[i] = StyleSheetCache.GetPropertyID(styleRule.properties[i].name);
         }
         StyleSheetCache.s_RulePropertyIDsCache.Add(key, array);
     }
     return(array);
 }
Esempio n. 21
0
        internal static StylePropertyID[] GetPropertyIDs(StyleSheet sheet, int ruleIndex)
        {
            SheetHandleKey key = new SheetHandleKey(sheet, ruleIndex);

            StylePropertyID[] propertyIDs;
            if (!s_RulePropertyIDsCache.TryGetValue(key, out propertyIDs))
            {
                StyleRule rule = sheet.rules[ruleIndex];
                propertyIDs = new StylePropertyID[rule.properties.Length];
                for (int i = 0; i < propertyIDs.Length; i++)
                {
                    propertyIDs[i] = GetPropertyID(sheet, rule, i);
                }
                s_RulePropertyIDsCache.Add(key, propertyIDs);
            }
            return(propertyIDs);
        }
        private bool SetInlineStyle(StylePropertyID id, StyleFont inlineValue, StyleFont sharedValue)
        {
            var sv = new StyleValue();

            if (TryGetInlineStyleValue(id, ref sv))
            {
                if (sv.resource.IsAllocated)
                {
                    var font = sv.resource.IsAllocated ? sv.resource.Target as Font : null;
                    if (font == inlineValue.value && sv.keyword == inlineValue.keyword)
                    {
                        return(false);
                    }

                    if (sv.resource.IsAllocated)
                    {
                        sv.resource.Free();
                    }
                }
            }

            sv.id       = id;
            sv.keyword  = inlineValue.keyword;
            sv.resource = inlineValue.value != null?GCHandle.Alloc(inlineValue.value) : new GCHandle();

            SetInlineStyle(sv);

            int specificity = StyleValueExtensions.InlineSpecificity;

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                specificity = sharedValue.specificity;
                sv.keyword  = sharedValue.keyword;
                sv.resource = sharedValue.value != null?GCHandle.Alloc(sharedValue.value) : new GCHandle();
            }

            ApplyStyleValue(sv, specificity);
            return(true);
        }
        private void ApplyInitialStyleValue(StylePropertyID propertyID, int specificity)
        {
            switch (propertyID)
            {
            case StylePropertyID.Unknown:
            case StylePropertyID.Custom:
            {
                Debug.LogAssertion($"Unexpected style property ID {propertyID.ToString()}.");
                break;
            }

            case StylePropertyID.BorderColor:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderLeftColor);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopColor);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderRightColor);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomColor);
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }

            case StylePropertyID.BorderRadius:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopLeftRadius);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopRightRadius);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomLeftRadius);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomRightRadius);
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }

            case StylePropertyID.BorderWidth:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderLeftWidth);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopWidth);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderRightWidth);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomWidth);
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }

            case StylePropertyID.Flex:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(StylePropertyID.FlexGrow);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.FlexShrink);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.FlexBasis);
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }

            case StylePropertyID.Margin:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(StylePropertyID.MarginLeft);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.MarginTop);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.MarginRight);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.MarginBottom);
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }

            case StylePropertyID.Padding:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(StylePropertyID.PaddingLeft);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.PaddingTop);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.PaddingRight);
                ApplyStyleValue(sv.id, sv, specificity);

                sv = StyleSheetCache.GetInitialValue(StylePropertyID.PaddingBottom);
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }

            case StylePropertyID.Cursor:
            {
                ApplyStyleCursor(new StyleCursor(), specificity);
                break;
            }

            default:
            {
                StyleValue sv = StyleSheetCache.GetInitialValue(propertyID);
                Debug.Assert(sv.keyword != StyleKeyword.Initial, "Recursive apply initial value");
                ApplyStyleValue(sv.id, sv, specificity);
                break;
            }
            }
        }
        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));
                }
            }
        }
Esempio n. 25
0
 internal static StyleValue GetInitialValue(StylePropertyID propertyId)
 {
     Debug.Assert(propertyId != StylePropertyID.Unknown && propertyId != StylePropertyID.Custom);
     return(s_InitialStyleValues[(int)propertyId]);
 }
Esempio n. 26
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));
                }
            }
        }
Esempio n. 27
0
 internal StylePropertyAttribute(string propertyName, StylePropertyID propertyID)
 {
     this.propertyName = propertyName;
     this.propertyID   = propertyID;
 }
 public void Set(StylePropertyID id, StyleValue value, int spec)
 {
     propertyID          = id;
     m_CurrentStyleValue = value;
     specificity         = spec;
 }
Esempio n. 29
0
        internal void ApplyStyleProperty(IStyleSheetApplicator applicator, StyleSheet sheet, StylePropertyID propertyID, StyleValueHandle[] handles, int specificity)
        {
            switch (propertyID)
            {
            case StylePropertyID.AlignContent:
                applicator.ApplyAlign(sheet, handles, specificity, ref alignContent);
                break;

            case StylePropertyID.AlignItems:
                applicator.ApplyAlign(sheet, handles, specificity, ref alignItems);
                break;

            case StylePropertyID.AlignSelf:
                applicator.ApplyAlign(sheet, handles, specificity, ref alignSelf);
                break;

            case StylePropertyID.BackgroundImage:
                applicator.ApplyImage(sheet, handles, specificity, ref backgroundImage);
                break;

            case StylePropertyID.FlexBasis:
                applicator.ApplyFlexBasis(sheet, handles, specificity, ref flexBasis);
                break;

            case StylePropertyID.FlexGrow:
                applicator.ApplyFloat(sheet, handles, specificity, ref flexGrow);
                break;

            case StylePropertyID.FlexShrink:
                applicator.ApplyFloat(sheet, handles, specificity, ref flexShrink);
                break;

            case StylePropertyID.Font:
                applicator.ApplyFont(sheet, handles, specificity, ref unityFont);
                break;

            case StylePropertyID.FontSize:
                applicator.ApplyLength(sheet, handles, specificity, ref fontSize);
                break;

            case StylePropertyID.FontStyleAndWeight:
                applicator.ApplyEnum <FontStyle>(sheet, handles, specificity, ref unityFontStyleAndWeight);
                break;

            case StylePropertyID.FlexDirection:
                applicator.ApplyEnum <FlexDirection>(sheet, handles, specificity, ref flexDirection);
                break;

            case StylePropertyID.FlexWrap:
                applicator.ApplyEnum <Wrap>(sheet, handles, specificity, ref flexWrap);
                break;

            case StylePropertyID.Height:
                applicator.ApplyLength(sheet, handles, specificity, ref height);
                break;

            case StylePropertyID.JustifyContent:
                applicator.ApplyEnum <Justify>(sheet, handles, specificity, ref justifyContent);
                break;

            case StylePropertyID.MarginLeft:
                applicator.ApplyLength(sheet, handles, specificity, ref marginLeft);
                break;

            case StylePropertyID.MarginTop:
                applicator.ApplyLength(sheet, handles, specificity, ref marginTop);
                break;

            case StylePropertyID.MarginRight:
                applicator.ApplyLength(sheet, handles, specificity, ref marginRight);
                break;

            case StylePropertyID.MarginBottom:
                applicator.ApplyLength(sheet, handles, specificity, ref marginBottom);
                break;

            case StylePropertyID.MaxHeight:
                applicator.ApplyLength(sheet, handles, specificity, ref maxHeight);
                break;

            case StylePropertyID.MaxWidth:
                applicator.ApplyLength(sheet, handles, specificity, ref maxWidth);
                break;

            case StylePropertyID.MinHeight:
                applicator.ApplyLength(sheet, handles, specificity, ref minHeight);
                break;

            case StylePropertyID.MinWidth:
                applicator.ApplyLength(sheet, handles, specificity, ref minWidth);
                break;

            case StylePropertyID.Overflow:
                applicator.ApplyEnum <OverflowInternal>(sheet, handles, specificity, ref overflow);
                break;

            case StylePropertyID.OverflowClipBox:
                applicator.ApplyEnum <OverflowClipBox>(sheet, handles, specificity, ref unityOverflowClipBox);
                break;

            case StylePropertyID.PaddingLeft:
                applicator.ApplyLength(sheet, handles, specificity, ref paddingLeft);
                break;

            case StylePropertyID.PaddingTop:
                applicator.ApplyLength(sheet, handles, specificity, ref paddingTop);
                break;

            case StylePropertyID.PaddingRight:
                applicator.ApplyLength(sheet, handles, specificity, ref paddingRight);
                break;

            case StylePropertyID.PaddingBottom:
                applicator.ApplyLength(sheet, handles, specificity, ref paddingBottom);
                break;

            case StylePropertyID.Position:
                applicator.ApplyEnum <Position>(sheet, handles, specificity, ref position);
                break;

            case StylePropertyID.PositionTop:
                applicator.ApplyLength(sheet, handles, specificity, ref top);
                break;

            case StylePropertyID.PositionBottom:
                applicator.ApplyLength(sheet, handles, specificity, ref bottom);
                break;

            case StylePropertyID.PositionLeft:
                applicator.ApplyLength(sheet, handles, specificity, ref left);
                break;

            case StylePropertyID.PositionRight:
                applicator.ApplyLength(sheet, handles, specificity, ref right);
                break;

            case StylePropertyID.UnityTextAlign:
                applicator.ApplyEnum <TextAnchor>(sheet, handles, specificity, ref unityTextAlign);
                break;

            case StylePropertyID.Color:
                applicator.ApplyColor(sheet, handles, specificity, ref color);
                break;

            case StylePropertyID.Width:
                applicator.ApplyLength(sheet, handles, specificity, ref width);
                break;

            case StylePropertyID.WhiteSpace:
                applicator.ApplyEnum <WhiteSpace>(sheet, handles, specificity, ref whiteSpace);
                break;

            case StylePropertyID.BackgroundColor:
                applicator.ApplyColor(sheet, handles, specificity, ref backgroundColor);
                break;

            case StylePropertyID.BackgroundScaleMode:
                applicator.ApplyEnum <ScaleMode>(sheet, handles, specificity, ref unityBackgroundScaleMode);
                break;

            case StylePropertyID.BackgroundImageTintColor:
                applicator.ApplyColor(sheet, handles, specificity, ref unityBackgroundImageTintColor);
                break;

            case StylePropertyID.BorderLeftColor:
                applicator.ApplyColor(sheet, handles, specificity, ref borderLeftColor);
                break;

            case StylePropertyID.BorderTopColor:
                applicator.ApplyColor(sheet, handles, specificity, ref borderTopColor);
                break;

            case StylePropertyID.BorderRightColor:
                applicator.ApplyColor(sheet, handles, specificity, ref borderRightColor);
                break;

            case StylePropertyID.BorderBottomColor:
                applicator.ApplyColor(sheet, handles, specificity, ref borderBottomColor);
                break;

            case StylePropertyID.BorderLeftWidth:
                applicator.ApplyFloat(sheet, handles, specificity, ref borderLeftWidth);
                break;

            case StylePropertyID.BorderTopWidth:
                applicator.ApplyFloat(sheet, handles, specificity, ref borderTopWidth);
                break;

            case StylePropertyID.BorderRightWidth:
                applicator.ApplyFloat(sheet, handles, specificity, ref borderRightWidth);
                break;

            case StylePropertyID.BorderBottomWidth:
                applicator.ApplyFloat(sheet, handles, specificity, ref borderBottomWidth);
                break;

            case StylePropertyID.BorderTopLeftRadius:
                applicator.ApplyLength(sheet, handles, specificity, ref borderTopLeftRadius);
                break;

            case StylePropertyID.BorderTopRightRadius:
                applicator.ApplyLength(sheet, handles, specificity, ref borderTopRightRadius);
                break;

            case StylePropertyID.BorderBottomRightRadius:
                applicator.ApplyLength(sheet, handles, specificity, ref borderBottomRightRadius);
                break;

            case StylePropertyID.BorderBottomLeftRadius:
                applicator.ApplyLength(sheet, handles, specificity, ref borderBottomLeftRadius);
                break;

            case StylePropertyID.Cursor:
                applicator.ApplyCursor(sheet, handles, specificity, ref cursor);
                break;

            case StylePropertyID.SliceLeft:
                applicator.ApplyInt(sheet, handles, specificity, ref unitySliceLeft);
                break;

            case StylePropertyID.SliceTop:
                applicator.ApplyInt(sheet, handles, specificity, ref unitySliceTop);
                break;

            case StylePropertyID.SliceRight:
                applicator.ApplyInt(sheet, handles, specificity, ref unitySliceRight);
                break;

            case StylePropertyID.SliceBottom:
                applicator.ApplyInt(sheet, handles, specificity, ref unitySliceBottom);
                break;

            case StylePropertyID.Opacity:
                applicator.ApplyFloat(sheet, handles, specificity, ref opacity);
                break;

            case StylePropertyID.Visibility:
                applicator.ApplyEnum <Visibility>(sheet, handles, specificity, ref visibility);
                break;

            case StylePropertyID.Display:
                applicator.ApplyDisplay(sheet, handles, specificity, ref display);
                break;

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