public void ApplyStyleValue(StyleValue sv, ComputedStyle parentStyle)
        {
            if (ApplyGlobalKeyword(sv, parentStyle))
            {
                return;
            }
            switch (sv.id)
            {
            case StylePropertyId.AlignContent:
                nonInheritedData.alignContent = (Align)sv.number;
                if (sv.keyword == StyleKeyword.Auto)
                {
                    nonInheritedData.alignContent = Align.Auto;
                }
                break;

            case StylePropertyId.AlignItems:
                nonInheritedData.alignItems = (Align)sv.number;
                if (sv.keyword == StyleKeyword.Auto)
                {
                    nonInheritedData.alignItems = Align.Auto;
                }
                break;

            case StylePropertyId.AlignSelf:
                nonInheritedData.alignSelf = (Align)sv.number;
                if (sv.keyword == StyleKeyword.Auto)
                {
                    nonInheritedData.alignSelf = Align.Auto;
                }
                break;

            case StylePropertyId.BackgroundColor:
                nonInheritedData.backgroundColor = sv.color;
                break;

            case StylePropertyId.BackgroundImage:
                nonInheritedData.backgroundImage = sv.resource.IsAllocated ? Background.FromObject(sv.resource.Target) : new Background();
                break;

            case StylePropertyId.BorderBottomColor:
                nonInheritedData.borderBottomColor = sv.color;
                break;

            case StylePropertyId.BorderBottomLeftRadius:
                nonInheritedData.borderBottomLeftRadius = sv.length;
                break;

            case StylePropertyId.BorderBottomRightRadius:
                nonInheritedData.borderBottomRightRadius = sv.length;
                break;

            case StylePropertyId.BorderBottomWidth:
                nonInheritedData.borderBottomWidth = sv.number;
                break;

            case StylePropertyId.BorderLeftColor:
                nonInheritedData.borderLeftColor = sv.color;
                break;

            case StylePropertyId.BorderLeftWidth:
                nonInheritedData.borderLeftWidth = sv.number;
                break;

            case StylePropertyId.BorderRightColor:
                nonInheritedData.borderRightColor = sv.color;
                break;

            case StylePropertyId.BorderRightWidth:
                nonInheritedData.borderRightWidth = sv.number;
                break;

            case StylePropertyId.BorderTopColor:
                nonInheritedData.borderTopColor = sv.color;
                break;

            case StylePropertyId.BorderTopLeftRadius:
                nonInheritedData.borderTopLeftRadius = sv.length;
                break;

            case StylePropertyId.BorderTopRightRadius:
                nonInheritedData.borderTopRightRadius = sv.length;
                break;

            case StylePropertyId.BorderTopWidth:
                nonInheritedData.borderTopWidth = sv.number;
                break;

            case StylePropertyId.Bottom:
                nonInheritedData.bottom = sv.length;
                break;

            case StylePropertyId.Color:
                inheritedData.color = sv.color;
                break;

            case StylePropertyId.Display:
                nonInheritedData.display = (DisplayStyle)sv.number;
                if (sv.keyword == StyleKeyword.None)
                {
                    nonInheritedData.display = DisplayStyle.None;
                }
                break;

            case StylePropertyId.FlexBasis:
                nonInheritedData.flexBasis = sv.length;
                break;

            case StylePropertyId.FlexDirection:
                nonInheritedData.flexDirection = (FlexDirection)sv.number;
                break;

            case StylePropertyId.FlexGrow:
                nonInheritedData.flexGrow = sv.number;
                break;

            case StylePropertyId.FlexShrink:
                nonInheritedData.flexShrink = sv.number;
                break;

            case StylePropertyId.FlexWrap:
                nonInheritedData.flexWrap = (Wrap)sv.number;
                break;

            case StylePropertyId.FontSize:
                inheritedData.fontSize = sv.length;
                break;

            case StylePropertyId.Height:
                nonInheritedData.height = sv.length;
                break;

            case StylePropertyId.JustifyContent:
                nonInheritedData.justifyContent = (Justify)sv.number;
                break;

            case StylePropertyId.Left:
                nonInheritedData.left = sv.length;
                break;

            case StylePropertyId.LetterSpacing:
                inheritedData.letterSpacing = sv.length;
                break;

            case StylePropertyId.MarginBottom:
                nonInheritedData.marginBottom = sv.length;
                break;

            case StylePropertyId.MarginLeft:
                nonInheritedData.marginLeft = sv.length;
                break;

            case StylePropertyId.MarginRight:
                nonInheritedData.marginRight = sv.length;
                break;

            case StylePropertyId.MarginTop:
                nonInheritedData.marginTop = sv.length;
                break;

            case StylePropertyId.MaxHeight:
                nonInheritedData.maxHeight = sv.length;
                break;

            case StylePropertyId.MaxWidth:
                nonInheritedData.maxWidth = sv.length;
                break;

            case StylePropertyId.MinHeight:
                nonInheritedData.minHeight = sv.length;
                break;

            case StylePropertyId.MinWidth:
                nonInheritedData.minWidth = sv.length;
                break;

            case StylePropertyId.Opacity:
                nonInheritedData.opacity = sv.number;
                break;

            case StylePropertyId.Overflow:
                nonInheritedData.overflow = (OverflowInternal)sv.number;
                break;

            case StylePropertyId.PaddingBottom:
                nonInheritedData.paddingBottom = sv.length;
                break;

            case StylePropertyId.PaddingLeft:
                nonInheritedData.paddingLeft = sv.length;
                break;

            case StylePropertyId.PaddingRight:
                nonInheritedData.paddingRight = sv.length;
                break;

            case StylePropertyId.PaddingTop:
                nonInheritedData.paddingTop = sv.length;
                break;

            case StylePropertyId.Position:
                nonInheritedData.position = (Position)sv.number;
                break;

            case StylePropertyId.Right:
                nonInheritedData.right = sv.length;
                break;

            case StylePropertyId.TextOverflow:
                nonInheritedData.textOverflow = (TextOverflow)sv.number;
                break;

            case StylePropertyId.Top:
                nonInheritedData.top = sv.length;
                break;

            case StylePropertyId.UnityBackgroundImageTintColor:
                nonInheritedData.unityBackgroundImageTintColor = sv.color;
                break;

            case StylePropertyId.UnityBackgroundScaleMode:
                nonInheritedData.unityBackgroundScaleMode = (ScaleMode)sv.number;
                break;

            case StylePropertyId.UnityFont:
                inheritedData.unityFont = sv.resource.IsAllocated ? sv.resource.Target as Font : null;
                break;

            case StylePropertyId.UnityFontDefinition:
                inheritedData.unityFontDefinition = sv.resource.IsAllocated ? FontDefinition.FromObject(sv.resource.Target) : new FontDefinition();
                break;

            case StylePropertyId.UnityFontStyleAndWeight:
                inheritedData.unityFontStyleAndWeight = (FontStyle)sv.number;
                break;

            case StylePropertyId.UnityOverflowClipBox:
                nonInheritedData.unityOverflowClipBox = (OverflowClipBox)sv.number;
                break;

            case StylePropertyId.UnityParagraphSpacing:
                inheritedData.unityParagraphSpacing = sv.length;
                break;

            case StylePropertyId.UnitySliceBottom:
                nonInheritedData.unitySliceBottom = (int)sv.number;
                break;

            case StylePropertyId.UnitySliceLeft:
                nonInheritedData.unitySliceLeft = (int)sv.number;
                break;

            case StylePropertyId.UnitySliceRight:
                nonInheritedData.unitySliceRight = (int)sv.number;
                break;

            case StylePropertyId.UnitySliceTop:
                nonInheritedData.unitySliceTop = (int)sv.number;
                break;

            case StylePropertyId.UnityTextAlign:
                inheritedData.unityTextAlign = (TextAnchor)sv.number;
                break;

            case StylePropertyId.UnityTextOutlineColor:
                inheritedData.unityTextOutlineColor = sv.color;
                break;

            case StylePropertyId.UnityTextOutlineWidth:
                inheritedData.unityTextOutlineWidth = sv.number;
                break;

            case StylePropertyId.UnityTextOverflowPosition:
                nonInheritedData.unityTextOverflowPosition = (TextOverflowPosition)sv.number;
                break;

            case StylePropertyId.Visibility:
                inheritedData.visibility = (Visibility)sv.number;
                break;

            case StylePropertyId.WhiteSpace:
                inheritedData.whiteSpace = (WhiteSpace)sv.number;
                break;

            case StylePropertyId.Width:
                nonInheritedData.width = sv.length;
                break;

            case StylePropertyId.WordSpacing:
                inheritedData.wordSpacing = sv.length;
                break;

            default:
                Debug.LogAssertion($"Unexpected property id {sv.id}");
                break;
            }
        }
 bool IStylePropertyAnimations.Start(StylePropertyId id, FontDefinition from, FontDefinition to, int durationMs, int delayMs, Func <float, float> easingCurve)
 {
     return(GetStylePropertyAnimationSystem().StartTransition(this, id, from, to, durationMs, delayMs, easingCurve));
 }
Example #3
0
        private bool SetStyleValue(StylePropertyId id, StyleFontDefinition inlineValue, FontDefinition sharedValue)
        {
            var sv = new StyleValue();

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

                if (sv.resource.IsAllocated)
                {
                    sv.resource.Free();
                }
            }
            else if (inlineValue.keyword == StyleKeyword.Null)
            {
                return(false);
            }

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

            SetStyleValue(sv);

            if (inlineValue.keyword == StyleKeyword.Null)
            {
                if (sharedValue.font != null)
                {
                    sv.resource = GCHandle.Alloc(sharedValue.font);
                }
                else if (sharedValue.fontAsset != null)
                {
                    sv.resource = GCHandle.Alloc(sharedValue.fontAsset);
                }
                else
                {
                    sv.resource = new GCHandle();
                }
            }

            ApplyStyleValue(sv);
            return(true);
        }