Пример #1
0
        public void Test_rounding()
        {
            // Test that whole numbers are rounded to whole despite ceil/floor flags
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(6.000001f, 2.0f, false, false));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(6.000001f, 2.0f, true, false));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(6.000001f, 2.0f, false, true));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(5.999999f, 2.0f, false, false));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(5.999999f, 2.0f, true, false));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(5.999999f, 2.0f, false, true));
            // Same tests for negative numbers
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-6.000001f, 2.0f, false, false));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-6.000001f, 2.0f, true, false));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-6.000001f, 2.0f, false, true));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-5.999999f, 2.0f, false, false));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-5.999999f, 2.0f, true, false));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-5.999999f, 2.0f, false, true));

            // Test that numbers with fraction are rounded correctly accounting for ceil/floor flags
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(6.01f, 2.0f, false, false));
            Assert.AreEqual(6.5f, YogaMath.RoundValueToPixelGrid(6.01f, 2.0f, true, false));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(6.01f, 2.0f, false, true));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(5.99f, 2.0f, false, false));
            Assert.AreEqual(6.0f, YogaMath.RoundValueToPixelGrid(5.99f, 2.0f, true, false));
            Assert.AreEqual(5.5f, YogaMath.RoundValueToPixelGrid(5.99f, 2.0f, false, true));
            // Same tests for negative numbers
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-6.01f, 2.0f, false, false));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-6.01f, 2.0f, true, false));
            Assert.AreEqual(-6.5f, YogaMath.RoundValueToPixelGrid(-6.01f, 2.0f, false, true));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-5.99f, 2.0f, false, false));
            Assert.AreEqual(-5.5f, YogaMath.RoundValueToPixelGrid(-5.99f, 2.0f, true, false));
            Assert.AreEqual(-6.0f, YogaMath.RoundValueToPixelGrid(-5.99f, 2.0f, false, true));
        }
Пример #2
0
        public float GetTrailingBorder(YogaFlexDirection flexDirection)
        {
            if (flexDirection.IsRow() &&
                _style.Border[YogaEdge.End].Unit != YogaUnit.Undefined &&
                _style.Border[YogaEdge.End].Value != null &&
                _style.Border[YogaEdge.End].Value >= 0.0f)
            {
                return(_style.Border[YogaEdge.End].Value.Value);
            }

            var computedEdgeValue = ComputedEdgeValue(_style.Border, Trailing[flexDirection], YogaValue.Zero).Value;

            return(YogaMath.Max(computedEdgeValue, 0.0f));
        }
Пример #3
0
        public float GetLeadingBorder(YogaFlexDirection axis)
        {
            if (axis.IsRow() &&
                _style.Border[YogaEdge.Start].Unit != YogaUnit.Undefined &&
                _style.Border[YogaEdge.Start].Value != null &&
                _style.Border[YogaEdge.Start].Value >= 0.0f)
            {
                return(_style.Border[YogaEdge.Start].Value.Value);
            }

            var computedEdgeValue = ComputedEdgeValue(_style.Border, Leading[axis], YogaValue.Zero).Value;

            return(YogaMath.Max(computedEdgeValue, 0.0F));
        }
Пример #4
0
        public float GetTrailingPadding(YogaFlexDirection axis, float?widthSize)
        {
            var paddingEdgeEnd = _style.Padding[YogaEdge.End].Resolve(widthSize);

            if (axis.IsRow() &&
                _style.Padding[YogaEdge.End].Unit != YogaUnit.Undefined &&
                paddingEdgeEnd != null &&
                paddingEdgeEnd >= 0.0f)
            {
                return(paddingEdgeEnd.Value);
            }

            var resolvedValue = ComputedEdgeValue(_style.Padding, Trailing[axis], YogaValue.Zero).Resolve(widthSize);

            return(YogaMath.Max(resolvedValue, 0.0f));
        }