浏览代码

scroll_view

/main
kg 6 年前
当前提交
c7d683d2
共有 11 个文件被更改,包括 606 次插入7 次删除
  1. 139
      Assets/UIWidgets/foundation/diagnostics.cs
  2. 23
      Assets/UIWidgets/painting/basic_types.cs
  3. 6
      Assets/UIWidgets/rendering/viewpoint.cs
  4. 25
      Assets/UIWidgets/widgets/debug.cs
  5. 2
      Assets/UIWidgets/widgets/framework.cs
  6. 44
      Assets/UIWidgets/widgets/primary_scroll_controller.cs
  7. 3
      Assets/UIWidgets/widgets/primary_scroll_controller.cs.meta
  8. 173
      Assets/UIWidgets/widgets/scroll_view.cs
  9. 3
      Assets/UIWidgets/widgets/scroll_view.cs.meta
  10. 192
      Assets/UIWidgets/widgets/viewport.cs
  11. 3
      Assets/UIWidgets/widgets/viewport.cs.meta

139
Assets/UIWidgets/foundation/diagnostics.cs


}
}
public abstract class _NumProperty<T> : DiagnosticsProperty<T> {
internal _NumProperty(string name,
T value,
string ifNull = null,
string unit = null,
bool showName = true,
Object defaultValue = null,
string tooltip = null,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
value,
ifNull: ifNull,
showName: showName,
defaultValue: defaultValue,
tooltip: tooltip,
level: level
) {
this.unit = unit;
}
internal _NumProperty(string name,
ComputePropertyValueCallback<T> computeValue,
string ifNull = null,
string unit = null,
bool showName = true,
object defaultValue = null,
string tooltip = null,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
computeValue,
ifNull: ifNull,
showName: showName,
defaultValue: defaultValue,
tooltip: tooltip,
level: level
) {
this.unit = unit;
}
public override Dictionary<string, object> toJsonMap() {
var json = base.toJsonMap();
if (this.unit != null) {
json["unit"] = this.unit;
}
json["numberToString"] = this.numberToString();
return json;
}
public readonly string unit;
protected abstract string numberToString();
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
if (this.value == null) {
return "null";
}
return this.unit != null ? this.numberToString() + this.unit : this.numberToString();
}
}
public class DoubleProperty : _NumProperty<double?> {
public DoubleProperty(string name, double? value,
string ifNull = null,
string unit = null,
string tooltip = null,
object defaultValue = null,
bool showName = true,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
value,
ifNull: ifNull,
unit: unit,
tooltip: tooltip,
defaultValue: defaultValue,
showName: showName,
level: level
) {
}
private DoubleProperty(
string name,
ComputePropertyValueCallback<double?> computeValue,
string ifNull = null,
bool showName = true,
string unit = null,
string tooltip = null,
object defaultValue = null,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
computeValue,
showName: showName,
ifNull: ifNull,
unit: unit,
tooltip: tooltip,
defaultValue: defaultValue,
level: level
) {
}
public static DoubleProperty lazy(
string name,
ComputePropertyValueCallback<double?> computeValue,
string ifNull = null,
bool showName = true,
string unit = null,
string tooltip = null,
object defaultValue = null,
DiagnosticLevel level = DiagnosticLevel.info
) {
return new DoubleProperty(
name,
computeValue,
showName: showName,
ifNull: ifNull,
unit: unit,
tooltip: tooltip,
defaultValue: defaultValue,
level: level
);
}
protected override string numberToString() {
if (this.value != null) {
return this.value.Value.ToString("F1");
}
return "null";
}
}
public class FlagProperty : DiagnosticsProperty<bool> {
public FlagProperty(String name,
bool value,

this.missingIfNull = missingIfNull;
}
private DiagnosticsProperty(
internal DiagnosticsProperty(
string name,
ComputePropertyValueCallback<T> computeValue,
string description = null,

23
Assets/UIWidgets/painting/basic_types.cs


using System;
using System.ComponentModel;
using UIWidgets.foundation;
using UIWidgets.widgets;
namespace UIWidgets.painting {
public enum AxisDirection {

throw new Exception("unknown axisDirection");
}
public static AxisDirection getAxisDirectionFromAxisReverseAndDirectionality(
BuildContext context,
Axis axis,
bool reverse
) {
switch (axis) {
case Axis.horizontal:
D.assert(WidgetsD.debugCheckHasDirectionality(context));
TextDirection textDirection = Directionality.of(context);
AxisDirection axisDirection = textDirectionToAxisDirection(textDirection);
return reverse ? flipAxisDirection(axisDirection) : axisDirection;
case Axis.vertical:
return reverse ? AxisDirection.up : AxisDirection.down;
}
throw new Exception("unknown axisDirection");
}
public enum RenderComparison
{
public enum RenderComparison {
identical,
metadata,
paint,

6
Assets/UIWidgets/rendering/viewpoint.cs


AxisDirection axisDirection = AxisDirection.down,
AxisDirection crossAxisDirection = AxisDirection.right,
ViewportOffset offset = null,
double cacheExtent = RenderAbstractViewportUtils.defaultCacheExtent
double? cacheExtent = null
this._cacheExtent = cacheExtent;
this._cacheExtent = cacheExtent ?? RenderAbstractViewportUtils.defaultCacheExtent;
}
public AxisDirection axisDirection {

double anchor = 0.0,
List<RenderSliver> children = null,
RenderSliver center = null,
double cacheExtent = RenderAbstractViewportUtils.defaultCacheExtent
double? cacheExtent = null
) : base(axisDirection, crossAxisDirection, offset, cacheExtent) {
this.addAll(children);
if (center == null && this.firstChild != null) {

25
Assets/UIWidgets/widgets/debug.cs


});
}
public static bool debugCheckHasDirectionality(BuildContext context) {
D.assert(() => {
if (!(context.widget is Directionality) &&
context.ancestorWidgetOfExactType(typeof(Directionality)) == null) {
Element element = (Element) context;
throw new UIWidgetsError(
"No Directionality widget found.\n" +
context.widget.GetType() + " widgets require a Directionality widget ancestor.\n" +
"The specific widget that could not find a Directionality ancestor was:\n" +
" " + context.widget + "\n" +
"The ownership chain for the affected widget is:\n" +
" " + element.debugGetCreatorChain(10) + "\n" +
"Typically, the Directionality widget is introduced by the MaterialApp " +
"or WidgetsApp widget at the top of your application widget tree. It " +
"determines the ambient reading direction and is used, for example, to " +
"determine how to lay out text, how to interpret \"start\" and \"end\" " +
"values, and to resolve EdgeInsetsDirectional, " +
"AlignmentDirectional, and other *Directional objects.");
}
return true;
});
return true;
}
internal static UIWidgetsErrorDetails _debugReportException(
string context,
Exception exception,

2
Assets/UIWidgets/widgets/framework.cs


public virtual void visitChildren(ElementVisitor visitor) {
}
public void debugVisitOnstageChildren(ElementVisitor visitor) {
public virtual void debugVisitOnstageChildren(ElementVisitor visitor) {
this.visitChildren(visitor);
}

44
Assets/UIWidgets/widgets/primary_scroll_controller.cs


using UIWidgets.foundation;
namespace UIWidgets.widgets {
public class PrimaryScrollController : InheritedWidget {
public PrimaryScrollController(
Key key = null,
ScrollController controller = null,
Widget child = null
) : base(key: key, child: child) {
D.assert(controller != null);
}
private PrimaryScrollController(
Key key = null,
Widget child = null
) : base(key: key, child: child) {
}
public static PrimaryScrollController none(
Key key = null,
Widget child = null
) {
return new PrimaryScrollController(key, child);
}
public readonly ScrollController controller;
public static ScrollController of(BuildContext context) {
PrimaryScrollController result =
(PrimaryScrollController) context.inheritFromWidgetOfExactType(typeof(PrimaryScrollController));
return result == null ? null : result.controller;
}
public override bool updateShouldNotify(InheritedWidget oldWidget) {
return this.controller != ((PrimaryScrollController) oldWidget).controller;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<ScrollController>("controller", this.controller,
ifNull: "no controller", showName: false));
}
}
}

3
Assets/UIWidgets/widgets/primary_scroll_controller.cs.meta


fileFormatVersion: 2
guid: aaa3c6886fef4a7b80059bd64b818145
timeCreated: 1537172309

173
Assets/UIWidgets/widgets/scroll_view.cs


using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.painting;
using UIWidgets.rendering;
namespace UIWidgets.widgets {
public abstract class ScrollView : StatelessWidget {
protected ScrollView(
Key key = null,
Axis scrollDirection = Axis.vertical,
bool reverse = false,
ScrollController controller = null,
bool? primary = null,
ScrollPhysics physics = null,
bool shrinkWrap = false,
double? cacheExtent = null
) : base(key: key) {
D.assert(!(controller != null && primary == true),
"Primary ScrollViews obtain their ScrollController via inheritance from a PrimaryScrollController widget. " +
"You cannot both set primary to true and pass an explicit controller.");
primary = primary ?? controller == null && scrollDirection == Axis.vertical;
physics = physics ?? (primary.Value ? new AlwaysScrollableScrollPhysics() : null);
this.scrollDirection = scrollDirection;
this.reverse = reverse;
this.controller = controller;
this.primary = primary.Value;
this.physics = physics;
this.shrinkWrap = shrinkWrap;
this.cacheExtent = cacheExtent;
}
public readonly Axis scrollDirection;
public readonly bool reverse;
public readonly ScrollController controller;
public readonly bool primary;
public readonly ScrollPhysics physics;
public readonly bool shrinkWrap;
public readonly double? cacheExtent;
protected AxisDirection getDirection(BuildContext context) {
return AxisUtils.getAxisDirectionFromAxisReverseAndDirectionality(context, this.scrollDirection,
this.reverse);
}
protected abstract List<Widget> buildSlivers(BuildContext context);
protected Widget buildViewport(
BuildContext context,
ViewportOffset offset,
AxisDirection axisDirection,
List<Widget> slivers
) {
if (this.shrinkWrap) {
return new ShrinkWrappingViewport(
axisDirection: axisDirection,
offset: offset,
slivers: slivers
);
}
return new Viewport(
axisDirection: axisDirection,
offset: offset,
slivers: slivers,
cacheExtent: this.cacheExtent
);
}
public override Widget build(BuildContext context) {
List<Widget> slivers = this.buildSlivers(context);
AxisDirection axisDirection = this.getDirection(context);
ScrollController scrollController = this.primary ? PrimaryScrollController.of(context) : this.controller;
Scrollable scrollable = new Scrollable(
axisDirection: axisDirection,
controller: scrollController,
physics: this.physics,
viewportBuilder: (viewportContext, offset) =>
this.buildViewport(viewportContext, offset, axisDirection, slivers)
);
return this.primary && scrollController != null
? (Widget) PrimaryScrollController.none(child: scrollable)
: scrollable;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<Axis>("scrollDirection", this.scrollDirection));
properties.add(new FlagProperty("reverse", value: this.reverse, ifTrue: "reversed", showName: true));
properties.add(new DiagnosticsProperty<ScrollController>("controller", this.controller, showName: false,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new FlagProperty("primary", value: this.primary, ifTrue: "using primary controller",
showName: true));
properties.add(new DiagnosticsProperty<ScrollPhysics>("physics", this.physics, showName: false,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new FlagProperty("shrinkWrap", value: this.shrinkWrap, ifTrue: "shrink-wrapping",
showName: true));
}
}
public abstract class BoxScrollView : ScrollView {
public BoxScrollView(
Key key = null,
Axis scrollDirection = Axis.vertical,
bool reverse = false,
ScrollController controller = null,
bool? primary = null,
ScrollPhysics physics = null,
bool shrinkWrap = false,
EdgeInsets padding = null,
double? cacheExtent = null
) : base(
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
controller: controller,
primary: primary,
physics: physics,
shrinkWrap: shrinkWrap,
cacheExtent: cacheExtent
) {
this.padding = padding;
}
public readonly EdgeInsets padding;
protected override List<Widget> buildSlivers(BuildContext context) {
Widget sliver = this.buildChildLayout(context);
EdgeInsets effectivePadding = this.padding;
if (this.padding == null) {
// final MediaQueryData mediaQuery = MediaQuery.of(context, nullOk: true);
// if (mediaQuery != null) {
// // Automatically pad sliver with padding from MediaQuery.
// final EdgeInsets mediaQueryHorizontalPadding =
// mediaQuery.padding.copyWith(top: 0.0, bottom: 0.0);
// final EdgeInsets mediaQueryVerticalPadding =
// mediaQuery.padding.copyWith(left: 0.0, right: 0.0);
// // Consume the main axis padding with SliverPadding.
// effectivePadding = scrollDirection == Axis.vertical
// ? mediaQueryVerticalPadding
// : mediaQueryHorizontalPadding;
// // Leave behind the cross axis padding.
// sliver = new MediaQuery(
// data: mediaQuery.copyWith(
// padding: scrollDirection == Axis.vertical
// ? mediaQueryHorizontalPadding
// : mediaQueryVerticalPadding,
// ),
// child: sliver,
// );
// }
}
if (effectivePadding != null) {
// sliver = new SliverPadding(padding: effectivePadding, sliver: sliver);
}
return new List<Widget> {sliver};
}
protected abstract Widget buildChildLayout(BuildContext context);
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<EdgeInsets>("padding", this.padding,
defaultValue: Diagnostics.kNullDefaultValue));
}
}
}

3
Assets/UIWidgets/widgets/scroll_view.cs.meta


fileFormatVersion: 2
guid: 167b885cf5254b048c2bac3acf71aafa
timeCreated: 1537171143

192
Assets/UIWidgets/widgets/viewport.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.foundation;
using UIWidgets.painting;
using UIWidgets.rendering;
namespace UIWidgets.widgets {
public class Viewport : MultiChildRenderObjectWidget {
public Viewport(
Key key = null,
AxisDirection axisDirection = AxisDirection.down,
AxisDirection? crossAxisDirection = null,
double anchor = 0.0,
ViewportOffset offset = null,
Key center = null,
double? cacheExtent = null,
List<Widget> slivers = null
) : base(key: key, children: slivers) {
D.assert(offset != null);
slivers = slivers ?? new List<Widget>();
D.assert(slivers != null);
D.assert(center == null || slivers.Count(child => child.key == center) == 1);
this.axisDirection = axisDirection;
this.crossAxisDirection = crossAxisDirection;
this.anchor = anchor;
this.offset = offset;
this.center = center;
this.cacheExtent = cacheExtent;
}
public readonly AxisDirection axisDirection;
public readonly AxisDirection? crossAxisDirection;
public readonly double anchor;
public readonly ViewportOffset offset;
public readonly Key center;
public readonly double? cacheExtent;
public static AxisDirection getDefaultCrossAxisDirection(BuildContext context, AxisDirection axisDirection) {
switch (axisDirection) {
case AxisDirection.up:
return AxisUtils.textDirectionToAxisDirection(Directionality.of(context));
case AxisDirection.right:
return AxisDirection.down;
case AxisDirection.down:
return AxisUtils.textDirectionToAxisDirection(Directionality.of(context));
case AxisDirection.left:
return AxisDirection.down;
}
throw new Exception("unknown axisDirection");
}
public override RenderObject createRenderObject(BuildContext context) {
return new RenderViewport(
axisDirection: this.axisDirection,
crossAxisDirection: this.crossAxisDirection ??
Viewport.getDefaultCrossAxisDirection(context, this.axisDirection),
anchor: this.anchor,
offset: this.offset,
cacheExtent: this.cacheExtent
);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObjectRaw) {
var renderObject = (RenderViewport) renderObjectRaw;
renderObject.axisDirection = this.axisDirection;
renderObject.crossAxisDirection = this.crossAxisDirection ??
Viewport.getDefaultCrossAxisDirection(context, this.axisDirection);
renderObject.anchor = this.anchor;
renderObject.offset = this.offset;
renderObject.cacheExtent = this.cacheExtent ?? RenderAbstractViewportUtils.defaultCacheExtent;
}
public override Element createElement() {
return new _ViewportElement(this);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<AxisDirection>("axisDirection", this.axisDirection));
properties.add(new EnumProperty<AxisDirection?>("crossAxisDirection", this.crossAxisDirection,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DoubleProperty("anchor", this.anchor));
properties.add(new DiagnosticsProperty<ViewportOffset>("offset", this.offset));
if (this.center != null) {
properties.add(new DiagnosticsProperty<Key>("center", this.center));
} else if (this.children.isNotEmpty() && this.children.First().key != null) {
properties.add(new DiagnosticsProperty<Key>("center", this.children.First().key, tooltip: "implicit"));
}
}
}
class _ViewportElement : MultiChildRenderObjectElement {
internal _ViewportElement(Viewport widget) : base(widget) {
}
public new Viewport widget {
get { return (Viewport) base.widget; }
}
public new RenderViewport renderObject {
get { return (RenderViewport) base.renderObject; }
}
public override void mount(Element parent, object newSlot) {
base.mount(parent, newSlot);
this._updateCenter();
}
public override void update(Widget newWidget) {
base.update(newWidget);
this._updateCenter();
}
void _updateCenter() {
if (this.widget.center != null) {
this.renderObject.center = (RenderSliver) this.children.Single(
element => element.widget.key == this.widget.center).renderObject;
} else if (this.children.Any()) {
this.renderObject.center = (RenderSliver) this.children.First().renderObject;
} else {
this.renderObject.center = null;
}
}
public override void debugVisitOnstageChildren(ElementVisitor visitor) {
this.children.Where(e => {
RenderSliver renderSliver = (RenderSliver) e.renderObject;
return renderSliver.geometry.visible;
}).ToList().ForEach(e => visitor(e));
}
}
public class ShrinkWrappingViewport : MultiChildRenderObjectWidget {
public ShrinkWrappingViewport(
Key key = null,
AxisDirection axisDirection = AxisDirection.down,
AxisDirection? crossAxisDirection = null,
ViewportOffset offset = null,
List<Widget> slivers = null
) : base(key: key, children: slivers) {
D.assert(offset != null);
this.axisDirection = axisDirection;
this.crossAxisDirection = crossAxisDirection;
this.offset = offset;
}
public readonly AxisDirection axisDirection;
public readonly AxisDirection? crossAxisDirection;
public readonly ViewportOffset offset;
public override RenderObject createRenderObject(BuildContext context) {
return new RenderShrinkWrappingViewport(
axisDirection: this.axisDirection,
crossAxisDirection:
this.crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection(context, this.axisDirection),
offset: this.offset
);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObjectRaw) {
var renderObject = (RenderShrinkWrappingViewport) renderObjectRaw;
renderObject.axisDirection = this.axisDirection;
renderObject.crossAxisDirection =
this.crossAxisDirection ?? Viewport.getDefaultCrossAxisDirection(context, this.axisDirection);
renderObject.offset = this.offset;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<AxisDirection>("axisDirection", this.axisDirection));
properties.add(new EnumProperty<AxisDirection?>("crossAxisDirection", this.crossAxisDirection,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<ViewportOffset>("offset", this.offset));
}
}
}

3
Assets/UIWidgets/widgets/viewport.cs.meta


fileFormatVersion: 2
guid: cbc0da359825401197d0c5772ebdaac1
timeCreated: 1537172721
正在加载...
取消
保存