Esempio n. 1
0
        public VisualElementStylesData(bool isShared)
        {
            this.isShared = isShared;

            // Initialize non trivial properties
            left                          = StyleSheetCache.GetInitialValue(StylePropertyID.PositionLeft).ToStyleLength();
            top                           = StyleSheetCache.GetInitialValue(StylePropertyID.PositionTop).ToStyleLength();
            right                         = StyleSheetCache.GetInitialValue(StylePropertyID.PositionRight).ToStyleLength();
            bottom                        = StyleSheetCache.GetInitialValue(StylePropertyID.PositionBottom).ToStyleLength();
            width                         = StyleSheetCache.GetInitialValue(StylePropertyID.Width).ToStyleLength();
            height                        = StyleSheetCache.GetInitialValue(StylePropertyID.Height).ToStyleLength();
            minWidth                      = StyleSheetCache.GetInitialValue(StylePropertyID.MinWidth).ToStyleLength();
            minHeight                     = StyleSheetCache.GetInitialValue(StylePropertyID.MinHeight).ToStyleLength();
            maxWidth                      = StyleSheetCache.GetInitialValue(StylePropertyID.MaxWidth).ToStyleLength();
            maxHeight                     = StyleSheetCache.GetInitialValue(StylePropertyID.MaxHeight).ToStyleLength();
            alignSelf                     = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignSelf).number;
            alignItems                    = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignItems).number;
            alignContent                  = (int)StyleSheetCache.GetInitialValue(StylePropertyID.AlignContent).number;
            flexGrow                      = StyleSheetCache.GetInitialValue(StylePropertyID.FlexGrow).ToStyleFloat();
            flexShrink                    = StyleSheetCache.GetInitialValue(StylePropertyID.FlexShrink).ToStyleFloat();
            flexBasis                     = StyleSheetCache.GetInitialValue(StylePropertyID.FlexBasis).ToStyleLength();
            color                         = StyleSheetCache.GetInitialValue(StylePropertyID.Color).color;
            borderLeftColor               = StyleSheetCache.GetInitialValue(StylePropertyID.BorderLeftColor).color;
            borderTopColor                = StyleSheetCache.GetInitialValue(StylePropertyID.BorderTopColor).color;
            borderRightColor              = StyleSheetCache.GetInitialValue(StylePropertyID.BorderRightColor).color;
            borderBottomColor             = StyleSheetCache.GetInitialValue(StylePropertyID.BorderBottomColor).color;
            opacity                       = StyleSheetCache.GetInitialValue(StylePropertyID.Opacity).number;
            unityBackgroundImageTintColor = StyleSheetCache.GetInitialValue(StylePropertyID.BackgroundImageTintColor).color;
        }
        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;
            }
            }
        }
 public InheritedStylesData()
 {
     color = StyleSheetCache.GetInitialValue(StylePropertyID.Color).color;
 }