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:
committed by
Facebook Github Bot
parent
f222d22ba8
commit
0dbbfc5910
@@ -9,10 +9,10 @@
|
|||||||
|
|
||||||
namespace Facebook.CSSLayout
|
namespace Facebook.CSSLayout
|
||||||
{
|
{
|
||||||
public delegate long MeasureFunction(
|
public delegate long MeasureFunction(
|
||||||
CSSNode node,
|
CSSNode node,
|
||||||
float width,
|
float width,
|
||||||
CSSMeasureMode widthMode,
|
CSSMeasureMode widthMode,
|
||||||
float height,
|
float height,
|
||||||
CSSMeasureMode heightMode);
|
CSSMeasureMode heightMode);
|
||||||
}
|
}
|
||||||
|
@@ -11,19 +11,24 @@ namespace Facebook.CSSLayout
|
|||||||
{
|
{
|
||||||
public class MeasureOutput
|
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)
|
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)
|
public static int GetWidth(long measureOutput)
|
||||||
{
|
{
|
||||||
return (int) (0xFFFFFFFF & (measureOutput >> 32));
|
return (int) (0xFFFFFFFF & (measureOutput >> 32));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetHeight(long measureOutput)
|
public static int GetHeight(long measureOutput)
|
||||||
{
|
{
|
||||||
return (int) (0xFFFFFFFF & measureOutput);
|
return (int) (0xFFFFFFFF & measureOutput);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -157,8 +157,20 @@ namespace Facebook.CSSLayout
|
|||||||
return MeasureOutput.Make(100, 150);
|
return MeasureOutput.Make(100, 150);
|
||||||
});
|
});
|
||||||
node.CalculateLayout();
|
node.CalculateLayout();
|
||||||
Assert.AreEqual(100, (int)node.LayoutWidth);
|
Assert.AreEqual(100, node.LayoutWidth);
|
||||||
Assert.AreEqual(150, (int)node.LayoutHeight);
|
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]
|
[Test]
|
||||||
|
Reference in New Issue
Block a user