Add convenient cast method for MeasureOutput.Make

Summary: Same as Java, it allows to use float and double values in Make arguments.

Reviewed By: emilsjolander

Differential Revision: D4163347

fbshipit-source-id: f373247b3f37e7940a66044000cca2935068decf
This commit is contained in:
Kazuki Sakamoto
2016-11-10 19:13:19 -08:00
committed by Facebook Github Bot
parent f222d22ba8
commit 0dbbfc5910
3 changed files with 28 additions and 11 deletions

View File

@@ -9,10 +9,10 @@
namespace Facebook.CSSLayout
{
public delegate long MeasureFunction(
CSSNode node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
public delegate long MeasureFunction(
CSSNode node,
float width,
CSSMeasureMode widthMode,
float height,
CSSMeasureMode heightMode);
}

View File

@@ -11,19 +11,24 @@ namespace Facebook.CSSLayout
{
public class MeasureOutput
{
public static long Make(double width, double height)
{
return Make((int) width, (int) height);
}
public static long Make(int width, int height)
{
return (long)(((ulong) width) << 32 | ((ulong) height));
return (long)(((ulong) width) << 32 | ((ulong) height));
}
public static int GetWidth(long measureOutput)
{
return (int) (0xFFFFFFFF & (measureOutput >> 32));
return (int) (0xFFFFFFFF & (measureOutput >> 32));
}
public static int GetHeight(long measureOutput)
{
return (int) (0xFFFFFFFF & measureOutput);
return (int) (0xFFFFFFFF & measureOutput);
}
}
}

View File

@@ -157,8 +157,20 @@ namespace Facebook.CSSLayout
return MeasureOutput.Make(100, 150);
});
node.CalculateLayout();
Assert.AreEqual(100, (int)node.LayoutWidth);
Assert.AreEqual(150, (int)node.LayoutHeight);
Assert.AreEqual(100, node.LayoutWidth);
Assert.AreEqual(150, node.LayoutHeight);
}
[Test]
public void TestMeasureFuncWithFloat()
{
CSSNode node = new CSSNode();
node.SetMeasureFunction((_, width, widthMode, height, heightMode) => {
return MeasureOutput.Make(123.4f, 81.7f);
});
node.CalculateLayout();
Assert.AreEqual(123, node.LayoutWidth);
Assert.AreEqual(81, node.LayoutHeight);
}
[Test]