kg
6 年前
当前提交
e4cadc03
共有 17 个文件被更改,包括 2380 次插入 和 30 次删除
-
46Assets/UIWidgets/painting/basic_types.cs
-
98Assets/UIWidgets/rendering/object.mixin.gen.cs
-
7Assets/UIWidgets/rendering/object.mixin.njk
-
514Assets/UIWidgets/rendering/sliver.cs
-
736Assets/UIWidgets/rendering/viewpoint.cs
-
61Assets/UIWidgets/rendering/viewport_offset.cs
-
39Assets/UIWidgets/ui/geometry.cs
-
170Assets/UIWidgets/rendering/sliver_fixed_extent_list.cs
-
3Assets/UIWidgets/rendering/sliver_fixed_extent_list.cs.meta
-
194Assets/UIWidgets/rendering/sliver_list.cs
-
3Assets/UIWidgets/rendering/sliver_list.cs.meta
-
299Assets/UIWidgets/rendering/sliver_multi_box_adaptor.cs
-
3Assets/UIWidgets/rendering/sliver_multi_box_adaptor.cs.meta
-
232Assets/UIWidgets/rendering/sliver_padding.cs
-
3Assets/UIWidgets/rendering/sliver_padding.cs.meta
-
2Assets/UIWidgets/gestures/arena.cs
|
|||
namespace UIWidgets.rendering { |
|||
using System; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
using Rect = UIWidgets.ui.Rect; |
|||
|
|||
namespace UIWidgets.rendering { |
|||
public enum GrowthDirection { |
|||
forward, |
|||
reverse, |
|||
} |
|||
|
|||
public static class GrowthDirectionUtils { |
|||
public static AxisDirection applyGrowthDirectionToAxisDirection( |
|||
AxisDirection axisDirection, GrowthDirection growthDirection) { |
|||
switch (growthDirection) { |
|||
case GrowthDirection.forward: |
|||
return axisDirection; |
|||
case GrowthDirection.reverse: |
|||
return AxisUtils.flipAxisDirection(axisDirection); |
|||
} |
|||
|
|||
throw new Exception("unknown growthDirection"); |
|||
} |
|||
|
|||
public static ScrollDirection applyGrowthDirectionToScrollDirection( |
|||
ScrollDirection scrollDirection, GrowthDirection growthDirection) { |
|||
switch (growthDirection) { |
|||
case GrowthDirection.forward: |
|||
return scrollDirection; |
|||
case GrowthDirection.reverse: |
|||
return ScrollDirectionUtils.flipScrollDirection(scrollDirection); |
|||
} |
|||
public class SliverPhysicalParentData : ContainerParentDataMixinParentData<RenderSliver> { |
|||
throw new Exception("unknown growthDirection"); |
|||
} |
|||
public class SliverPhysicalContainerParentData : SliverPhysicalParentData { |
|||
public class SliverConstraints : Constraints, IEquatable<SliverConstraints> { |
|||
public SliverConstraints( |
|||
AxisDirection axisDirection, |
|||
GrowthDirection growthDirection, |
|||
ScrollDirection userScrollDirection, |
|||
double scrollOffset, |
|||
double overlap, |
|||
double remainingPaintExtent, |
|||
double crossAxisExtent, |
|||
AxisDirection crossAxisDirection, |
|||
double viewportMainAxisExtent, |
|||
double remainingCacheExtent, |
|||
double cacheOrigin |
|||
) { |
|||
this.axisDirection = axisDirection; |
|||
this.growthDirection = growthDirection; |
|||
this.userScrollDirection = userScrollDirection; |
|||
this.scrollOffset = scrollOffset; |
|||
this.overlap = overlap; |
|||
this.remainingPaintExtent = remainingPaintExtent; |
|||
this.crossAxisExtent = crossAxisExtent; |
|||
this.crossAxisDirection = crossAxisDirection; |
|||
this.viewportMainAxisExtent = viewportMainAxisExtent; |
|||
this.remainingCacheExtent = remainingCacheExtent; |
|||
this.cacheOrigin = cacheOrigin; |
|||
} |
|||
|
|||
public SliverConstraints copyWith( |
|||
AxisDirection? axisDirection = null, |
|||
GrowthDirection? growthDirection = null, |
|||
ScrollDirection? userScrollDirection = null, |
|||
double? scrollOffset = null, |
|||
double? overlap = null, |
|||
double? remainingPaintExtent = null, |
|||
double? crossAxisExtent = null, |
|||
AxisDirection? crossAxisDirection = null, |
|||
double? viewportMainAxisExtent = null, |
|||
double? remainingCacheExtent = null, |
|||
double? cacheOrigin = null |
|||
) { |
|||
return new SliverConstraints( |
|||
axisDirection: axisDirection ?? this.axisDirection, |
|||
growthDirection: growthDirection ?? this.growthDirection, |
|||
userScrollDirection: userScrollDirection ?? this.userScrollDirection, |
|||
scrollOffset: scrollOffset ?? this.scrollOffset, |
|||
overlap: overlap ?? this.overlap, |
|||
remainingPaintExtent: remainingPaintExtent ?? this.remainingPaintExtent, |
|||
crossAxisExtent: crossAxisExtent ?? this.crossAxisExtent, |
|||
crossAxisDirection: crossAxisDirection ?? this.crossAxisDirection, |
|||
viewportMainAxisExtent: viewportMainAxisExtent ?? this.viewportMainAxisExtent, |
|||
remainingCacheExtent: remainingCacheExtent ?? this.remainingCacheExtent, |
|||
cacheOrigin: cacheOrigin ?? this.cacheOrigin |
|||
); |
|||
} |
|||
|
|||
public readonly AxisDirection axisDirection; |
|||
|
|||
public readonly GrowthDirection growthDirection; |
|||
|
|||
public readonly ScrollDirection userScrollDirection; |
|||
|
|||
public readonly double scrollOffset; |
|||
|
|||
public readonly double overlap; |
|||
|
|||
public readonly double remainingPaintExtent; |
|||
|
|||
public readonly double crossAxisExtent; |
|||
|
|||
public readonly AxisDirection crossAxisDirection; |
|||
|
|||
public readonly double viewportMainAxisExtent; |
|||
|
|||
public readonly double cacheOrigin; |
|||
|
|||
public readonly double remainingCacheExtent; |
|||
|
|||
public Axis axis { |
|||
get { return AxisUtils.axisDirectionToAxis(this.axisDirection); } |
|||
} |
|||
|
|||
public GrowthDirection normalizedGrowthDirection { |
|||
get { |
|||
switch (this.axisDirection) { |
|||
case AxisDirection.down: |
|||
case AxisDirection.right: |
|||
return this.growthDirection; |
|||
case AxisDirection.up: |
|||
case AxisDirection.left: |
|||
switch (this.growthDirection) { |
|||
case GrowthDirection.forward: |
|||
return GrowthDirection.reverse; |
|||
case GrowthDirection.reverse: |
|||
return GrowthDirection.forward; |
|||
} |
|||
|
|||
throw new Exception("unknown growthDirection"); |
|||
} |
|||
|
|||
throw new Exception("unknown axisDirection"); |
|||
} |
|||
} |
|||
|
|||
public override bool isTight { |
|||
get { return false; } |
|||
} |
|||
|
|||
public override bool isNormalized { |
|||
get { |
|||
return this.scrollOffset >= 0.0 |
|||
&& this.crossAxisExtent >= 0.0 |
|||
&& AxisUtils.axisDirectionToAxis(this.axisDirection) != |
|||
AxisUtils.axisDirectionToAxis(this.crossAxisDirection) |
|||
&& this.viewportMainAxisExtent >= 0.0 |
|||
&& this.remainingPaintExtent >= 0.0; |
|||
} |
|||
} |
|||
|
|||
public BoxConstraints asBoxConstraints( |
|||
double minExtent = 0.0, |
|||
double maxExtent = double.PositiveInfinity, |
|||
double? crossAxisExtent = null |
|||
) { |
|||
crossAxisExtent = crossAxisExtent ?? this.crossAxisExtent; |
|||
switch (this.axis) { |
|||
case Axis.horizontal: |
|||
return new BoxConstraints( |
|||
minHeight: crossAxisExtent.Value, |
|||
maxHeight: crossAxisExtent.Value, |
|||
minWidth: minExtent, |
|||
maxWidth: maxExtent |
|||
); |
|||
case Axis.vertical: |
|||
return new BoxConstraints( |
|||
minWidth: crossAxisExtent.Value, |
|||
maxWidth: crossAxisExtent.Value, |
|||
minHeight: minExtent, |
|||
maxHeight: maxExtent |
|||
); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
|
|||
public bool Equals(SliverConstraints other) { |
|||
if (object.ReferenceEquals(null, other)) return false; |
|||
if (object.ReferenceEquals(this, other)) return true; |
|||
return this.axisDirection == other.axisDirection |
|||
&& this.growthDirection == other.growthDirection |
|||
&& this.userScrollDirection == other.userScrollDirection |
|||
&& this.scrollOffset.Equals(other.scrollOffset) |
|||
&& this.overlap.Equals(other.overlap) |
|||
&& this.remainingPaintExtent.Equals(other.remainingPaintExtent) |
|||
&& this.crossAxisExtent.Equals(other.crossAxisExtent) |
|||
&& this.crossAxisDirection == other.crossAxisDirection |
|||
&& this.viewportMainAxisExtent.Equals(other.viewportMainAxisExtent) |
|||
&& this.cacheOrigin.Equals(other.cacheOrigin) |
|||
&& this.remainingCacheExtent.Equals(other.remainingCacheExtent); |
|||
} |
|||
|
|||
public override bool Equals(object obj) { |
|||
if (object.ReferenceEquals(null, obj)) return false; |
|||
if (object.ReferenceEquals(this, obj)) return true; |
|||
if (obj.GetType() != this.GetType()) return false; |
|||
return this.Equals((SliverConstraints) obj); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
var hashCode = (int) this.axisDirection; |
|||
hashCode = (hashCode * 397) ^ (int) this.growthDirection; |
|||
hashCode = (hashCode * 397) ^ (int) this.userScrollDirection; |
|||
hashCode = (hashCode * 397) ^ this.scrollOffset.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.overlap.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.remainingPaintExtent.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.crossAxisExtent.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ (int) this.crossAxisDirection; |
|||
hashCode = (hashCode * 397) ^ this.viewportMainAxisExtent.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.cacheOrigin.GetHashCode(); |
|||
hashCode = (hashCode * 397) ^ this.remainingCacheExtent.GetHashCode(); |
|||
return hashCode; |
|||
} |
|||
} |
|||
|
|||
public static bool operator ==(SliverConstraints left, SliverConstraints right) { |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(SliverConstraints left, SliverConstraints right) { |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
|
|||
public class SliverGeometry { |
|||
public SliverGeometry( |
|||
double scrollExtent = 0.0, |
|||
double paintExtent = 0.0, |
|||
double paintOrigin = 0.0, |
|||
double? layoutExtent = null, |
|||
double maxPaintExtent = 0.0, |
|||
double maxScrollObstructionExtent = 0.0, |
|||
double? hitTestExtent = null, |
|||
bool? visible = null, |
|||
bool hasVisualOverflow = false, |
|||
double scrollOffsetCorrection = 0.0, |
|||
double? cacheExtent = null |
|||
) { |
|||
this.scrollExtent = scrollExtent; |
|||
this.paintExtent = paintExtent; |
|||
this.paintOrigin = paintOrigin; |
|||
this.layoutExtent = layoutExtent ?? paintExtent; |
|||
this.maxPaintExtent = maxPaintExtent; |
|||
this.maxScrollObstructionExtent = maxScrollObstructionExtent; |
|||
this.hitTestExtent = hitTestExtent ?? paintExtent; |
|||
this.visible = visible ?? paintExtent > 0.0; |
|||
this.hasVisualOverflow = hasVisualOverflow; |
|||
this.scrollOffsetCorrection = scrollOffsetCorrection; |
|||
this.cacheExtent = cacheExtent ?? layoutExtent ?? paintExtent; |
|||
} |
|||
|
|||
public static readonly SliverGeometry zero = new SliverGeometry(); |
|||
|
|||
public readonly double scrollExtent; |
|||
public readonly double paintOrigin; |
|||
public readonly double paintExtent; |
|||
public readonly double layoutExtent; |
|||
public readonly double maxPaintExtent; |
|||
public readonly double maxScrollObstructionExtent; |
|||
public readonly double hitTestExtent; |
|||
public readonly bool visible; |
|||
public readonly bool hasVisualOverflow; |
|||
public readonly double scrollOffsetCorrection; |
|||
public readonly double cacheExtent; |
|||
} |
|||
|
|||
public class SliverPhysicalParentData : ParentData { |
|||
public Offset paintOffset = Offset.zero; |
|||
|
|||
public void applyPaintTransform(ref Matrix4x4 transform) { |
|||
transform = Matrix4x4.Translate(this.paintOffset.toVector()) * transform; |
|||
} |
|||
} |
|||
|
|||
public class SliverPhysicalContainerParentData : ContainerParentDataMixinSliverPhysicalParentData<RenderSliver> { |
|||
} |
|||
|
|||
public class SliverLogicalParentData : ParentData { |
|||
public double layoutOffset = 0.0; |
|||
} |
|||
|
|||
public class SliverLogicalContainerParentData : ContainerParentDataMixinSliverLogicalParentData<RenderSliver> { |
|||
} |
|||
|
|||
|
|||
public new SliverConstraints constraints { |
|||
get { return (SliverConstraints) base.constraints; } |
|||
} |
|||
|
|||
public SliverGeometry geometry { |
|||
get { return this._geometry; } |
|||
set { this._geometry = value; } |
|||
} |
|||
|
|||
public SliverGeometry _geometry; |
|||
|
|||
public override Rect paintBounds { |
|||
get { |
|||
switch (this.constraints.axis) { |
|||
case Axis.horizontal: |
|||
return Rect.fromLTWH( |
|||
0.0, 0.0, |
|||
this.geometry.paintExtent, |
|||
this.constraints.crossAxisExtent |
|||
); |
|||
case Axis.vertical: |
|||
return Rect.fromLTWH( |
|||
0.0, 0.0, |
|||
this.constraints.crossAxisExtent, |
|||
this.geometry.paintExtent |
|||
); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public override void performResize() { |
|||
} |
|||
|
|||
public double centerOffsetAdjustment { |
|||
get { return 0.0; } |
|||
} |
|||
|
|||
public double calculatePaintOffset(SliverConstraints constraints, double from, double to) { |
|||
double a = constraints.scrollOffset; |
|||
double b = constraints.scrollOffset + constraints.remainingPaintExtent; |
|||
return (to.clamp(a, b) - from.clamp(a, b)).clamp(0.0, constraints.remainingPaintExtent); |
|||
} |
|||
|
|||
public double calculateCacheOffset(SliverConstraints constraints, double from, double to) { |
|||
double a = constraints.scrollOffset + constraints.cacheOrigin; |
|||
double b = constraints.scrollOffset + constraints.remainingCacheExtent; |
|||
return (to.clamp(a, b) - from.clamp(a, b)).clamp(0.0, constraints.remainingCacheExtent); |
|||
} |
|||
|
|||
public virtual double childMainAxisPosition(RenderObject child) { |
|||
return 0.0; |
|||
} |
|||
|
|||
public virtual double childCrossAxisPosition(RenderObject child) { |
|||
return 0.0; |
|||
} |
|||
|
|||
public virtual double childScrollOffset(RenderObject child) { |
|||
return 0.0; |
|||
} |
|||
|
|||
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) { |
|||
} |
|||
|
|||
public Size getAbsoluteSizeRelativeToOrigin() { |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection( |
|||
this.constraints.axisDirection, this.constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
return new Size(this.constraints.crossAxisExtent, -this.geometry.paintExtent); |
|||
case AxisDirection.right: |
|||
return new Size(this.geometry.paintExtent, this.constraints.crossAxisExtent); |
|||
case AxisDirection.down: |
|||
return new Size(this.constraints.crossAxisExtent, this.geometry.paintExtent); |
|||
case AxisDirection.left: |
|||
return new Size(-this.geometry.paintExtent, this.constraints.crossAxisExtent); |
|||
} |
|||
|
|||
return null; |
|||
} |
|||
} |
|||
|
|||
public static class RenderSliverHelpers { |
|||
public static bool _getRightWayUp(SliverConstraints constraints) { |
|||
bool rightWayUp = true; |
|||
switch (constraints.axisDirection) { |
|||
case AxisDirection.up: |
|||
case AxisDirection.left: |
|||
rightWayUp = false; |
|||
break; |
|||
case AxisDirection.down: |
|||
case AxisDirection.right: |
|||
rightWayUp = true; |
|||
break; |
|||
} |
|||
|
|||
switch (constraints.growthDirection) { |
|||
case GrowthDirection.forward: |
|||
break; |
|||
case GrowthDirection.reverse: |
|||
rightWayUp = !rightWayUp; |
|||
break; |
|||
} |
|||
|
|||
return rightWayUp; |
|||
} |
|||
|
|||
public static void applyPaintTransformForBoxChild(this RenderSliver it, RenderBox child, |
|||
ref Matrix4x4 transform) { |
|||
bool rightWayUp = RenderSliverHelpers._getRightWayUp(it.constraints); |
|||
double delta = it.childMainAxisPosition(child); |
|||
double crossAxisDelta = it.childCrossAxisPosition(child); |
|||
switch (it.constraints.axis) { |
|||
case Axis.horizontal: |
|||
if (!rightWayUp) { |
|||
delta = it.geometry.paintExtent - child.size.width - delta; |
|||
} |
|||
|
|||
transform = Matrix4x4.Translate(new Vector2((float) delta, (float) crossAxisDelta)) * transform; |
|||
break; |
|||
case Axis.vertical: |
|||
if (!rightWayUp) { |
|||
delta = it.geometry.paintExtent - child.size.height - delta; |
|||
} |
|||
|
|||
transform = Matrix4x4.Translate(new Vector2((float) crossAxisDelta, (float) delta)) * transform; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
public abstract class RenderSliverSingleBoxAdapter : RenderObjectWithChildMixinRenderSliver<RenderBox> { |
|||
public RenderSliverSingleBoxAdapter( |
|||
RenderBox child = null |
|||
) { |
|||
this.child = child; |
|||
} |
|||
|
|||
public override void setupParentData(RenderObject child) { |
|||
if (!(child.parentData is SliverPhysicalParentData)) { |
|||
child.parentData = new SliverPhysicalParentData(); |
|||
} |
|||
} |
|||
|
|||
public void setChildParentData(RenderObject child, SliverConstraints constraints, SliverGeometry geometry) { |
|||
var childParentData = (SliverPhysicalParentData) child.parentData; |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection(constraints.axisDirection, |
|||
constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
childParentData.paintOffset = new Offset(0.0, |
|||
-(geometry.scrollExtent - (geometry.paintExtent + constraints.scrollOffset))); |
|||
break; |
|||
case AxisDirection.right: |
|||
childParentData.paintOffset = new Offset(-constraints.scrollOffset, 0.0); |
|||
break; |
|||
case AxisDirection.down: |
|||
childParentData.paintOffset = new Offset(0.0, -constraints.scrollOffset); |
|||
break; |
|||
case AxisDirection.left: |
|||
childParentData.paintOffset = |
|||
new Offset(-(geometry.scrollExtent - (geometry.paintExtent + constraints.scrollOffset)), 0.0); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
public override double childMainAxisPosition(RenderObject child) { |
|||
return -this.constraints.scrollOffset; |
|||
} |
|||
|
|||
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) { |
|||
var childParentData = (SliverPhysicalParentData) child.parentData; |
|||
childParentData.applyPaintTransform(ref transform); |
|||
} |
|||
|
|||
public override void paint(PaintingContext context, Offset offset) { |
|||
if (this.child != null && this.geometry.visible) { |
|||
var childParentData = (SliverPhysicalParentData) this.child.parentData; |
|||
context.paintChild(this.child, offset + childParentData.paintOffset); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class RenderSliverToBoxAdapter : RenderSliverSingleBoxAdapter { |
|||
public RenderSliverToBoxAdapter( |
|||
RenderBox child = null |
|||
) : base(child) { |
|||
} |
|||
|
|||
public override void performLayout() { |
|||
if (this.child == null) { |
|||
this.geometry = SliverGeometry.zero; |
|||
return; |
|||
} |
|||
|
|||
this.child.layout(this.constraints.asBoxConstraints(), parentUsesSize: true); |
|||
|
|||
double childExtent = 0.0; |
|||
switch (this.constraints.axis) { |
|||
case Axis.horizontal: |
|||
childExtent = this.child.size.width; |
|||
break; |
|||
case Axis.vertical: |
|||
childExtent = this.child.size.height; |
|||
break; |
|||
} |
|||
|
|||
double paintedChildSize = this.calculatePaintOffset(this.constraints, from: 0.0, to: childExtent); |
|||
double cacheExtent = this.calculateCacheOffset(this.constraints, from: 0.0, to: childExtent); |
|||
|
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: childExtent, |
|||
paintExtent: paintedChildSize, |
|||
cacheExtent: cacheExtent, |
|||
maxPaintExtent: childExtent, |
|||
hitTestExtent: paintedChildSize, |
|||
hasVisualOverflow: childExtent > this.constraints.remainingPaintExtent |
|||
|| this.constraints.scrollOffset > 0.0 |
|||
); |
|||
|
|||
this.setChildParentData(this.child, this.constraints, this.geometry); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using UIWidgets.ui; |
|||
|
|||
namespace UIWidgets.rendering { |
|||
public abstract class RenderSliverFixedExtentBoxAdaptor : RenderSliverMultiBoxAdaptor { |
|||
RenderSliverFixedExtentBoxAdaptor( |
|||
RenderSliverBoxChildManager childManager = null |
|||
) : base(childManager: childManager) { |
|||
} |
|||
|
|||
public abstract double itemExtent { get; } |
|||
|
|||
public double indexToLayoutOffset(double itemExtent, int index) { |
|||
return itemExtent * index; |
|||
} |
|||
|
|||
public int getMinChildIndexForScrollOffset(double scrollOffset, double itemExtent) { |
|||
return itemExtent > 0.0 ? Math.Max(0, (int) (scrollOffset / itemExtent)) : 0; |
|||
} |
|||
|
|||
public int getMaxChildIndexForScrollOffset(double scrollOffset, double itemExtent) { |
|||
return itemExtent > 0.0 ? Math.Max(0, (int) Math.Ceiling(scrollOffset / itemExtent) - 1) : 0; |
|||
} |
|||
|
|||
public double estimateMaxScrollOffset(SliverConstraints constraints, |
|||
int firstIndex = 0, |
|||
int lastIndex = 0, |
|||
double leadingScrollOffset = 0.0, |
|||
double trailingScrollOffset = 0.0 |
|||
) { |
|||
return this.childManager.estimateMaxScrollOffset( |
|||
constraints, |
|||
firstIndex: firstIndex, |
|||
lastIndex: lastIndex, |
|||
leadingScrollOffset: leadingScrollOffset, |
|||
trailingScrollOffset: trailingScrollOffset |
|||
); |
|||
} |
|||
|
|||
public double computeMaxScrollOffset(SliverConstraints constraints, double itemExtent) { |
|||
return this.childManager.childCount * itemExtent; |
|||
} |
|||
|
|||
|
|||
public override void performLayout() { |
|||
this.childManager.didStartLayout(); |
|||
this.childManager.setDidUnderflow(false); |
|||
|
|||
double itemExtent = this.itemExtent; |
|||
|
|||
double scrollOffset = this.constraints.scrollOffset + this.constraints.cacheOrigin; |
|||
double remainingExtent = this.constraints.remainingCacheExtent; |
|||
double targetEndScrollOffset = scrollOffset + remainingExtent; |
|||
|
|||
BoxConstraints childConstraints = this.constraints.asBoxConstraints( |
|||
minExtent: itemExtent, |
|||
maxExtent: itemExtent |
|||
); |
|||
|
|||
int firstIndex = this.getMinChildIndexForScrollOffset(scrollOffset, itemExtent); |
|||
int? targetLastIndex = !double.IsInfinity(targetEndScrollOffset) |
|||
? this.getMaxChildIndexForScrollOffset(targetEndScrollOffset, itemExtent) |
|||
: (int?) null; |
|||
|
|||
if (this.firstChild != null) { |
|||
int oldFirstIndex = this.indexOf(this.firstChild); |
|||
int oldLastIndex = this.indexOf(this.lastChild); |
|||
int leadingGarbage = (firstIndex - oldFirstIndex).clamp(0, this.childCount); |
|||
int trailingGarbage = |
|||
targetLastIndex == null ? 0 : (oldLastIndex - targetLastIndex.Value).clamp(0, this.childCount); |
|||
this.collectGarbage(leadingGarbage, trailingGarbage); |
|||
} else { |
|||
this.collectGarbage(0, 0); |
|||
} |
|||
|
|||
if (this.firstChild == null) { |
|||
if (!this.addInitialChild(index: firstIndex, |
|||
layoutOffset: this.indexToLayoutOffset(itemExtent, firstIndex))) { |
|||
double max = this.computeMaxScrollOffset(this.constraints, itemExtent); |
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: max, |
|||
maxPaintExtent: max |
|||
); |
|||
this.childManager.didFinishLayout(); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
RenderBox trailingChildWithLayout = null; |
|||
|
|||
for (int index = this.indexOf(this.firstChild) - 1; index >= firstIndex; --index) { |
|||
RenderBox child = this.insertAndLayoutLeadingChild(childConstraints); |
|||
if (child == null) { |
|||
this.geometry = new SliverGeometry(scrollOffsetCorrection: index * itemExtent); |
|||
return; |
|||
} |
|||
|
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
childParentData.layoutOffset = this.indexToLayoutOffset(itemExtent, index); |
|||
trailingChildWithLayout = trailingChildWithLayout ?? child; |
|||
} |
|||
|
|||
if (trailingChildWithLayout == null) { |
|||
this.firstChild.layout(childConstraints); |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) this.firstChild.parentData; |
|||
childParentData.layoutOffset = this.indexToLayoutOffset(itemExtent, firstIndex); |
|||
trailingChildWithLayout = this.firstChild; |
|||
} |
|||
|
|||
while (targetLastIndex == null || this.indexOf(trailingChildWithLayout) < targetLastIndex) { |
|||
RenderBox child = this.childAfter(trailingChildWithLayout); |
|||
if (child == null) { |
|||
child = this.insertAndLayoutChild(childConstraints, after: trailingChildWithLayout); |
|||
if (child == null) { |
|||
break; |
|||
} |
|||
} else { |
|||
child.layout(childConstraints); |
|||
} |
|||
|
|||
trailingChildWithLayout = child; |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
childParentData.layoutOffset = this.indexToLayoutOffset(itemExtent, childParentData.index); |
|||
} |
|||
|
|||
int lastIndex = this.indexOf(this.lastChild); |
|||
double leadingScrollOffset = this.indexToLayoutOffset(itemExtent, firstIndex); |
|||
double trailingScrollOffset = this.indexToLayoutOffset(itemExtent, lastIndex + 1); |
|||
|
|||
double estimatedMaxScrollOffset = this.estimateMaxScrollOffset( |
|||
this.constraints, |
|||
firstIndex: firstIndex, |
|||
lastIndex: lastIndex, |
|||
leadingScrollOffset: leadingScrollOffset, |
|||
trailingScrollOffset: trailingScrollOffset |
|||
); |
|||
|
|||
double paintExtent = this.calculatePaintOffset( |
|||
this.constraints, |
|||
from: leadingScrollOffset, |
|||
to: trailingScrollOffset |
|||
); |
|||
|
|||
double cacheExtent = this.calculateCacheOffset( |
|||
this.constraints, |
|||
from: leadingScrollOffset, |
|||
to: trailingScrollOffset |
|||
); |
|||
|
|||
double targetEndScrollOffsetForPaint = |
|||
this.constraints.scrollOffset + this.constraints.remainingPaintExtent; |
|||
int? targetLastIndexForPaint = !double.IsInfinity(targetEndScrollOffsetForPaint) |
|||
? this.getMaxChildIndexForScrollOffset(targetEndScrollOffsetForPaint, itemExtent) |
|||
: (int?) null; |
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: estimatedMaxScrollOffset, |
|||
paintExtent: paintExtent, |
|||
cacheExtent: cacheExtent, |
|||
maxPaintExtent: estimatedMaxScrollOffset, |
|||
hasVisualOverflow: (targetLastIndexForPaint != null && lastIndex >= targetLastIndexForPaint) |
|||
|| this.constraints.scrollOffset > 0.0 |
|||
); |
|||
if (estimatedMaxScrollOffset == trailingScrollOffset) { |
|||
this.childManager.setDidUnderflow(true); |
|||
} |
|||
|
|||
this.childManager.didFinishLayout(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e602742e1e9c408989efd79055a9e552 |
|||
timeCreated: 1535524936 |
|
|||
using System; |
|||
|
|||
namespace UIWidgets.rendering { |
|||
public class RenderSliverList : RenderSliverMultiBoxAdaptor { |
|||
RenderSliverList( |
|||
RenderSliverBoxChildManager childManager = null |
|||
) : base(childManager: childManager) { |
|||
} |
|||
|
|||
public override void performLayout() { |
|||
this.childManager.didStartLayout(); |
|||
this.childManager.setDidUnderflow(false); |
|||
|
|||
double scrollOffset = this.constraints.scrollOffset + this.constraints.cacheOrigin; |
|||
double remainingExtent = this.constraints.remainingCacheExtent; |
|||
double targetEndScrollOffset = scrollOffset + remainingExtent; |
|||
BoxConstraints childConstraints = this.constraints.asBoxConstraints(); |
|||
int leadingGarbage = 0; |
|||
int trailingGarbage = 0; |
|||
bool reachedEnd = false; |
|||
|
|||
if (this.firstChild == null) { |
|||
if (!this.addInitialChild()) { |
|||
this.geometry = SliverGeometry.zero; |
|||
this.childManager.didFinishLayout(); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
RenderBox leadingChildWithLayout = null, trailingChildWithLayout = null; |
|||
|
|||
RenderBox earliestUsefulChild = this.firstChild; |
|||
for (double earliestScrollOffset = this.childScrollOffset(earliestUsefulChild); |
|||
earliestScrollOffset > scrollOffset; |
|||
earliestScrollOffset = this.childScrollOffset(earliestUsefulChild)) { |
|||
earliestUsefulChild = this.insertAndLayoutLeadingChild(childConstraints, parentUsesSize: true); |
|||
|
|||
if (earliestUsefulChild == null) { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) this.firstChild.parentData; |
|||
childParentData.layoutOffset = 0.0; |
|||
|
|||
if (scrollOffset == 0.0) { |
|||
earliestUsefulChild = this.firstChild; |
|||
leadingChildWithLayout = earliestUsefulChild; |
|||
trailingChildWithLayout = trailingChildWithLayout ?? earliestUsefulChild; |
|||
break; |
|||
} else { |
|||
this.geometry = new SliverGeometry( |
|||
scrollOffsetCorrection: -scrollOffset |
|||
); |
|||
return; |
|||
} |
|||
} else { |
|||
double firstChildScrollOffset = earliestScrollOffset - this.paintExtentOf(this.firstChild); |
|||
if (firstChildScrollOffset < 0.0) { |
|||
double correction = 0.0; |
|||
while (earliestUsefulChild != null) { |
|||
correction += this.paintExtentOf(firstChild); |
|||
earliestUsefulChild = |
|||
this.insertAndLayoutLeadingChild(childConstraints, parentUsesSize: true); |
|||
} |
|||
|
|||
this.geometry = new SliverGeometry( |
|||
scrollOffsetCorrection: correction - earliestScrollOffset |
|||
); |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) this.firstChild.parentData; |
|||
childParentData.layoutOffset = 0.0; |
|||
return; |
|||
} else { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) earliestUsefulChild.parentData; |
|||
childParentData.layoutOffset = firstChildScrollOffset; |
|||
leadingChildWithLayout = earliestUsefulChild; |
|||
trailingChildWithLayout = trailingChildWithLayout ?? earliestUsefulChild; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (leadingChildWithLayout == null) { |
|||
earliestUsefulChild.layout(childConstraints, parentUsesSize: true); |
|||
leadingChildWithLayout = earliestUsefulChild; |
|||
trailingChildWithLayout = earliestUsefulChild; |
|||
} |
|||
|
|||
bool inLayoutRange = true; |
|||
RenderBox child = earliestUsefulChild; |
|||
int index = this.indexOf(child); |
|||
double endScrollOffset = this.childScrollOffset(child) + this.paintExtentOf(child); |
|||
|
|||
Func<bool> advance = () => { |
|||
if (child == trailingChildWithLayout) { |
|||
inLayoutRange = false; |
|||
} |
|||
|
|||
child = this.childAfter(child); |
|||
if (child == null) { |
|||
inLayoutRange = false; |
|||
} |
|||
|
|||
index += 1; |
|||
if (!inLayoutRange) { |
|||
if (child == null || this.indexOf(child) != index) { |
|||
child = insertAndLayoutChild(childConstraints, |
|||
after: trailingChildWithLayout, |
|||
parentUsesSize: true |
|||
); |
|||
if (child == null) { |
|||
return false; |
|||
} |
|||
} else { |
|||
child.layout(childConstraints, parentUsesSize: true); |
|||
} |
|||
|
|||
trailingChildWithLayout = child; |
|||
} |
|||
|
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
childParentData.layoutOffset = endScrollOffset; |
|||
endScrollOffset = this.childScrollOffset(child) + this.paintExtentOf(child); |
|||
return true; |
|||
}; |
|||
|
|||
while (endScrollOffset < scrollOffset) { |
|||
leadingGarbage += 1; |
|||
if (!advance()) { |
|||
this.collectGarbage(leadingGarbage - 1, 0); |
|||
double extent = this.childScrollOffset(this.lastChild) + this.paintExtentOf(this.lastChild); |
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: extent, |
|||
paintExtent: 0.0, |
|||
maxPaintExtent: extent |
|||
); |
|||
return; |
|||
} |
|||
} |
|||
|
|||
while (endScrollOffset < targetEndScrollOffset) { |
|||
if (!advance()) { |
|||
reachedEnd = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (child != null) { |
|||
child = this.childAfter(child); |
|||
while (child != null) { |
|||
trailingGarbage += 1; |
|||
child = this.childAfter(child); |
|||
} |
|||
} |
|||
|
|||
this.collectGarbage(leadingGarbage, trailingGarbage); |
|||
|
|||
double estimatedMaxScrollOffset; |
|||
if (reachedEnd) { |
|||
estimatedMaxScrollOffset = endScrollOffset; |
|||
} else { |
|||
estimatedMaxScrollOffset = this.childManager.estimateMaxScrollOffset( |
|||
this.constraints, |
|||
firstIndex: this.indexOf(this.firstChild), |
|||
lastIndex: this.indexOf(this.lastChild), |
|||
leadingScrollOffset: this.childScrollOffset(this.firstChild), |
|||
trailingScrollOffset: endScrollOffset |
|||
); |
|||
} |
|||
|
|||
double paintExtent = this.calculatePaintOffset( |
|||
this.constraints, |
|||
from: this.childScrollOffset(this.firstChild), |
|||
to: endScrollOffset |
|||
); |
|||
double cacheExtent = this.calculateCacheOffset( |
|||
this.constraints, |
|||
from: this.childScrollOffset(this.firstChild), |
|||
to: endScrollOffset |
|||
); |
|||
double targetEndScrollOffsetForPaint = |
|||
this.constraints.scrollOffset + this.constraints.remainingPaintExtent; |
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: estimatedMaxScrollOffset, |
|||
paintExtent: paintExtent, |
|||
cacheExtent: cacheExtent, |
|||
maxPaintExtent: estimatedMaxScrollOffset, |
|||
hasVisualOverflow: endScrollOffset > targetEndScrollOffsetForPaint || |
|||
this.constraints.scrollOffset > 0.0 |
|||
); |
|||
|
|||
if (estimatedMaxScrollOffset == endScrollOffset) { |
|||
this.childManager.setDidUnderflow(true); |
|||
} |
|||
|
|||
this.childManager.didFinishLayout(); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1db4d92862744fcdb527f4020106fdf8 |
|||
timeCreated: 1535522746 |
|
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using UIWidgets.foundation; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgets.rendering { |
|||
public interface RenderSliverBoxChildManager { |
|||
void createChild(int index, RenderBox after = null); |
|||
|
|||
void removeChild(RenderBox child); |
|||
|
|||
double estimateMaxScrollOffset( |
|||
SliverConstraints constraints, |
|||
int firstIndex = 0, |
|||
int lastIndex = 0, |
|||
double leadingScrollOffset = 0, |
|||
double trailingScrollOffset = 0); |
|||
|
|||
int childCount { get; } |
|||
|
|||
void didAdoptChild(RenderBox child); |
|||
|
|||
void setDidUnderflow(bool value); |
|||
|
|||
void didStartLayout(); |
|||
|
|||
void didFinishLayout(); |
|||
} |
|||
|
|||
public class SliverMultiBoxAdaptorParentData : ContainerParentDataMixinSliverLogicalParentData<RenderBox> { |
|||
public int index; |
|||
|
|||
public bool keepAlive = false; |
|||
|
|||
public bool _keptAlive = false; |
|||
} |
|||
|
|||
public abstract class RenderSliverMultiBoxAdaptor |
|||
: ContainerRenderObjectMixinRenderSliver<RenderBox, SliverMultiBoxAdaptorParentData> { |
|||
public RenderSliverMultiBoxAdaptor( |
|||
RenderSliverBoxChildManager childManager = null |
|||
) { |
|||
this._childManager = childManager; |
|||
} |
|||
|
|||
public override void setupParentData(RenderObject child) { |
|||
if (!(child.parentData is SliverMultiBoxAdaptorParentData)) { |
|||
child.parentData = new SliverMultiBoxAdaptorParentData(); |
|||
} |
|||
} |
|||
|
|||
public RenderSliverBoxChildManager childManager { |
|||
get { return this._childManager; } |
|||
} |
|||
|
|||
public RenderSliverBoxChildManager _childManager; |
|||
|
|||
public readonly Dictionary<int, RenderBox> _keepAliveBucket = new Dictionary<int, RenderBox>(); |
|||
|
|||
public override void adoptChild(AbstractNode childNode) { |
|||
base.adoptChild(childNode); |
|||
var child = (RenderBox) childNode; |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
if (!childParentData._keptAlive) { |
|||
this.childManager.didAdoptChild(child); |
|||
} |
|||
} |
|||
|
|||
public override void insert(RenderBox child, RenderBox after = null) { |
|||
base.insert(child, after: after); |
|||
} |
|||
|
|||
public override void remove(RenderBox child) { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
if (!childParentData._keptAlive) { |
|||
base.remove(child); |
|||
return; |
|||
} |
|||
|
|||
this._keepAliveBucket.Remove(childParentData.index); |
|||
this.dropChild(child); |
|||
} |
|||
|
|||
public override void removeAll() { |
|||
base.removeAll(); |
|||
|
|||
foreach (var child in this._keepAliveBucket.Values) { |
|||
this.dropChild(child); |
|||
} |
|||
|
|||
this._keepAliveBucket.Clear(); |
|||
} |
|||
|
|||
void _createOrObtainChild(int index, RenderBox after = null) { |
|||
this.invokeLayoutCallback<SliverConstraints>((SliverConstraints constraints) => { |
|||
if (this._keepAliveBucket.ContainsKey(index)) { |
|||
RenderBox child = this._keepAliveBucket[index]; |
|||
this._keepAliveBucket.Remove(index); |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
this.dropChild(child); |
|||
child.parentData = childParentData; |
|||
this.insert(child, after: after); |
|||
childParentData._keptAlive = false; |
|||
} else { |
|||
this._childManager.createChild(index, after: after); |
|||
} |
|||
}); |
|||
} |
|||
|
|||
public void _destroyOrCacheChild(RenderBox child) { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
if (childParentData.keepAlive) { |
|||
this.remove(child); |
|||
this._keepAliveBucket[childParentData.index] = child; |
|||
child.parentData = childParentData; |
|||
base.adoptChild(child); |
|||
childParentData._keptAlive = true; |
|||
} else { |
|||
this._childManager.removeChild(child); |
|||
} |
|||
} |
|||
|
|||
public override void attach(object owner) { |
|||
base.attach(owner); |
|||
foreach (RenderBox child in this._keepAliveBucket.Values) { |
|||
child.attach(owner); |
|||
} |
|||
} |
|||
|
|||
public override void detach() { |
|||
base.detach(); |
|||
foreach (RenderBox child in this._keepAliveBucket.Values) { |
|||
child.detach(); |
|||
} |
|||
} |
|||
|
|||
public override void redepthChildren() { |
|||
base.redepthChildren(); |
|||
foreach (var child in this._keepAliveBucket.Values) { |
|||
this.redepthChild(child); |
|||
} |
|||
} |
|||
|
|||
public override void visitChildren(RenderObjectVisitor visitor) { |
|||
base.visitChildren(visitor); |
|||
|
|||
foreach (var child in this._keepAliveBucket.Values) { |
|||
visitor(child); |
|||
} |
|||
} |
|||
|
|||
public bool addInitialChild(int index = 0, double layoutOffset = 0.0) { |
|||
this._createOrObtainChild(index, after: null); |
|||
if (this.firstChild != null) { |
|||
var firstChildParentData = (SliverMultiBoxAdaptorParentData) this.firstChild.parentData; |
|||
firstChildParentData.layoutOffset = layoutOffset; |
|||
return true; |
|||
} |
|||
|
|||
this.childManager.setDidUnderflow(true); |
|||
return false; |
|||
} |
|||
|
|||
public RenderBox insertAndLayoutLeadingChild(BoxConstraints childConstraints, bool parentUsesSize = false) { |
|||
int index = this.indexOf(this.firstChild) - 1; |
|||
this._createOrObtainChild(index, after: null); |
|||
if (this.indexOf(this.firstChild) == index) { |
|||
this.firstChild.layout(childConstraints, parentUsesSize: parentUsesSize); |
|||
return this.firstChild; |
|||
} |
|||
|
|||
this.childManager.setDidUnderflow(true); |
|||
return null; |
|||
} |
|||
|
|||
public RenderBox insertAndLayoutChild( |
|||
BoxConstraints childConstraints, |
|||
RenderBox after = null, |
|||
bool parentUsesSize = false |
|||
) { |
|||
int index = this.indexOf(after) + 1; |
|||
this._createOrObtainChild(index, after: after); |
|||
RenderBox child = this.childAfter(after); |
|||
if (child != null && this.indexOf(child) == index) { |
|||
child.layout(childConstraints, parentUsesSize: parentUsesSize); |
|||
return child; |
|||
} |
|||
|
|||
this.childManager.setDidUnderflow(true); |
|||
return null; |
|||
} |
|||
|
|||
public void collectGarbage(int leadingGarbage, int trailingGarbage) { |
|||
this.invokeLayoutCallback<SliverConstraints>((SliverConstraints constraints) => { |
|||
while (leadingGarbage > 0) { |
|||
this._destroyOrCacheChild(this.firstChild); |
|||
leadingGarbage -= 1; |
|||
} |
|||
|
|||
while (trailingGarbage > 0) { |
|||
this._destroyOrCacheChild(this.lastChild); |
|||
trailingGarbage -= 1; |
|||
} |
|||
|
|||
this._keepAliveBucket.Values.Where((RenderBox child) => { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
return !childParentData.keepAlive; |
|||
}).ToList().ForEach(this._childManager.removeChild); |
|||
}); |
|||
} |
|||
|
|||
public int indexOf(RenderBox child) { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
return childParentData.index; |
|||
} |
|||
|
|||
public double paintExtentOf(RenderBox child) { |
|||
switch (this.constraints.axis) { |
|||
case Axis.horizontal: |
|||
return child.size.width; |
|||
case Axis.vertical: |
|||
return child.size.height; |
|||
} |
|||
|
|||
return 0.0; |
|||
} |
|||
|
|||
public override double childMainAxisPosition(RenderObject child) { |
|||
return this.childScrollOffset(child) - this.constraints.scrollOffset; |
|||
} |
|||
|
|||
public override double childScrollOffset(RenderObject child) { |
|||
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData; |
|||
return childParentData.layoutOffset; |
|||
} |
|||
|
|||
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) { |
|||
this.applyPaintTransformForBoxChild((RenderBox) child, ref transform); |
|||
} |
|||
|
|||
public override void paint(PaintingContext context, Offset offset) { |
|||
if (this.firstChild == null) { |
|||
return; |
|||
} |
|||
|
|||
Offset mainAxisUnit = null, crossAxisUnit = null, originOffset = null; |
|||
bool addExtent = false; |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection(this.constraints.axisDirection, |
|||
this.constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
mainAxisUnit = new Offset(0.0, -1.0); |
|||
crossAxisUnit = new Offset(1.0, 0.0); |
|||
originOffset = offset + new Offset(0.0, this.geometry.paintExtent); |
|||
addExtent = true; |
|||
break; |
|||
case AxisDirection.right: |
|||
mainAxisUnit = new Offset(1.0, 0.0); |
|||
crossAxisUnit = new Offset(0.0, 1.0); |
|||
originOffset = offset; |
|||
addExtent = false; |
|||
break; |
|||
case AxisDirection.down: |
|||
mainAxisUnit = new Offset(0.0, 1.0); |
|||
crossAxisUnit = new Offset(1.0, 0.0); |
|||
originOffset = offset; |
|||
addExtent = false; |
|||
break; |
|||
case AxisDirection.left: |
|||
mainAxisUnit = new Offset(-1.0, 0.0); |
|||
crossAxisUnit = new Offset(0.0, 1.0); |
|||
originOffset = offset + new Offset(this.geometry.paintExtent, 0.0); |
|||
addExtent = true; |
|||
break; |
|||
} |
|||
|
|||
RenderBox child = this.firstChild; |
|||
while (child != null) { |
|||
double mainAxisDelta = this.childMainAxisPosition(child); |
|||
double crossAxisDelta = this.childCrossAxisPosition(child); |
|||
Offset childOffset = new Offset( |
|||
originOffset.dx + mainAxisUnit.dx * mainAxisDelta + crossAxisUnit.dx * crossAxisDelta, |
|||
originOffset.dy + mainAxisUnit.dy * mainAxisDelta + crossAxisUnit.dy * crossAxisDelta |
|||
); |
|||
if (addExtent) { |
|||
childOffset += mainAxisUnit * this.paintExtentOf(child); |
|||
} |
|||
|
|||
if (mainAxisDelta < this.constraints.remainingPaintExtent && |
|||
mainAxisDelta + this.paintExtentOf(child) > 0) { |
|||
context.paintChild(child, childOffset); |
|||
} |
|||
|
|||
child = this.childAfter(child); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 00853d7738fe40eeb3e7b44db23248be |
|||
timeCreated: 1535502825 |
|
|||
using System; |
|||
using UIWidgets.painting; |
|||
using UIWidgets.ui; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgets.rendering { |
|||
public class RenderSliverPadding : RenderObjectWithChildMixinRenderSliver<RenderSliver> { |
|||
RenderSliverPadding( |
|||
EdgeInsets padding, |
|||
RenderSliver child |
|||
) { |
|||
this._padding = padding; |
|||
this.child = child; |
|||
} |
|||
|
|||
public EdgeInsets padding { |
|||
get { return this._padding; } |
|||
set { |
|||
if (this._padding == value) { |
|||
return; |
|||
} |
|||
|
|||
this._padding = value; |
|||
this.markNeedsLayout(); |
|||
} |
|||
} |
|||
|
|||
public EdgeInsets _padding; |
|||
|
|||
public double beforePadding { |
|||
get { |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection( |
|||
this.constraints.axisDirection, this.constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
return this._padding.bottom; |
|||
case AxisDirection.right: |
|||
return this._padding.left; |
|||
case AxisDirection.down: |
|||
return this._padding.top; |
|||
case AxisDirection.left: |
|||
return this._padding.right; |
|||
} |
|||
|
|||
return 0.0; |
|||
} |
|||
} |
|||
|
|||
public double afterPadding { |
|||
get { |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection( |
|||
this.constraints.axisDirection, this.constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
return this._padding.top; |
|||
case AxisDirection.right: |
|||
return this._padding.right; |
|||
case AxisDirection.down: |
|||
return this._padding.bottom; |
|||
case AxisDirection.left: |
|||
return this._padding.left; |
|||
} |
|||
|
|||
return 0.0; |
|||
} |
|||
} |
|||
|
|||
public double mainAxisPadding { |
|||
get { return this._padding.along(this.constraints.axis); } |
|||
} |
|||
|
|||
public double crossAxisPadding { |
|||
get { |
|||
switch (this.constraints.axis) { |
|||
case Axis.horizontal: |
|||
return this._padding.vertical; |
|||
case Axis.vertical: |
|||
return this._padding.horizontal; |
|||
} |
|||
|
|||
return 0.0; |
|||
} |
|||
} |
|||
|
|||
public override void setupParentData(RenderObject child) { |
|||
if (!(child.parentData is SliverPhysicalParentData)) { |
|||
child.parentData = new SliverPhysicalParentData(); |
|||
} |
|||
} |
|||
|
|||
public override void performLayout() { |
|||
double beforePadding = this.beforePadding; |
|||
double afterPadding = this.afterPadding; |
|||
double mainAxisPadding = this.mainAxisPadding; |
|||
double crossAxisPadding = this.crossAxisPadding; |
|||
if (this.child == null) { |
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: mainAxisPadding, |
|||
paintExtent: Math.Min(mainAxisPadding, this.constraints.remainingPaintExtent), |
|||
maxPaintExtent: mainAxisPadding |
|||
); |
|||
return; |
|||
} |
|||
|
|||
this.child.layout( |
|||
this.constraints.copyWith( |
|||
scrollOffset: Math.Max(0.0, this.constraints.scrollOffset - beforePadding), |
|||
cacheOrigin: Math.Min(0.0, this.constraints.cacheOrigin + beforePadding), |
|||
overlap: 0.0, |
|||
remainingPaintExtent: this.constraints.remainingPaintExtent - |
|||
this.calculatePaintOffset(this.constraints, from: 0.0, to: beforePadding), |
|||
remainingCacheExtent: this.constraints.remainingCacheExtent - |
|||
this.calculateCacheOffset(this.constraints, from: 0.0, to: beforePadding), |
|||
crossAxisExtent: Math.Max(0.0, this.constraints.crossAxisExtent - crossAxisPadding) |
|||
), |
|||
parentUsesSize: true |
|||
); |
|||
|
|||
SliverGeometry childLayoutGeometry = this.child.geometry; |
|||
if (childLayoutGeometry.scrollOffsetCorrection != 0.0) { |
|||
this.geometry = new SliverGeometry( |
|||
scrollOffsetCorrection: childLayoutGeometry.scrollOffsetCorrection |
|||
); |
|||
return; |
|||
} |
|||
|
|||
double beforePaddingPaintExtent = this.calculatePaintOffset( |
|||
this.constraints, |
|||
from: 0.0, |
|||
to: beforePadding |
|||
); |
|||
|
|||
double afterPaddingPaintExtent = this.calculatePaintOffset( |
|||
this.constraints, |
|||
from: beforePadding + childLayoutGeometry.scrollExtent, |
|||
to: mainAxisPadding + childLayoutGeometry.scrollExtent |
|||
); |
|||
|
|||
double mainAxisPaddingPaintExtent = beforePaddingPaintExtent + afterPaddingPaintExtent; |
|||
double beforePaddingCacheExtent = this.calculateCacheOffset( |
|||
this.constraints, |
|||
from: 0.0, |
|||
to: beforePadding |
|||
); |
|||
double afterPaddingCacheExtent = this.calculateCacheOffset( |
|||
this.constraints, |
|||
from: beforePadding + childLayoutGeometry.scrollExtent, |
|||
to: mainAxisPadding + childLayoutGeometry.scrollExtent |
|||
); |
|||
|
|||
double mainAxisPaddingCacheExtent = afterPaddingCacheExtent + beforePaddingCacheExtent; |
|||
double paintExtent = Math.Min( |
|||
beforePaddingPaintExtent + Math.Max(childLayoutGeometry.paintExtent, |
|||
childLayoutGeometry.layoutExtent + afterPaddingPaintExtent), |
|||
this.constraints.remainingPaintExtent |
|||
); |
|||
|
|||
this.geometry = new SliverGeometry( |
|||
scrollExtent: mainAxisPadding + childLayoutGeometry.scrollExtent, |
|||
paintExtent: paintExtent, |
|||
layoutExtent: Math.Min(mainAxisPaddingPaintExtent + childLayoutGeometry.layoutExtent, paintExtent), |
|||
cacheExtent: Math.Min(mainAxisPaddingCacheExtent + childLayoutGeometry.cacheExtent, |
|||
this.constraints.remainingCacheExtent), |
|||
maxPaintExtent: mainAxisPadding + childLayoutGeometry.maxPaintExtent, |
|||
hitTestExtent: Math.Max( |
|||
mainAxisPaddingPaintExtent + childLayoutGeometry.paintExtent, |
|||
beforePaddingPaintExtent + childLayoutGeometry.hitTestExtent |
|||
), |
|||
hasVisualOverflow: childLayoutGeometry.hasVisualOverflow |
|||
); |
|||
|
|||
var childParentData = (SliverPhysicalParentData) this.child.parentData; |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection(this.constraints.axisDirection, |
|||
this.constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
childParentData.paintOffset = new Offset(this._padding.left, |
|||
this.calculatePaintOffset(this.constraints, |
|||
from: this._padding.bottom + childLayoutGeometry.scrollExtent, |
|||
to: this._padding.bottom + childLayoutGeometry.scrollExtent + this._padding.top)); |
|||
break; |
|||
case AxisDirection.right: |
|||
childParentData.paintOffset = |
|||
new Offset(this.calculatePaintOffset(this.constraints, from: 0.0, to: this._padding.left), |
|||
this._padding.top); |
|||
break; |
|||
case AxisDirection.down: |
|||
childParentData.paintOffset = new Offset(this._padding.left, |
|||
this.calculatePaintOffset(this.constraints, from: 0.0, to: this._padding.top)); |
|||
break; |
|||
case AxisDirection.left: |
|||
childParentData.paintOffset = new Offset( |
|||
this.calculatePaintOffset(this.constraints, |
|||
from: this._padding.right + childLayoutGeometry.scrollExtent, |
|||
to: this._padding.right + childLayoutGeometry.scrollExtent + this._padding.left), |
|||
this._padding.top); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
public override double childMainAxisPosition(RenderObject child) { |
|||
return this.calculatePaintOffset(this.constraints, from: 0.0, to: this.beforePadding); |
|||
} |
|||
|
|||
public override double childCrossAxisPosition(RenderObject child) { |
|||
switch (GrowthDirectionUtils.applyGrowthDirectionToAxisDirection( |
|||
this.constraints.axisDirection, this.constraints.growthDirection)) { |
|||
case AxisDirection.up: |
|||
case AxisDirection.down: |
|||
return this._padding.left; |
|||
case AxisDirection.left: |
|||
case AxisDirection.right: |
|||
return this._padding.top; |
|||
} |
|||
|
|||
return 0.0; |
|||
} |
|||
|
|||
public override double childScrollOffset(RenderObject child) { |
|||
return this.beforePadding; |
|||
} |
|||
|
|||
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) { |
|||
var childParentData = (SliverPhysicalParentData) child.parentData; |
|||
childParentData.applyPaintTransform(ref transform); |
|||
} |
|||
|
|||
public override void paint(PaintingContext context, Offset offset) { |
|||
if (this.child != null && this.child.geometry.visible) { |
|||
var childParentData = (SliverPhysicalParentData) this.child.parentData; |
|||
context.paintChild(this.child, offset + childParentData.paintOffset); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 470336df9a5d4af3a4ccfa5fa759d854 |
|||
timeCreated: 1535523877 |
|
|||
namespace UIWidgets.gestures { |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue