浏览代码

review rendering T to END

/siyaoH-1.17-PlatformMessage
guanghuispark 4 年前
当前提交
1a43f539
共有 7 个文件被更改,包括 184 次插入129 次删除
  1. 101
      com.unity.uiwidgets/Runtime/rendering/table.cs
  2. 6
      com.unity.uiwidgets/Runtime/rendering/table_border.cs
  3. 1
      com.unity.uiwidgets/Runtime/rendering/texture.cs
  4. 12
      com.unity.uiwidgets/Runtime/rendering/tweens.cs
  5. 28
      com.unity.uiwidgets/Runtime/rendering/view.cs
  6. 144
      com.unity.uiwidgets/Runtime/rendering/viewport.cs
  7. 21
      com.unity.uiwidgets/Runtime/rendering/wrap.cs

101
com.unity.uiwidgets/Runtime/rendering/table.cs


int? rows = null,
Dictionary<int, TableColumnWidth> columnWidths = null,
TableColumnWidth defaultColumnWidth = null,
TextDirection? textDirection = null,
TableBorder border = null,
List<Decoration> rowDecorations = null,
ImageConfiguration configuration = null,

) {
defaultColumnWidth = defaultColumnWidth ?? new FlexColumnWidth(1.0f);
configuration = configuration ?? ImageConfiguration.empty;
_textDirection = textDirection ?? TextDirection.ltr;
_columns = columns ?? (children != null && children.isNotEmpty() ? children[0].Count : 0);
_rows = rows ?? 0;
_children = new List<RenderBox>();

_columnWidths = columnWidths ?? new Dictionary<int, TableColumnWidth>();
_defaultColumnWidth = defaultColumnWidth;
_defaultColumnWidth = defaultColumnWidth ?? new FlexColumnWidth(1.0f);
_configuration = configuration;
_configuration = configuration ?? ImageConfiguration.empty;
_defaultVerticalAlignment = defaultVerticalAlignment;
_textBaseline = textBaseline;

TableColumnWidth _defaultColumnWidth;
TextDirection textDirection {
get {
return _textDirection;
}
set {
if (_textDirection == value)
return;
_textDirection = value;
markNeedsLayout();
}
}
TextDirection _textDirection;
public TableBorder border {
get { return _border; }
set {

painter?.Dispose();
}
_rowDecorationPainters = null;
_rowDecorationPainters = new List<BoxPainter>();
for (int i = 0; i < _rowDecorations.Count; i++) {
_rowDecorationPainters.Add(null);
}
}
foreach (RenderBox child in _children) {

float? _baselineDistance;
protected override float? computeDistanceToActualBaseline(TextBaseline baseline) {
D.assert(!debugNeedsLayout);
return _baselineDistance;
}

}
}
D.assert(tableWidth >= targetWidth);
D.assert(tableWidth + foundation_.precisionErrorTolerance >= targetWidth);
}
}
else if (tableWidth < minWidthConstraint) {

//(Xingwei Zhu) this deficit is double and set to be 0.00000001f in flutter.
//since we use float by default, making it larger should make sense in most cases
float minimumDeficit = 0.0001f;
while (deficit > minimumDeficit && totalFlex > minimumDeficit) {
while (deficit > foundation_.precisionErrorTolerance && totalFlex > foundation_.precisionErrorTolerance) {
float newTotalFlex = 0.0f;
for (int x = 0; x < columns; x++) {
if (flexes[x] != null) {

widths[x] - Mathf.Max(minimumDeficit, deficit * flexes[x].Value / totalFlex);
widths[x] - Mathf.Max(foundation_.precisionErrorTolerance, deficit * flexes[x].Value / totalFlex);
D.assert(newWidth.isFinite());
if (newWidth <= minWidths[x]) {
deficit -= widths[x] - minWidths[x];

totalFlex = newTotalFlex;
}
if (deficit > 0.0f) {
do {
float delta = deficit / availableColumns;
int newAvailableColumns = 0;
for (int x = 0; x < columns; x++) {
float availableDelta = widths[x] - minWidths[x];
if (availableDelta > 0.0f) {
if (availableDelta <= delta) {
deficit -= widths[x] - minWidths[x];
widths[x] = minWidths[x];
}
else {
deficit -= availableDelta;
widths[x] -= availableDelta;
newAvailableColumns += 1;
}
while (deficit > foundation_.precisionErrorTolerance && availableColumns > 0) {
float delta = deficit / availableColumns;
D.assert(delta != 0);
int newAvailableColumns = 0;
for (int x = 0; x < columns; x++) {
float availableDelta = widths[x] - minWidths[x];
if (availableDelta > 0.0f) {
if (availableDelta <= delta) {
deficit -= widths[x] - minWidths[x];
widths[x] = minWidths[x];
}
else {
deficit -= availableDelta;
widths[x] -= availableDelta;
newAvailableColumns += 1;
availableColumns = newAvailableColumns;
} while (deficit > 0.0f && availableColumns > 0);
}
availableColumns = newAvailableColumns;
return widths;
}

Rect getRowBox(int row) {
D.assert(row >= 0);
D.assert(row < rows);
D.assert(!debugNeedsLayout);
BoxConstraints constraints = this.constraints;
int rows = this.rows;
int columns = this.columns;
D.assert(_children.Count == rows * columns);

List<float> widths = _computeColumnWidths(constraints);
List<float> positions = new List<float>();
for (int i = 0; i < columns; i++) {
positions.Add(0.0f);
}
positions.Add(0.0f);
for (int x = 1; x < columns; x++) {
positions.Add(positions[x - 1] + widths[x - 1]);
switch (textDirection) {
case TextDirection.rtl:
positions[columns - 1] = 0.0f;
for (int x = columns - 2; x >= 0; x -= 1)
positions[x] = positions[x+1] + widths[x+1];
_columnLefts = positions;
tableWidth = positions[0] + widths[0];
break;
case TextDirection.ltr:
positions[0] = 0.0f;
for (int x = 1; x < columns; x += 1)
positions[x] = positions[x-1] + widths[x-1];
_columnLefts = positions;
tableWidth = positions[columns - 1] + widths[columns - 1];
break;
_columnLefts = positions;
tableWidth = positions[positions.Count - 1] + widths[widths.Count - 1];
_rowTops.Clear();
_baselineDistance = null;

D.assert(_rowTops.Count == this.rows + 1);
if (_rowDecorations != null) {
D.assert(_rowDecorations.Count == _rowDecorationPainters.Count);
Canvas canvas = context.canvas;
for (int y = 0; y < rows; y++) {
if (_rowDecorations.Count <= y) {

6
com.unity.uiwidgets/Runtime/rendering/table_border.cs


public EdgeInsets dimensions {
get {
return EdgeInsets.fromLTRB(left.width,
return EdgeInsets.fromLTRB(
left.width,
bottom.width);
bottom.width
);
}
}

1
com.unity.uiwidgets/Runtime/rendering/texture.cs


public class TextureBox : RenderBox {
public TextureBox(int textureId) {
D.assert(textureId != null);
_textureId = textureId;
}

12
com.unity.uiwidgets/Runtime/rendering/tweens.cs


using Unity.UIWidgets.painting;
namespace Unity.UIWidgets.rendering {
public class FractionalOffsetTween : Tween<FractionalOffset> {
public FractionalOffsetTween(FractionalOffset begin = null, FractionalOffset end = null)
: base(begin: begin, end: end) {
}
public override FractionalOffset lerp(float t) {
return FractionalOffset.lerp(begin, end, t);
}
}
public class AlignmentTween : Tween<Alignment> {
public AlignmentTween(
Alignment begin = null,

AlignmentGeometry begin = null,
AlignmentGeometry end = null
) : base(begin: begin, end: end) {
}
public override AlignmentGeometry lerp(float t) {
return AlignmentGeometry.lerp(begin, end, t);

28
com.unity.uiwidgets/Runtime/rendering/view.cs


public readonly float devicePixelRatio;
public Matrix4 toMatrix() {
//return new Matrix4().identity();
}
public override string ToString() {

public class RenderView : RenderObjectWithChildMixinRenderObject<RenderBox> {
public RenderView(
RenderBox child = null,
ViewConfiguration configuration = null) {
ViewConfiguration configuration = null,
ui.Window window = null) {
_window = window;
}
public Size size {

_configuration = value;
replaceRootLayer((OffsetLayer) _updateMatricesAndCreateNewRootLayer());
D.assert(_rootTransform != null);
public void scheduleInitialFrame() {
D.assert(owner != null);
scheduleInitialLayout();
scheduleInitialPaint((OffsetLayer) _updateMatricesAndCreateNewRootLayer());
owner.requestVisualUpdate();
}
ui.Window _window;
public void prepareInitialFrame() {
D.assert(owner != null);

Matrix4 _rootTransform;
public Layer _updateMatricesAndCreateNewRootLayer() {
public TransformLayer _updateMatricesAndCreateNewRootLayer() {
ContainerLayer rootLayer = new TransformLayer(transform: _rootTransform);
TransformLayer rootLayer = new TransformLayer(transform: _rootTransform);
rootLayer.attach(this);
return rootLayer;
}

}
protected override void performLayout() {
D.assert(_rootTransform != null);
_size = configuration.size;
D.assert(_size.isFinite);

}
public IEnumerable<MouseTrackerAnnotation> hitTestMouseTrackers(Offset position) {
// Layer hit testing is done using device pixels, so we have to convert
// the logical coordinates of the event location back to device pixels
// here.
/*return layer.find<MouseTrackerAnnotation>(
position * configuration.devicePixelRatio
);*/
return layer.findAllAnnotations<MouseTrackerAnnotation>(
position * configuration.devicePixelRatio
).annotations;

144
com.unity.uiwidgets/Runtime/rendering/viewport.cs


namespace Unity.UIWidgets.rendering {
public enum CacheExtentStyle {
/// Treat the [Viewport.cacheExtent] as logical pixels.
/// Treat the [Viewport.cacheExtent] as a multiplier of the main axis extent.
viewport,
}
public interface RenderAbstractViewport {

) {
D.assert(offset != null);
D.assert(AxisUtils.axisDirectionToAxis(axisDirection) != AxisUtils.axisDirectionToAxis(crossAxisDirection));
D.assert(axisDirection != null);
D.assert(crossAxisDirection != null);
D.assert(cacheExtentStyle != null);
D.assert(cacheExtent != null || cacheExtentStyle == CacheExtentStyle.pixel);
D.assert(cacheExtentStyle == CacheExtentStyle.pixel);
_axisDirection = axisDirection;
_crossAxisDirection = crossAxisDirection;
_offset = offset;

return _cacheExtentStyle;
}
set {
D.assert(value != null);
if (value == _cacheExtentStyle) {
return;
}

D.assert(() => {
if (!debugCheckingIntrinsics) {
D.assert(!(this is RenderShrinkWrappingViewport));
throw new UIWidgetsError(
GetType() + " does not support returning intrinsic dimensions.\n" +
"Calculating the intrinsic dimensions would require instantiating every child of " +
"the viewport, which defeats the point of viewports being lazy.\n" +
"If you are merely trying to shrink-wrap the viewport in the main axis direction, " +
"consider a RenderShrinkWrappingViewport render object (ShrinkWrappingViewport widget), " +
"which achieves that effect without implementing the intrinsic dimension API."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary($"{GetType()} does not support returning intrinsic dimensions."),
new ErrorDescription(
"Calculating the intrinsic dimensions would require instantiating every child of " +
"the viewport, which defeats the point of viewports being lazy."
),
new ErrorHint(
"If you are merely trying to shrink-wrap the viewport in the main axis direction, " +
"consider a RenderShrinkWrappingViewport render object (ShrinkWrappingViewport widget), " +
"which achieves that effect without implementing the intrinsic dimension API."
),
});
}
return true;

RenderSliver child = (RenderSliver) childRaw;
Rect viewportClip = Offset.zero & size;
if (child.constraints.overlap == 0.0) {
if (child.constraints.overlap == 0.0 || !child.constraints.viewportMainAxisExtent.isFinite()) {
return viewportClip;
}

RenderBox pivot = null;
bool onlySlivers = target is RenderSliver;
while (child.parent != this) {
D.assert(child.parent != null, () => $"target must be a descendant of ${this}");
D.assert(child.parent != null, () => $"{target} must be a descendant of {this}");
if (child is RenderBox) {
pivot = (RenderBox) child;
}

targetMainAxisExtent = bounds.height;
break;
case AxisDirection.right:
leadingScrollOffset += bounds.left;
float offset2 = 0.0f;
switch (growthDirection) {
case GrowthDirection.forward:
offset2 = bounds.left;
break;
case GrowthDirection.reverse:
offset2 = bounds.right;
break;
}
leadingScrollOffset += offset2;
leadingScrollOffset += bounds.top;
float offset3 = 0.0f;
switch (growthDirection) {
case GrowthDirection.forward:
offset3 = bounds.top;
break;
case GrowthDirection.reverse:
offset3 = bounds.bottom;
break;
}
leadingScrollOffset += offset3;
targetMainAxisExtent = bounds.height;
break;
case AxisDirection.left:

return MatrixUtils.transformRect(transform, rect ?? descendant.paintBounds);
}
D.assert(targetOffset != null);
offset.moveTo(targetOffset.offset, duration: duration.Value, curve: curve);
return targetOffset.rect;
}

switch (axis) {
case Axis.vertical:
if (!constraints.hasBoundedHeight) {
throw new UIWidgetsError(
"Vertical viewport was given unbounded height.\n" +
"Viewports expand in the scrolling direction to fill their container." +
"In this case, a vertical viewport was given an unlimited amount of " +
"vertical space in which to expand. This situation typically happens " +
"when a scrollable widget is nested inside another scrollable widget.\n" +
"If this widget is always nested in a scrollable widget there " +
"is no need to use a viewport because there will always be enough " +
"vertical space for the children. In this case, consider using a " +
"Column instead. Otherwise, consider using the \"shrinkWrap\" property " +
"(or a ShrinkWrappingViewport) to size the height of the viewport " +
"to the sum of the heights of its children."
);
throw new UIWidgetsError(new List<DiagnosticsNode> {
new ErrorSummary("Vertical viewport was given unbounded height."),
new ErrorDescription(
"Vertical viewport was given unbounded height.\n" +
"Viewports expand in the scrolling direction to fill their container." +
"In this case, a vertical viewport was given an unlimited amount of " +
"vertical space in which to expand. This situation typically happens " +
"when a scrollable widget is nested inside another scrollable widget.\n"
),
new ErrorHint("If this widget is always nested in a scrollable widget there " +
"is no need to use a viewport because there will always be enough " +
"vertical space for the children. In this case, consider using a " +
"Column instead. Otherwise, consider using the \"shrinkWrap\" property " +
"(or a ShrinkWrappingViewport) to size the height of the viewport " +
"to the sum of the heights of its children."
)
});
}
if (!constraints.hasBoundedWidth) {

break;
case Axis.horizontal:
if (!constraints.hasBoundedWidth) {
throw new UIWidgetsError(
"Horizontal viewport was given unbounded width.\n" +
"Viewports expand in the scrolling direction to fill their container." +
"In this case, a horizontal viewport was given an unlimited amount of " +
"horizontal space in which to expand. This situation typically happens " +
"when a scrollable widget is nested inside another scrollable widget.\n" +
"If this widget is always nested in a scrollable widget there " +
"is no need to use a viewport because there will always be enough " +
"horizontal space for the children. In this case, consider using a " +
"Row instead. Otherwise, consider using the \"shrinkWrap\" property " +
"(or a ShrinkWrappingViewport) to size the width of the viewport " +
"to the sum of the widths of its children."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("Horizontal viewport was given unbounded width."),
new ErrorDescription(
"Viewports expand in the scrolling direction to fill their container. " +
"In this case, a horizontal viewport was given an unlimited amount of " +
"horizontal space in which to expand. This situation typically happens " +
"when a scrollable widget is nested inside another scrollable widget."
),
new ErrorHint(
"If this widget is always nested in a scrollable widget there " +
"is no need to use a viewport because there will always be enough " +
"horizontal space for the children. In this case, consider using a " +
"Row instead. Otherwise, consider using the \"shrinkWrap\" property " +
"(or a ShrinkWrappingViewport) to size the width of the viewport " +
"to the sum of the widths of its children."
)
});
}
if (!constraints.hasBoundedHeight) {

offset.applyContentDimensions(0.0f, 0.0f);
return;
}
D.assert(center.parent == this);
float mainAxisExtent = 0.0f;
float crossAxisExtent = 0.0f;
switch (axis) {

}
float centerOffsetAdjustment = center.centerOffsetAdjustment;
int count = 0;
do {
var correction = _attemptLayout(mainAxisExtent, crossAxisExtent,

"RenderViewport render objects, during layout, can retry if either their " +
"slivers or their ViewportOffset decide that the offset should be corrected " +
"to take into account information collected during that layout.\n" +
"In the case of this RenderViewport object, however, this happened $count " +
$"In the case of this RenderViewport object, however, this happened {count} " +
"times and still there was no consensus on the scroll offset. This usually " +
"indicates a bug. Specifically, it means that one of the following three " +
"problems is being experienced by the RenderViewport object:\n" +

protected override bool debugThrowIfNotCheckingIntrinsics() {
D.assert(() => {
if (!debugCheckingIntrinsics) {
throw new UIWidgetsError(
GetType() + " does not support returning intrinsic dimensions.\n" +
"Calculating the intrinsic dimensions would require instantiating every child of " +
"the viewport, which defeats the point of viewports being lazy.\n" +
"If you are merely trying to shrink-wrap the viewport in the main axis direction, " +
"you should be able to achieve that effect by just giving the viewport loose " +
"constraints, without needing to measure its intrinsic dimensions."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary($"{GetType()} does not support returning intrinsic dimensions."),
new ErrorDescription(
"Calculating the intrinsic dimensions would require instantiating every child of " +
"the viewport, which defeats the point of viewports being lazy."
),
new ErrorHint(
"If you are merely trying to shrink-wrap the viewport in the main axis direction, " +
"you should be able to achieve that effect by just giving the viewport loose " +
"constraints, without needing to measure its intrinsic dimensions."
)
});
}
return true;

bool _hasVisualOverflow = false;
protected override void performLayout() {
BoxConstraints constraints = this.constraints;
if (firstChild == null) {
switch (axis) {
case Axis.vertical:

21
com.unity.uiwidgets/Runtime/rendering/wrap.cs


throw new Exception("Unknown axis: " + direction);
}
D.assert(childConstraints != null);
float spacing = this.spacing;
float runSpacing = this.runSpacing;
List<_RunMetrics> runMetrics = new List<_RunMetrics> { };

child = firstChild;
for (int i = 0; i < runCount; ++i) {
_RunMetrics metrics = runMetrics[i];
runMainAxisExtent = metrics.mainAxisExtent;
runCrossAxisExtent = metrics.crossAxisExtent;
childCount = metrics.childCount;
float runMainAxisExtent2 = metrics.mainAxisExtent;
float runCrossAxisExtent2 = metrics.crossAxisExtent;
float childCount2 = metrics.childCount;
float mainAxisFreeSpace = Mathf.Max(0.0f, containerMainAxisExtent - runMainAxisExtent);
float mainAxisFreeSpace = Mathf.Max(0.0f, containerMainAxisExtent - runMainAxisExtent2);
float childLeadingSpace = 0.0f;
float childBetweenSpace = 0.0f;

childLeadingSpace = mainAxisFreeSpace / 2.0f;
break;
case WrapAlignment.spaceBetween:
childBetweenSpace = childCount > 1 ? mainAxisFreeSpace / (childCount - 1) : 0.0f;
childBetweenSpace = childCount2 > 1 ? mainAxisFreeSpace / (childCount2 - 1) : 0.0f;
childBetweenSpace = mainAxisFreeSpace / childCount;
childBetweenSpace = mainAxisFreeSpace / childCount2;
childBetweenSpace = mainAxisFreeSpace / (childCount + 1);
childBetweenSpace = mainAxisFreeSpace / (childCount2 + 1);
childLeadingSpace = childBetweenSpace;
break;
}

flipMainAxis ? containerMainAxisExtent - childLeadingSpace : childLeadingSpace;
if (flipCrossAxis) {
crossAxisOffset -= runCrossAxisExtent;
crossAxisOffset -= runCrossAxisExtent2;
}
while (child != null) {

float childMainAxisExtent = _getMainAxisExtent(child);
float childCrossAxisExtent = _getCrossAxisExtent(child);
float childCrossAxisOffset =
_getChildCrossAxisOffset(flipCrossAxis, runCrossAxisExtent, childCrossAxisExtent);
_getChildCrossAxisOffset(flipCrossAxis, runCrossAxisExtent2, childCrossAxisExtent);
if (flipMainAxis) {
childMainPosition -= childMainAxisExtent;
}

crossAxisOffset -= runBetweenSpace;
}
else {
crossAxisOffset += runCrossAxisExtent + runBetweenSpace;
crossAxisOffset += runCrossAxisExtent2 + runBetweenSpace;
}
}
}

正在加载...
取消
保存