kg
6 年前
当前提交
c7d683d2
共有 11 个文件被更改,包括 606 次插入 和 7 次删除
-
139Assets/UIWidgets/foundation/diagnostics.cs
-
23Assets/UIWidgets/painting/basic_types.cs
-
6Assets/UIWidgets/rendering/viewpoint.cs
-
25Assets/UIWidgets/widgets/debug.cs
-
2Assets/UIWidgets/widgets/framework.cs
-
44Assets/UIWidgets/widgets/primary_scroll_controller.cs
-
3Assets/UIWidgets/widgets/primary_scroll_controller.cs.meta
-
173Assets/UIWidgets/widgets/scroll_view.cs
-
3Assets/UIWidgets/widgets/scroll_view.cs.meta
-
192Assets/UIWidgets/widgets/viewport.cs
-
3Assets/UIWidgets/widgets/viewport.cs.meta
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: aaa3c6886fef4a7b80059bd64b818145 |
|||
timeCreated: 1537172309 |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 167b885cf5254b048c2bac3acf71aafa |
|||
timeCreated: 1537171143 |
|
|||
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)); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: cbc0da359825401197d0c5772ebdaac1 |
|||
timeCreated: 1537172721 |
撰写
预览
正在加载...
取消
保存
Reference in new issue