Clean up MeasureFunc and PrintFunc
Summary: - Remove unneeded instance variables - Simplify MeasureFunc call - Add unittest Reviewed By: emilsjolander Differential Revision: D4013176 fbshipit-source-id: 4cdfa3ac3ad60a6bac5cda10644376ee9c46300b
This commit is contained in:
committed by
Facebook Github Bot
parent
722bfb9032
commit
7548164edb
@@ -22,14 +22,10 @@ namespace Facebook.CSSLayout
|
||||
private WeakReference _parent;
|
||||
private List<CSSNode> _children;
|
||||
private MeasureFunction _measureFunction;
|
||||
private CSSMeasureFunc _measureFunc;
|
||||
private CSSPrintFunc _printFunc;
|
||||
private object _data;
|
||||
|
||||
public CSSNode()
|
||||
{
|
||||
_measureFunc = MeasureInternal;
|
||||
_printFunc = PrintInternal;
|
||||
Reinitialize();
|
||||
}
|
||||
|
||||
@@ -116,7 +112,7 @@ namespace Facebook.CSSLayout
|
||||
CSSAssert.Initialize();
|
||||
_cssNode = Native.CSSNodeNew();
|
||||
_children = new List<CSSNode>(4);
|
||||
Native.CSSNodeSetPrintFunc(_cssNode, _printFunc);
|
||||
Native.CSSNodeSetPrintFunc(_cssNode, PrintInternal);
|
||||
}
|
||||
|
||||
public void Free()
|
||||
@@ -681,7 +677,7 @@ namespace Facebook.CSSLayout
|
||||
{
|
||||
AssertNativeInstance();
|
||||
_measureFunction = measureFunction;
|
||||
Native.CSSNodeSetMeasureFunc(_cssNode, measureFunction != null ? _measureFunc : null);
|
||||
Native.CSSNodeSetMeasureFunc(_cssNode, measureFunction != null ? MeasureInternal : (CSSMeasureFunc)null);
|
||||
}
|
||||
|
||||
public void CalculateLayout()
|
||||
@@ -690,25 +686,6 @@ namespace Facebook.CSSLayout
|
||||
Native.CSSNodeCalculateLayout(_cssNode, CSSConstants.Undefined, CSSConstants.Undefined, Native.CSSNodeStyleGetDirection(_cssNode));
|
||||
}
|
||||
|
||||
public long Measure(CSSNode node, float width, CSSMeasureMode widthMode, float height, CSSMeasureMode heightMode)
|
||||
{
|
||||
if (_measureFunction == null)
|
||||
{
|
||||
throw new InvalidOperationException(@"Measure function is not defined.");
|
||||
}
|
||||
|
||||
var output = new MeasureOutput();
|
||||
|
||||
_measureFunction(this,
|
||||
width,
|
||||
widthMode,
|
||||
height,
|
||||
heightMode,
|
||||
output);
|
||||
|
||||
return ((long)output.Width) << 32 | ((long)output.Height);
|
||||
}
|
||||
|
||||
private CSSSize MeasureInternal(
|
||||
IntPtr context,
|
||||
float width,
|
||||
@@ -716,11 +693,15 @@ namespace Facebook.CSSLayout
|
||||
float height,
|
||||
CSSMeasureMode heightMode)
|
||||
{
|
||||
var measureResult = Measure(this, width, widthMode, height, heightMode);
|
||||
var measuredWidth = 0xFFFFFFFF & (measureResult >> 32);
|
||||
var measuredHeight = 0xFFFFFFFF & measureResult;
|
||||
if (_measureFunction == null)
|
||||
{
|
||||
throw new InvalidOperationException("Measure function is not defined.");
|
||||
}
|
||||
|
||||
return new CSSSize { width = measuredWidth, height = measuredHeight };
|
||||
var measureResult = new MeasureOutput();
|
||||
_measureFunction(this, width, widthMode, height, heightMode, measureResult);
|
||||
|
||||
return new CSSSize { width = measureResult.Width, height = measureResult.Height };
|
||||
}
|
||||
|
||||
private void PrintInternal(IntPtr context)
|
||||
|
Reference in New Issue
Block a user