浏览代码

widgets

/main
kg 6 年前
当前提交
731f823d
共有 14 个文件被更改,包括 896 次插入111 次删除
  1. 109
      Assets/UIWidgets/foundation/diagnostics.cs
  2. 4
      Assets/UIWidgets/gestures/recognizer.cs
  3. 2
      Assets/UIWidgets/gestures/tap.cs
  4. 2
      Assets/UIWidgets/rendering/box.cs
  5. 2
      Assets/UIWidgets/rendering/object.cs
  6. 4
      Assets/UIWidgets/rendering/proxy_box.cs
  7. 1
      Assets/UIWidgets/scheduler/ticker.cs
  8. 474
      Assets/UIWidgets/widgets/framework.cs
  9. 196
      Assets/UIWidgets/widgets/scroll_activity.cs
  10. 154
      Assets/UIWidgets/widgets/scroll_position.cs
  11. 56
      Assets/UIWidgets/foundation/key.cs
  12. 3
      Assets/UIWidgets/foundation/key.cs.meta
  13. 0
      /Assets/UIWidgets/widgets/scroll_metrics.cs
  14. 0
      /Assets/UIWidgets/widgets/scroll_metrics.cs.meta

109
Assets/UIWidgets/foundation/diagnostics.cs


}
}
public class ObjectFlagProperty<T> : DiagnosticsProperty<T> {
public ObjectFlagProperty(String name, T value,
string ifPresent = null,
String ifNull = null,
bool showName = false,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
value,
showName: showName,
ifNull: ifNull,
level: level
) {
D.assert(ifPresent != null || ifNull != null);
}
private ObjectFlagProperty(
String name,
T value,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
value,
showName: false,
level: level
) {
D.assert(name != null);
this.ifPresent = "has " + name;
}
public static ObjectFlagProperty<T> has(
String name,
T value,
DiagnosticLevel level = DiagnosticLevel.info
) {
return new ObjectFlagProperty<T>(name, value, level);
}
public readonly string ifPresent;
protected override string valueToString(
TextTreeConfiguration parentConfiguration = null) {
if (this.value != null) {
if (this.ifPresent != null) {
return this.ifPresent;
}
} else {
if (this.ifNull != null) {
return this.ifNull;
}
}
return base.valueToString(parentConfiguration: parentConfiguration);
}
public override bool showName {
get {
if ((this.value != null && this.ifPresent == null) || (this.value == null && this.ifNull == null)) {
return true;
}
return base.showName;
}
}
public override DiagnosticLevel level {
get {
if (this.value != null) {
if (this.ifPresent == null) {
return DiagnosticLevel.hidden;
}
} else {
if (this.ifNull == null) {
return DiagnosticLevel.hidden;
}
}
return base.level;
}
}
public override Dictionary<String, Object> toJsonMap() {
var json = base.toJsonMap();
if (this.ifPresent != null) {
json["ifPresent"] = this.ifPresent;
}
return json;
}
}
public delegate T ComputePropertyValueCallback<T>();
public class DiagnosticsProperty<T> : DiagnosticsNode {

}
D.assert(defaultValue == null || defaultValue == Diagnostics.kNoDefaultValue || defaultValue is T);
this._description = description;
this._valueComputed = true;
this._value = value;

this.ifEmpty = ifEmpty;
this.defaultValue = defaultValue;
this.tooltip = tooltip;

}
D.assert(defaultValue == null || defaultValue == Diagnostics.kNoDefaultValue || defaultValue is T);
this._description = description;
this._valueComputed = false;
this._value = default(T);

this.ifEmpty = ifEmpty;
this.defaultValue = defaultValue;
this.tooltip = tooltip;

public override Dictionary<string, object> toJsonMap() {
var json = base.toJsonMap();
if (this.defaultValue != Diagnostics.kNoDefaultValue) {
json["defaultValue"] = this.defaultValue == null ? "null" : this.defaultValue.ToString();
}

}
json["missingIfNull"] = this.missingIfNull;
if (typeof(Diagnosticable).IsAssignableFrom(typeof(T))) {
json["isDiagnosticableValue"] = true;
}

}
public readonly string ifNull;
public readonly bool missingIfNull;
public Type propertyType {

}
public readonly object defaultValue;
DiagnosticLevel _defaultLevel;
public override DiagnosticLevel level {

}
readonly T _value;
DiagnosticPropertiesBuilder _cachedBuilder;
DiagnosticPropertiesBuilder _builder {

);
}
protected internal virtual void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public virtual void debugFillProperties(DiagnosticPropertiesBuilder properties) {
}
}

);
}
protected internal virtual List<DiagnosticsNode> debugDescribeChildren() {
public virtual List<DiagnosticsNode> debugDescribeChildren() {
return new List<DiagnosticsNode>();
}
}

4
Assets/UIWidgets/gestures/recognizer.cs


public abstract void acceptGesture(int pointer);
public abstract void rejectGesture(int pointer);
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<object>("debugOwner", this.debugOwner,
defaultValue: Diagnostics.kNullDefaultValue));

return offset.distance;
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<GestureRecognizerState>("state", this.state));
}

2
Assets/UIWidgets/gestures/tap.cs


get { return "tap"; }
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new FlagProperty("wonArenaForPrimaryPointer",
value: this._wonArenaForPrimaryPointer,

2
Assets/UIWidgets/rendering/box.cs


return true;
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Size>("size", this._size, missingIfNull: true));
}

2
Assets/UIWidgets/rendering/object.cs


public virtual void handleEvent(PointerEvent evt, HitTestEntry entry) {
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
properties.add(new DiagnosticsProperty<object>(
"creator", this.debugCreator, defaultValue: Diagnostics.kNullDefaultValue,
level: DiagnosticLevel.debug));

4
Assets/UIWidgets/rendering/proxy_box.cs


return this.behavior == HitTestBehavior.opaque;
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<HitTestBehavior>(
"behavior", this.behavior, defaultValue: Diagnostics.kNullDefaultValue));

}
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
var listeners = new List<string>();
if (this.onPointerDown != null)

1
Assets/UIWidgets/scheduler/ticker.cs


public interface TickerProvider {
Ticker createTicker(TickerCallback onTick);
SchedulerBinding schedulerBinding { get; }
}
public class Ticker {

474
Assets/UIWidgets/widgets/framework.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIWidgets.foundation;
using UIWidgets.rendering;
using UIWidgets.ui;

public delegate void ElementVisitor(Element element);
public delegate bool ElementVisitorBool(Element element);
public class UniqueKey : LocalKey {
public UniqueKey() {
}
public override string ToString() {
return string.Format("[#{0}]", Diagnostics.shortHash(this));
}
}
public class ObjectKey : LocalKey, IEquatable<ObjectKey> {
public ObjectKey(object value) {
this.value = value;
}
public readonly object value;
public bool Equals(ObjectKey other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return object.Equals(this.value, other.value);
}
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((ObjectKey) obj);
}
public override int GetHashCode() {
return (this.value != null ? this.value.GetHashCode() : 0);
}
public static bool operator ==(ObjectKey left, ObjectKey right) {
return object.Equals(left, right);
}
public static bool operator !=(ObjectKey left, ObjectKey right) {
return !object.Equals(left, right);
}
public override string ToString() {
return string.Format("[{0} {1}]", this.GetType(), Diagnostics.describeIdentity(this.value));
}
}
public abstract class GlobalKey<T> : Key where T : State<StatefulWidget> {
protected GlobalKey() {
}
public static GlobalKey<T> key(string debugLabel = null) {
return new LabeledGlobalKey<T>(debugLabel);
}
static readonly Dictionary<GlobalKey<T>, Element> _registry = new Dictionary<GlobalKey<T>, Element>();
static readonly HashSet<GlobalKey<T>> _removedKeys = new HashSet<GlobalKey<T>>();
static readonly HashSet<Element> _debugIllFatedElements = new HashSet<Element>();
static readonly Dictionary<GlobalKey<T>, Element> _debugReservations = new Dictionary<GlobalKey<T>, Element>();
void _register(Element element) {
D.assert(() => {
if (_registry.ContainsKey(this)) {
D.assert(element.widget != null);
D.assert(_registry[this].widget != null);
D.assert(element.widget.GetType() != _registry[this].widget.GetType());
_debugIllFatedElements.Add(_registry[this]);
}
return true;
});
_registry[this] = element;
}
void _unregister(Element element) {
D.assert(() => {
if (_registry.ContainsKey(this) && _registry[this] != element) {
D.assert(element.widget != null);
D.assert(_registry[this].widget != null);
D.assert(element.widget.GetType() != _registry[this].widget.GetType());
}
return true;
});
if (_registry[this] == element) {
_registry.Remove(this);
_removedKeys.Add(this);
}
}
void _debugReserveFor(Element parent) {
D.assert(() => {
D.assert(parent != null);
if (_debugReservations.ContainsKey(this) && _debugReservations[this] != parent) {
string older = _debugReservations[this].ToString();
string newer = parent.ToString();
if (older != newer) {
throw new UIWidgetsError(
string.Format(
"Multiple widgets used the same GlobalKey.\n" +
"The key {0} was used by multiple widgets. The parents of those widgets were:\n" +
"- {1}\n" +
"- {2}\n" +
"A GlobalKey can only be specified on one widget at a time in the widget tree.",
this, older, newer));
}
throw new UIWidgetsError(
string.Format(
"Multiple widgets used the same GlobalKey.\n" +
"The key {0} was used by multiple widgets. The parents of those widgets were " +
"different widgets that both had the following description:\n" +
" {1}\n" +
"A GlobalKey can only be specified on one widget at a time in the widget tree.",
this, newer));
}
_debugReservations[this] = parent;
return true;
});
}
static void _debugVerifyIllFatedPopulation() {
D.assert(() => {
Dictionary<GlobalKey<T>, HashSet<Element>> duplicates = null;
foreach (Element element in _debugIllFatedElements) {
if (element._debugLifecycleState != _ElementLifecycle.defunct) {
D.assert(element != null);
D.assert(element.widget != null);
D.assert(element.widget.key != null);
GlobalKey key = element.widget.key;
D.assert(_registry.ContainsKey(key));
duplicates = duplicates ?? new Dictionary<GlobalKey<T>, HashSet<Element>>();
var elements = duplicates.putIfAbsent(key, () => new HashSet<Element>());
elements.Add(element);
elements.Add(_registry[key]);
}
}
_debugIllFatedElements.Clear();
_debugReservations.Clear();
if (duplicates != null) {
var buffer = new StringBuilder();
buffer.AppendLine("Multiple widgets used the same GlobalKey.\n");
foreach (GlobalKey<T> key in duplicates.Keys) {
HashSet<Element> elements = duplicates[key];
buffer.AppendLine(string.Format("The key {0} was used by {1} widgets:", key, elements.Count));
foreach (Element element in elements) {
buffer.AppendLine("- " + element);
}
}
public abstract class Widget {
protected Widget(string key) {
this._key = key;
buffer.Append("A GlobalKey can only be specified on one widget at a time in the widget tree.");
throw new UIWidgetsError(buffer.ToString());
}
return true;
});
public readonly string _key;
Element _currentElement {
get { return _registry[this]; }
}
public string key {
get { return this._key; }
public BuildContext currentContext {
get { return this._currentElement; }
public abstract Element createElement();
public Widget currentWidget {
get { return this._currentElement == null ? null : this._currentElement.widget; }
}
public T currentState {
get {
Element element = this._currentElement;
if (element is StatefulElement) {
var statefulElement = (StatefulElement) element;
State state = statefulElement.state;
if (state is T) {
return (T) state;
}
}
return null;
}
}
}
public class LabeledGlobalKey<T> : GlobalKey<T> where T : State<StatefulWidget> {
public LabeledGlobalKey(string _debugLabel = null) {
}
readonly string _debugLabel;
public override string ToString() {
string label = this._debugLabel != null ? " " + this._debugLabel : "";
if (this.GetType() == typeof(LabeledGlobalKey<T>)) {
return string.Format("[GlobalKey#{0}{1}]", Diagnostics.shortHash(this), label);
}
return string.Format("[{0}{1}]", Diagnostics.describeIdentity(this), label);
}
}
class GlobalObjectKey<T> : GlobalKey<T>, IEquatable<GlobalObjectKey<T>> where T : State<StatefulWidget> {
public GlobalObjectKey(object value) {
}
public readonly Object value;
public bool Equals(GlobalObjectKey<T> other) {
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(this.value, other.value);
}
public override bool Equals(object obj) {
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((GlobalObjectKey<T>) obj);
}
public override int GetHashCode() {
return (this.value != null ? this.value.GetHashCode() : 0);
}
public static bool operator ==(GlobalObjectKey<T> left, GlobalObjectKey<T> right) {
return Equals(left, right);
}
public static bool operator !=(GlobalObjectKey<T> left, GlobalObjectKey<T> right) {
return !Equals(left, right);
}
public override string ToString() {
String selfType = this.GetType().ToString();
string suffix = "<State<StatefulWidget>>";
if (selfType.EndsWith(suffix)) {
selfType = selfType.Substring(0, selfType.Length - suffix.Length);
}
return string.Format("[{0} {1}]", selfType, Diagnostics.describeIdentity(this.value));
}
}
public delegate void ElementVisitor(Element element);
public delegate bool ElementVisitorBool(Element element);
public abstract class Widget : DiagnosticableTree {
protected Widget(Key key = null) {
this.key = key;
}
public readonly Key key;
protected abstract Element createElement();
public override string toStringShort() {
return this.key == null ? this.GetType().ToString() : this.GetType() + "-" + this.key;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.dense;
}
return oldWidget.GetType() == newWidget.GetType() && oldWidget.key == newWidget.key;
return oldWidget.GetType() == newWidget.GetType() && object.Equals(oldWidget.key, newWidget.key);
protected StatelessWidget(string key) : base(key) {
protected StatelessWidget(Key key = null) : base(key: key) {
public override Element createElement() {
protected override Element createElement() {
public abstract Widget build(BuildContext context);
protected abstract Widget build(BuildContext context);
protected StatefulWidget(string key) : base(key) {
protected StatefulWidget(Key key) : base(key: key) {
public override Element createElement() {
protected override Element createElement() {
public abstract State createState();
protected abstract State createState();
enum _StateLifecycle {
created,
initialized,

public delegate void StateSetter(VoidCallback fn);
get { return _widget; }
set { _widget = value; }
get { return this._widget; }
private StatefulWidget _widget;
StatefulWidget _widget;
protected virtual bool _debugTypesAreRight(Widget widget) {
return widget is StatefulWidget;
}
get { return _element; }
get { return this._element; }
public StatefulElement element {
get { return _element; }
set { _element = value; }
}
private StatefulElement _element;
StatefulElement _element;
get { return _element != null; }
get { return this._element != null; }
public virtual void initState() {
D.assert(_debugLifecycleState == _StateLifecycle.created);
protected virtual void initState() {
D.assert(this._debugLifecycleState == _StateLifecycle.created);
public abstract void didChangeDependencies();
public abstract void reassemble();
protected void setState(VoidCallback fn) {
D.assert(fn != null);
D.assert(() => {
if (this._debugLifecycleState == _StateLifecycle.defunct) {
throw new UIWidgetsError(
"setState() called after dispose(): " + this + "\n" +
"This error happens if you call setState() on a State object for a widget that " +
"no longer appears in the widget tree (e.g., whose parent widget no longer " +
"includes the widget in its build). This error can occur when code calls " +
"setState() from a timer or an animation callback. The preferred solution is " +
"to cancel the timer or stop listening to the animation in the dispose() " +
"callback. Another solution is to check the \"mounted\" property of this " +
"object before calling setState() to ensure the object is still in the " +
"tree.\n" +
"This error might indicate a memory leak if setState() is being called " +
"because another object is retaining a reference to this State object " +
"after it has been removed from the tree. To avoid memory leaks, " +
"consider breaking the reference to this object during dispose()."
);
}
if (this._debugLifecycleState == _StateLifecycle.created && !this.mounted) {
throw new UIWidgetsError(
"setState() called in constructor: " + this + "\n" +
"This happens when you call setState() on a State object for a widget that " +
"hasn\"t been inserted into the widget tree yet. It is not necessary to call " +
"setState() in the constructor, since the state is already assumed to be dirty " +
"when it is initially created."
);
}
public void setState(VoidCallback fn) {
return true;
});
_element.markNeedsBuild();
this._element.markNeedsBuild();
}
protected virtual void deactivate() {
}
protected void dispose() {
D.assert(this._debugLifecycleState == _StateLifecycle.ready);
D.assert(() => {
this._debugLifecycleState = _StateLifecycle.defunct;
return true;
});
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
protected virtual void didChangeDependencies() {
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
D.assert(() => {
properties.add(new EnumProperty<_StateLifecycle>("lifecycle state", _debugLifecycleState,
defaultValue: _StateLifecycle.ready));
return true;
});
properties.add(new ObjectFlagProperty<StatefulWidget>("_widget", this._widget, ifNull: "no widget"));
properties.add(new ObjectFlagProperty<StatefulElement>("_element", this._element, ifNull: "not mounted"));
}
}
public abstract class State<T> : State where T : StatefulWidget {
public new T widget {
get { return (T) base.widget; }
}
protected bool _debugTypesAreRight(Widget widget) {
return widget is T;
}
}
public abstract class ProxyWidget : Widget {
protected ProxyWidget(Key key = null, Widget child = null) : base(key: key) {
this.child = child;
}
public readonly Widget child;
}
public abstract class ParentDataWidget<T> : ProxyWidget where T : RenderObjectWidget {
public ParentDataWidget(Key key = null, Widget child = null)
: base(key: key, child: child) {
}
protected override Element createElement() {
return new ParentDataElement<T>(this);
}
protected virtual bool debugIsValidAncestor(RenderObjectWidget ancestor) {
D.assert(typeof(T) != typeof(RenderObjectWidget));
return ancestor is T;
}
protected virtual string debugDescribeInvalidAncestorChain(
String description = null, String ownershipChain = null, bool foundValidAncestor = false,
IEnumerable<Widget> badAncestors = null
) {
D.assert(typeof(T) != typeof(RenderObjectWidget));
String result;
if (!foundValidAncestor) {
result = string.Format("{0} widgets must be placed inside {1} widgets.\n" +
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(T), description);
} else {
D.assert(badAncestors != null);
D.assert(badAncestors.Any());
result = string.Format("{0} widgets must be placed directly inside {1} widgets.\n" +
"{2} has a {1} ancestor, but there are other widgets between them:\n",
this.GetType(), typeof(T), description);
foreach (Widget ancestor in badAncestors) {
if (ancestor.GetType() == this.GetType()) {
result += string.Format("- {0} (this is a different {1} than the one with the problem)\n",
ancestor, this.GetType());
} else {
result += string.Format("- {0}\n", ancestor);
}
}
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(T) + ".\n";
}
result += "The ownership chain for the parent of the offending "
+ this.GetType() + " was:\n " + ownershipChain;
return result;
}
protected abstract void applyParentData(RenderObject renderObject);
protected virtual bool debugCanApplyOutOfTurn() {
return false;
}
}

}
private static int _nextHashCode = 1;
private readonly int _cachedHash = Element._nextHashCode = (Element._nextHashCode + 1) % 0xffffff;
public override int GetHashCode() {

public RenderObject renderObject {
get {
RenderObject result = null;
}
else {
} else {
return result;
}
}

this._owner = parent.owner;
}
// _updateInheritance();
// _updateInheritance();
}
void updateSlotForChild(Element child, object newSlot) {

}
}
public void detachRenderObject() {
this.visitChildren(child => { child.detachRenderObject(); });
this._slot = null;

public abstract void performRebuild();
}
public abstract class ComponentElement : Element {
protected ComponentElement(Widget widget) : base(widget) {
}

public override void mount(Element parent, object newSlot) {
base.mount(parent, newSlot);
this._firstBuild();
}

public override void performRebuild() {
Widget built;
try {
built = this.build();
}

public override void update(Widget newWidget) {
base.update(newWidget);
this._dirty = true;
this.rebuild();
}

public override void update(Widget newWidget) {
base.update(newWidget);
this.widget.updateRenderObject(this, this.renderObject);
this._dirty = false;
}

public readonly _InactiveElements _inactiveElements = new _InactiveElements();
public readonly List<Element> _dirtyElements = new List<Element>();
public bool _scheduledFlushDirtyElements = false;
public bool _dirtyElementsNeedsResorting = false;

return;
}
try {
this._scheduledFlushDirtyElements = true;
if (callback != null) {

this._dirtyElements.Sort(Element._sort);
this._dirtyElementsNeedsResorting = false;
if (dirtyCount < this._dirtyElements.Count || this._dirtyElementsNeedsResorting) {
this._dirtyElements.Sort(Element._sort);
this._dirtyElementsNeedsResorting = false;

public SingleChildRenderObjectElement(SingleChildRenderObjectWidget widget) : base(widget) {
}
public override void forgetChild(Element child) {
}
}

public void _unmountAll() {
List<Element> elements = this._elements.ToList();
this._elements.Clear();
elements.ForEach(this._unmount);
}

196
Assets/UIWidgets/widgets/scroll_activity.cs


using System;
using RSG;
using UIWidgets.animation;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.painting;

}
public abstract class ScrollActivity {
public ScrollActivity(ScrollActivityDelegate @delegate) {
this._delegate = @delegate;
public ScrollActivity(ScrollActivityDelegate del) {
this._del = del;
public ScrollActivityDelegate @delegate {
get { return this._delegate; }
public ScrollActivityDelegate del {
get { return this._del; }
ScrollActivityDelegate _delegate;
ScrollActivityDelegate _del;
D.assert(this._delegate != value);
this._delegate = value;
D.assert(this._del != value);
this._del = value;
}
public virtual void resetActivity() {

public abstract double velocity { get; }
public virtual void dispose() {
this._delegate = null;
this._del = null;
}
public override string ToString() {

public class IdleScrollActivity : ScrollActivity {
public IdleScrollActivity(ScrollActivityDelegate @delegate) : base(@delegate) {
public IdleScrollActivity(ScrollActivityDelegate del) : base(del) {
this.@delegate.goBallistic(0.0);
this.del.goBallistic(0.0);
}
public override bool shouldIgnorePointer {

public class HoldScrollActivity : ScrollActivity, ScrollHoldController {
public HoldScrollActivity(
ScrollActivityDelegate @delegate = null,
ScrollActivityDelegate del = null,
) : base(@delegate) {
) : base(del) {
this.onHoldCanceled = onHoldCanceled;
}

}
public void cancel() {
this.@delegate.goBallistic(0.0);
this.del.goBallistic(0.0);
}
public override void dispose() {

public class ScrollDragController : Drag {
public ScrollDragController(
ScrollActivityDelegate @delegate = null,
ScrollActivityDelegate del = null,
D.assert(@delegate != null);
D.assert(del != null);
D.assert(details != null);
D.assert(
motionStartDistanceThreshold == null || motionStartDistanceThreshold > 0.0,

this._delegate = @delegate;
this._del = del;
this._lastDetails = details;
this._retainMomentum = carriedVelocity != null && carriedVelocity != 0.0;
this._lastNonStationaryTimestamp = details.sourceTimeStamp;

this.motionStartDistanceThreshold = motionStartDistanceThreshold;
}
public ScrollActivityDelegate @delegate {
get { return this._delegate; }
public ScrollActivityDelegate del {
get { return this._del; }
ScrollActivityDelegate _delegate;
ScrollActivityDelegate _del;
public readonly VoidCallback onDragCanceled;

const double _bigThresholdBreakDistance = 24.0;
bool _reversed {
get { return AxisUtils.axisDirectionIsReversed(this.@delegate.axisDirection); }
get { return AxisUtils.axisDirectionIsReversed(this.del.axisDirection); }
D.assert(this._delegate != value);
this._delegate = value;
D.assert(this._del != value);
this._del = value;
}
void _maybeLoseMomentum(double offset, DateTime? timestamp) {

offset = -offset;
}
this.@delegate.applyUserOffset(offset);
this.del.applyUserOffset(offset);
}
public void end(DragEndDetails details) {

velocity += this.carriedVelocity.Value;
}
this.@delegate.goBallistic(velocity);
this.del.goBallistic(velocity);
this.@delegate.goBallistic(0.0);
this.del.goBallistic(0.0);
}
public virtual void dispose() {

public class DragScrollActivity : ScrollActivity {
public DragScrollActivity(
ScrollActivityDelegate @delegate,
ScrollActivityDelegate del,
) : base(@delegate) {
) : base(del) {
this._controller = controller;
}

public override void dispose() {
this._controller = null;
base.dispose();
}
public override string ToString() {
return string.Format("{0}({1})", Diagnostics.describeIdentity(this), this._controller);
}
}
public class BallisticScrollActivity : ScrollActivity {
public BallisticScrollActivity(
ScrollActivityDelegate del,
Simulation simulation,
TickerProvider vsync
) : base(del) {
this._controller = AnimationController.unbounded(
debugLabel: this.GetType().ToString(),
vsync: vsync
);
this._controller.addListener(this._tick);
this._controller.animateWith(simulation).Then(() => this._end());
}
public override double velocity {
get { return this._controller.velocity; }
}
readonly AnimationController _controller;
public override void resetActivity() {
this.del.goBallistic(this.velocity);
}
public override void applyNewDimensions() {
this.del.goBallistic(this.velocity);
}
void _tick() {
if (!this.applyMoveTo(this._controller.value)) {
this.del.goIdle();
}
}
protected bool applyMoveTo(double value) {
return this.del.setPixels(value) == 0.0;
}
void _end() {
if (this.del != null) {
this.del.goBallistic(0.0);
}
}
public override void dispatchOverscrollNotification(
ScrollMetrics metrics, BuildContext context, double overscroll) {
new OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll,
velocity: this.velocity).dispatch(context);
}
public override bool shouldIgnorePointer {
get { return true; }
}
public override bool isScrolling {
get { return true; }
}
public override void dispose() {
this._controller.dispose();
base.dispose();
}
public override string ToString() {
return string.Format("{0}({1})", Diagnostics.describeIdentity(this), this._controller);
}
}
public class DrivenScrollActivity : ScrollActivity {
public DrivenScrollActivity(
ScrollActivityDelegate del,
double from,
double to,
TimeSpan duration,
Curve curve,
TickerProvider vsync
) : base(del) {
D.assert(duration > TimeSpan.Zero);
D.assert(curve != null);
this._completer = new Promise();
this._controller = AnimationController.unbounded(
value: from,
debugLabel: this.GetType().ToString(),
vsync: vsync
);
this._controller.addListener(this._tick);
this._controller.animateTo(to, duration: duration, curve: curve)
.Then(() => this._end());
}
readonly Promise _completer;
readonly AnimationController _controller;
public IPromise done {
get { return this._completer; }
}
public override double velocity {
get { return this._controller.velocity; }
}
void _tick() {
if (this.del.setPixels(this._controller.value) != 0.0) {
this.del.goIdle();
}
}
void _end() {
if (this.del != null) {
this.del.goBallistic(this.velocity);
}
}
public override void dispatchOverscrollNotification(
ScrollMetrics metrics, BuildContext context, double overscroll) {
new OverscrollNotification(metrics: metrics, context: context, overscroll: overscroll,
velocity: this.velocity).dispatch(context);
}
public override bool shouldIgnorePointer {
get { return true; }
}
public override bool isScrolling {
get { return true; }
}
public override void dispose() {
this._completer.Resolve();
this._controller.dispose();
base.dispose();
}

154
Assets/UIWidgets/widgets/scroll_position.cs


using UIWidgets.foundation;
using UIWidgets.scheduler;
using UIWidgets.ui;
// public abstract class ScrollPosition : ViewportOffset, ScrollMetrics {
//
// }
public abstract class ScrollPosition : ViewportOffset, ScrollMetrics {
ScrollPosition(
ScrollPhysics physics = null,
ScrollContext context = null,
bool keepScrollOffset = true,
ScrollPosition oldPosition = null,
string debugLabel = null
) {
D.assert(physics != null);
D.assert(context != null);
D.assert(context.vsync != null);
this.physics = physics;
this.context = context;
this.keepScrollOffset = keepScrollOffset;
this.debugLabel = debugLabel;
if (oldPosition != null) {
this.absorb(oldPosition);
}
if (keepScrollOffset) {
this.restoreScrollOffset();
}
}
public readonly ScrollPhysics physics;
public readonly ScrollContext context;
public readonly bool keepScrollOffset;
public readonly string debugLabel;
public double minScrollExtent {
get { return this._minScrollExtent; }
}
double _minScrollExtent;
public double maxScrollExtent {
get { return this._maxScrollExtent; }
}
double _maxScrollExtent;
public override double? pixels {
get { return this._pixels; }
}
double? _pixels;
public double viewportDimension {
get { return this._viewportDimension; }
}
double _viewportDimension;
public bool haveDimensions {
get { return this._haveDimensions; }
}
bool _haveDimensions = false;
protected virtual void absorb(ScrollPosition other) {
D.assert(other != null);
D.assert(other.context == context);
D.assert(_pixels == null);
_minScrollExtent = other.minScrollExtent;
_maxScrollExtent = other.maxScrollExtent;
_pixels = other._pixels;
_viewportDimension = other.viewportDimension;
D.assert(activity == null);
D.assert(other.activity != null);
_activity = other.activity;
other._activity = null;
if (other.runtimeType != runtimeType)
activity.resetActivity();
context.setIgnorePointer(activity.shouldIgnorePointer);
isScrollingNotifier.value = activity.isScrolling;
}
public double setPixels(double newPixels) {
D.assert(this._pixels != null);
D.assert(this.context.vsync.schedulerBinding.schedulerPhase <= SchedulerPhase.transientCallbacks);
if (newPixels != this.pixels) {
double overscroll = this.applyBoundaryConditions(newPixels);
D.assert(() => {
double delta = newPixels - this.pixels;
if (overscroll.abs() > delta.abs()) {
throw new UIWidgetsError(
string.Format(
"{0}.applyBoundaryConditions returned invalid overscroll value.\n" +
"setPixels() was called to change the scroll offset from {1} to {2}.\n" +
"That is a delta of {3} units.\n" +
"{0}.applyBoundaryConditions reported an overscroll of {4} units."
, this.GetType(), this.pixels, newPixels, delta, overscroll));
}
return true;
});
double oldPixels = this.pixels;
this._pixels = newPixels - overscroll;
if (this._pixels != oldPixels) {
this.notifyListeners();
this.didUpdateScrollPositionBy(this._pixels - oldPixels);
}
if (overscroll != 0.0) {
this.didOverscrollBy(overscroll);
return overscroll;
}
}
return 0.0;
}
public void correctPixels(double value) {
this._pixels = value;
}
public override void correctBy(double correction) {
D.assert(
this._pixels != null,
"An initial pixels value must exist by caling correctPixels on the ScrollPosition"
);
this._pixels += correction;
this._didChangeViewportDimensionOrReceiveCorrection = true;
}
protected void forcePixels(double value) {
D.assert(this.pixels != null);
_pixels = value;
notifyListeners();
}
protected void saveScrollOffset() {
PageStorage.of(context.storageContext)?.writeState(context.storageContext, pixels);
}
protected void restoreScrollOffset() {
if (pixels == null) {
final double value = PageStorage.of(context.storageContext)?.readState(context.storageContext);
if (value != null)
correctPixels(value);
}
}
}
}

56
Assets/UIWidgets/foundation/key.cs


using System;
using System.Collections.Generic;
namespace UIWidgets.foundation {
public abstract class Key {
protected Key() {
}
public static Key key(string value) {
return new ValueKey<string>(value);
}
}
public abstract class LocalKey : Key {
protected LocalKey() {
}
}
public class ValueKey<T> : LocalKey, IEquatable<ValueKey<T>> {
public ValueKey(T value) {
this.value = value;
}
public readonly T value;
public bool Equals(ValueKey<T> other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;
return EqualityComparer<T>.Default.Equals(this.value, other.value);
}
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((ValueKey<T>) obj);
}
public override int GetHashCode() {
return EqualityComparer<T>.Default.GetHashCode(this.value);
}
public static bool operator ==(ValueKey<T> left, ValueKey<T> right) {
return object.Equals(left, right);
}
public static bool operator !=(ValueKey<T> left, ValueKey<T> right) {
return !object.Equals(left, right);
}
public override string ToString() {
string valueString = typeof(T) == typeof(string) ? "<\'" + this.value + "\'>" : "<" + this.value + ">";
return string.Format("[{0} {1}]", this.GetType(), valueString);
}
}
}

3
Assets/UIWidgets/foundation/key.cs.meta


fileFormatVersion: 2
guid: 69b5bafdaadd44a9b8ef37ee8f62164e
timeCreated: 1536806963

/Assets/UIWidgets/widgets/scroll_matrics.cs → /Assets/UIWidgets/widgets/scroll_metrics.cs

/Assets/UIWidgets/widgets/scroll_matrics.cs.meta → /Assets/UIWidgets/widgets/scroll_metrics.cs.meta

正在加载...
取消
保存