Example #1
0
 // Convert StyleLength to StyleFloat for IResolvedStyle
 internal static StyleFloat ToStyleFloat(this StyleLength styleLength)
 {
     return(new StyleFloat(styleLength.value.value, styleLength.keyword)
     {
         specificity = styleLength.specificity
     });
 }
Example #2
0
        private StyleFloat ResolveLengthValue(StyleLength styleLength, bool isRow)
        {
            if (styleLength.keyword != StyleKeyword.Undefined)
            {
                return(styleLength.ToStyleFloat());
            }

            var length = styleLength.value;

            if (length.unit != LengthUnit.Percent)
            {
                return(styleLength.ToStyleFloat());
            }

            var parent = hierarchy.parent;

            if (parent == null)
            {
                return(0f);
            }

            float parentSize = isRow ? parent.resolvedStyle.width : parent.resolvedStyle.height;

            return(length.value * parentSize / 100);
        }
 private static void AssignRect(RectOffset rect, StyleLength left, StyleLength top, StyleLength right, StyleLength bottom)
 {
     rect.left   = (int)left.GetSpecifiedValueOrDefault((float)rect.left);
     rect.top    = (int)top.GetSpecifiedValueOrDefault((float)rect.top);
     rect.right  = (int)right.GetSpecifiedValueOrDefault((float)rect.right);
     rect.bottom = (int)bottom.GetSpecifiedValueOrDefault((float)rect.bottom);
 }
Example #4
0
        internal static YogaValue ToYogaValue(this StyleLength styleValue)
        {
            if (styleValue.keyword == StyleKeyword.Auto)
            {
                return(YogaValue.Auto());
            }

            // For max-width and max-height
            if (styleValue.keyword == StyleKeyword.None)
            {
                return(float.NaN);
            }

            var length = styleValue.value;

            switch (length.unit)
            {
            case LengthUnit.Pixel:
                return(YogaValue.Point(length.value));

            case LengthUnit.Percent:
                return(YogaValue.Percent(length.value));

            default:
                Debug.LogAssertion($"Unexpected unit '{length.unit}'");
                return(float.NaN);
            }
        }
Example #5
0
        private bool SetStyleValue(StylePropertyId id, StyleLength inlineValue, StyleLength sharedValue)
        {
            var sv = new StyleValue();

            if (TryGetStyleValue(id, ref sv))
            {
                if (sv.length == inlineValue.value && sv.keyword == inlineValue.keyword)
                {
                    return(false);
                }
            }
            else if (inlineValue.keyword == StyleKeyword.Null)
            {
                return(false);
            }

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

            SetStyleValue(sv);

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

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

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

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

            SetInlineStyle(sv);

            int specificity = StyleValueExtensions.InlineSpecificity;

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

            ApplyStyleValue(sv, specificity);
            return(true);
        }
Example #7
0
        internal static float GetSpecifiedValueOrDefault(this StyleLength styleValue, float defaultValue)
        {
            if (styleValue.specificity != UndefinedSpecificity)
            {
                return(styleValue.value.value);
            }

            return(defaultValue);
        }
Example #8
0
        internal static Length ToLength(this StyleLength styleLength)
        {
            switch (styleLength.keyword)
            {
            case StyleKeyword.Auto:
            case StyleKeyword.None:
                return(styleLength.keyword.ToLength());

            default:
                return(styleLength.value);
            }
        }
        public override bool Equals(object obj)
        {
            bool flag = !(obj is StyleLength);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                StyleLength lhs = (StyleLength)obj;
                result = (lhs == this);
            }
            return(result);
        }
        public StyleLength GetStyleLength(StylePropertyId id)
        {
            StyleValue  styleValue = default(StyleValue);
            bool        flag       = this.TryGetStyleValue(id, ref styleValue);
            StyleLength result;

            if (flag)
            {
                result = new StyleLength(styleValue.length, styleValue.keyword);
            }
            else
            {
                result = StyleKeyword.Null;
            }
            return(result);
        }
Example #11
0
        internal static YogaValue ToYogaValue(this StyleLength styleValue)
        {
            if (styleValue.keyword == StyleKeyword.Auto)
            {
                return(YogaValue.Auto());
            }

            // For max-width and max-height
            if (styleValue.keyword == StyleKeyword.None)
            {
                return(float.NaN);
            }

            if (styleValue.specificity != UndefinedSpecificity)
            {
                return(styleValue.value.value);
            }

            return(float.NaN);
        }
Example #12
0
        internal static YogaValue ToYogaValue(this StyleLength styleValue)
        {
            bool      flag = styleValue.keyword == StyleKeyword.Auto;
            YogaValue result;

            if (flag)
            {
                result = YogaValue.Auto();
            }
            else
            {
                bool flag2 = styleValue.keyword == StyleKeyword.None;
                if (flag2)
                {
                    result = float.NaN;
                }
                else
                {
                    Length     value      = styleValue.value;
                    LengthUnit unit       = value.unit;
                    LengthUnit lengthUnit = unit;
                    if (lengthUnit != LengthUnit.Pixel)
                    {
                        if (lengthUnit != LengthUnit.Percent)
                        {
                            Debug.LogAssertion(string.Format("Unexpected unit '{0}'", value.unit));
                            result = float.NaN;
                        }
                        else
                        {
                            result = YogaValue.Percent(value.value);
                        }
                    }
                    else
                    {
                        result = YogaValue.Point(value.value);
                    }
                }
            }
            return(result);
        }
Example #13
0
 public bool Equals(StyleLength other)
 {
     return(other == this);
 }
Example #14
0
 internal static StyleFloat ToStyleFloat(this StyleLength styleLength)
 {
     return(new StyleFloat(styleLength.value.value, styleLength.keyword));
 }
 public StyleLength(float v)
 {
     this = new StyleLength(new Length(v, LengthUnit.Pixel), StyleKeyword.Undefined);
 }
 public StyleLength(Length v)
 {
     this = new StyleLength(v, StyleKeyword.Undefined);
 }
 public StyleLength(StyleKeyword keyword)
 {
     this = new StyleLength(default(Length), keyword);
 }