From cd78291de5779adb9aa1fcf5c900a25375c591ab Mon Sep 17 00:00:00 2001 From: Lukas Woehrl Date: Sat, 24 Dec 2016 02:40:25 -0800 Subject: [PATCH] C# use YogaSize throughout the measure call chain Summary: Java still has the same problem (see #296) Also there is no need to have double in the method signature as we only use float internally, which could confuse some. Closes https://github.com/facebook/yoga/pull/300 Reviewed By: splhack Differential Revision: D4365993 Pulled By: emilsjolander fbshipit-source-id: 681f8b1725e63eddcfb9a6c756f2ae215a44425a --- csharp/Facebook.Yoga/MeasureFunction.cs | 2 +- csharp/Facebook.Yoga/MeasureOutput.cs | 19 ++----------------- csharp/Facebook.Yoga/YogaNode.cs | 3 +-- csharp/tests/Facebook.Yoga/YogaNodeTest.cs | 4 ++-- 4 files changed, 6 insertions(+), 22 deletions(-) diff --git a/csharp/Facebook.Yoga/MeasureFunction.cs b/csharp/Facebook.Yoga/MeasureFunction.cs index f25ec6da..d5056ec9 100644 --- a/csharp/Facebook.Yoga/MeasureFunction.cs +++ b/csharp/Facebook.Yoga/MeasureFunction.cs @@ -9,7 +9,7 @@ namespace Facebook.Yoga { - public delegate long MeasureFunction( + public delegate YogaSize MeasureFunction( YogaNode node, float width, YogaMeasureMode widthMode, diff --git a/csharp/Facebook.Yoga/MeasureOutput.cs b/csharp/Facebook.Yoga/MeasureOutput.cs index 380b5b2c..52693b82 100644 --- a/csharp/Facebook.Yoga/MeasureOutput.cs +++ b/csharp/Facebook.Yoga/MeasureOutput.cs @@ -11,24 +11,9 @@ namespace Facebook.Yoga { public class MeasureOutput { - public static long Make(double width, double height) + public static YogaSize Make(float width, float height) { - return Make((int) width, (int) height); - } - - public static long Make(int width, int height) - { - return (long)(((ulong) width) << 32 | ((uint) height)); - } - - public static int GetWidth(long measureOutput) - { - return (int) (0xFFFFFFFF & (measureOutput >> 32)); - } - - public static int GetHeight(long measureOutput) - { - return (int) (0xFFFFFFFF & measureOutput); + return new YogaSize { width = width, height = height}; } } } diff --git a/csharp/Facebook.Yoga/YogaNode.cs b/csharp/Facebook.Yoga/YogaNode.cs index ab2989e8..96a4d629 100644 --- a/csharp/Facebook.Yoga/YogaNode.cs +++ b/csharp/Facebook.Yoga/YogaNode.cs @@ -532,8 +532,7 @@ namespace Facebook.Yoga throw new InvalidOperationException("Measure function is not defined."); } - long output = _measureFunction(this, width, widthMode, height, heightMode); - return new YogaSize { width = MeasureOutput.GetWidth(output), height = MeasureOutput.GetHeight(output) }; + return _measureFunction(this, width, widthMode, height, heightMode); } public string Print(YogaPrintOptions options = diff --git a/csharp/tests/Facebook.Yoga/YogaNodeTest.cs b/csharp/tests/Facebook.Yoga/YogaNodeTest.cs index 7efd2a67..b9e20982 100644 --- a/csharp/tests/Facebook.Yoga/YogaNodeTest.cs +++ b/csharp/tests/Facebook.Yoga/YogaNodeTest.cs @@ -169,8 +169,8 @@ namespace Facebook.Yoga return MeasureOutput.Make(123.4f, 81.7f); }); node.CalculateLayout(); - Assert.AreEqual(123, node.LayoutWidth); - Assert.AreEqual(81, node.LayoutHeight); + Assert.AreEqual(123.4f, node.LayoutWidth); + Assert.AreEqual(81.7f, node.LayoutHeight); } [Test]