浏览代码

gestures

/main
kg 6 年前
当前提交
70cc57ee
共有 17 个文件被更改,包括 668 次插入135 次删除
  1. 5
      Assets/UIWidgets/Tests/Menu.cs
  2. 2
      Assets/UIWidgets/foundation/debug.cs
  3. 118
      Assets/UIWidgets/foundation/diagnostics.cs
  4. 57
      Assets/UIWidgets/foundation/node.cs
  5. 11
      Assets/UIWidgets/gestures/binding.cs
  6. 78
      Assets/UIWidgets/gestures/events.cs
  7. 25
      Assets/UIWidgets/rendering/binding.cs
  8. 22
      Assets/UIWidgets/rendering/box.cs
  9. 33
      Assets/UIWidgets/rendering/object.cs
  10. 92
      Assets/UIWidgets/rendering/proxy_box.cs
  11. 2
      Assets/UIWidgets/rendering/sliver_multi_box_adaptor.cs
  12. 90
      Assets/UIWidgets/Tests/Gestures.cs
  13. 3
      Assets/UIWidgets/Tests/Gestures.cs.meta
  14. 163
      Assets/UIWidgets/foundation/node.mixin.gen.cs
  15. 11
      Assets/UIWidgets/foundation/node.mixin.gen.cs.meta
  16. 88
      Assets/UIWidgets/foundation/node.mixin.njk
  17. 3
      Assets/UIWidgets/foundation/node.mixin.njk.meta

5
Assets/UIWidgets/Tests/Menu.cs


public static void renderRenderParagraph() {
EditorWindow.GetWindow(typeof(Paragraph));
}
[MenuItem("UIWidgetsTests/Gestures")]
public static void gestures() {
EditorWindow.GetWindow(typeof(Gestures));
}
}
}

2
Assets/UIWidgets/foundation/debug.cs


public static bool debugPrintGestureArenaDiagnostics = true;
public static bool debugPrintHitTestResults = true;
public static bool debugPaintPointersEnabled = false;
}
}

118
Assets/UIWidgets/foundation/diagnostics.cs


internal _NoDefaultValue() {
}
}
class _NullDefaultValue {
internal _NullDefaultValue() {
}
}
public abstract class DiagnosticsNode {
protected DiagnosticsNode(

}
}
public class EnumerableProperty<T> : DiagnosticsProperty<IEnumerable<T>> {
public EnumerableProperty(
string name,
IEnumerable<T> value,
object defaultValue = null,
string ifNull = null,
string ifEmpty = "[]",
DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine,
bool showName = true,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
value,
defaultValue: defaultValue,
ifNull: ifNull,
ifEmpty: ifEmpty,
style: style,
showName: showName,
level: level
) {
}
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
if (this.value == null) {
return "null";
}
if (!this.value.Any()) {
return this.ifEmpty ?? "[]";
}
if (parentConfiguration != null && !parentConfiguration.lineBreakProperties) {
return string.Join(", ", this.value.Select(v => v.ToString()).ToArray());
}
return string.Join(this.style == DiagnosticsTreeStyle.singleLine ? ", " : "\n",
this.value.Select(v => v.ToString()).ToArray());
}
public override DiagnosticLevel level {
get {
if (this.ifEmpty == null &&
this.value != null && !this.value.Any()
&& base.level != DiagnosticLevel.hidden) {
return DiagnosticLevel.fine;
}
return base.level;
}
}
public override Dictionary<string, object> toJsonMap() {
var json = base.toJsonMap();
if (this.value != null) {
json["values"] = this.value.Select(v => v.ToString()).ToList();
}
return json;
}
}
public class EnumProperty<T> : DiagnosticsProperty<T> {
public EnumProperty(String name, T value,
Object defaultValue = null,
DiagnosticLevel level = DiagnosticLevel.info
) : base(
name,
value,
defaultValue: defaultValue,
level: level
) {
}
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
if (this.value == null) {
return "null";
}
return this.value.ToString();
}
}
public class DiagnosticsProperty<T> : DiagnosticsNode where T : class {
public class DiagnosticsProperty<T> : DiagnosticsNode {
public DiagnosticsProperty(
string name,
T value,

style: style
) {
defaultValue = defaultValue ?? Diagnostics.kNoDefaultValue;
D.assert(defaultValue == Diagnostics.kNoDefaultValue || defaultValue is T);
if (defaultValue == Diagnostics.kNullDefaultValue) {
defaultValue = null;
}
D.assert(defaultValue == null || defaultValue == Diagnostics.kNoDefaultValue || defaultValue is T);
this._description = description;
this._valueComputed = true;

style: style
) {
defaultValue = defaultValue ?? Diagnostics.kNoDefaultValue;
D.assert(defaultValue == Diagnostics.kNoDefaultValue || defaultValue is T);
if (defaultValue == Diagnostics.kNullDefaultValue) {
defaultValue = null;
}
D.assert(defaultValue == null || defaultValue == Diagnostics.kNoDefaultValue || defaultValue is T);
this._value = null;
this._value = default(T);
this._computeValue = computeValue;
this._defaultLevel = level;
this.ifNull = ifNull ?? (missingIfNull ? "MISSING" : null);

var json = base.toJsonMap();
if (this.defaultValue != Diagnostics.kNoDefaultValue) {
json["defaultValue"] = this.defaultValue.ToString();
json["defaultValue"] = this.defaultValue == null ? "null" : this.defaultValue.ToString();
}
if (this.ifEmpty != null) {

}
catch (Exception ex) {
this._exception = ex;
this._value = null;
this._value = default(T);
}
}

return DiagnosticLevel.warning;
}
if (this.defaultValue != Diagnostics.kNoDefaultValue && this.value == this.defaultValue) {
if (this.defaultValue != Diagnostics.kNoDefaultValue && object.Equals(this.value, this.defaultValue)) {
return DiagnosticLevel.fine;
}

}
public class DiagnosticPropertiesBuilder {
void add(DiagnosticsNode property) {
public void add(DiagnosticsNode property) {
this.properties.Add(property);
}

);
}
public virtual void debugFillProperties(DiagnosticPropertiesBuilder properties) {
protected internal virtual void debugFillProperties(DiagnosticPropertiesBuilder properties) {
protected DiagnosticableTree() {
}
public string toStringShallow(
String joiner = ", ",
DiagnosticLevel minLevel = DiagnosticLevel.debug

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

);
internal static readonly _NoDefaultValue kNoDefaultValue = new _NoDefaultValue();
internal static readonly _NoDefaultValue kNullDefaultValue = new _NoDefaultValue();
public static string shortHash(object o) {
return (o.GetHashCode() & 0xFFFFF).ToString("X").PadLeft(5, '0');

57
Assets/UIWidgets/foundation/node.cs


namespace UIWidgets.foundation {
public class AbstractNode {
public int depth {
get { return this._depth; }
}
public int _depth = 0;
public void redepthChild(AbstractNode child) {
if (child._depth <= this._depth) {
child._depth = this._depth + 1;
child.redepthChildren();
}
}
public virtual void redepthChildren() {
}
public object owner {
get { return this._owner; }
}
public object _owner;
public bool attached {
get { return this._owner != null; }
}
public virtual void attach(object owner) {
this._owner = owner;
}
public virtual void detach() {
this._owner = null;
}
public AbstractNode parent {
get { return this._parent; }
}
public AbstractNode _parent;
public virtual void adoptChild(AbstractNode child) {
child._parent = this;
if (this.attached) {
child.attach(this._owner);
}
this.redepthChild(child);
}
public virtual void dropChild(AbstractNode child) {
child._parent = null;
if (this.attached) {
child.detach();
}
}
}
}

11
Assets/UIWidgets/gestures/binding.cs


namespace UIWidgets.gestures {
public class GestureBinding : HitTestable, HitTestDispatcher, HitTestTarget {
public GestureBinding(Window window) {
public GestureBinding(Window window, HitTestable hitTestable = null) {
this._hitTestable = hitTestable;
readonly HitTestable _hitTestable;
void _handlePointerDataPacket(PointerDataPacket packet) {
foreach (var pointerEvent in PointerEventConverter.expand(packet.data)) {
this._pendingPointerEvents.Enqueue(pointerEvent);

if (evt is PointerDownEvent) {
D.assert(!this._hitTests.ContainsKey(evt.pointer));
result = new HitTestResult();
if (this._hitTestable != null) {
this._hitTestable.hitTest(result, evt.position);
}
this._hitTests[evt.pointer] = result;
D.assert(() => {
if (D.debugPrintHitTestResults) {

78
Assets/UIWidgets/gestures/events.cs


int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null,
Offset delta = null,
bool down = false,
bool synthesized = false)
Offset position = null)
pointer,
kind,
device,
position,
delta,
down,
synthesized) {
pointer: pointer,
kind: kind,
device: device,
position: position,
down: true) {
public class PointerUpEvent : PointerEvent {
public PointerUpEvent(
public class PointerMoveEvent : PointerEvent {
public PointerMoveEvent(
DateTime timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,

bool down = false,
pointer,
kind,
device,
position,
delta,
down,
synthesized) {
pointer: pointer,
kind: kind,
device: device,
position: position,
delta: delta,
down: true,
synthesized: synthesized) {
public class PointerCancelEvent : PointerEvent {
public PointerCancelEvent(
public class PointerUpEvent : PointerEvent {
public PointerUpEvent(
Offset position = null,
Offset delta = null,
bool down = false,
bool synthesized = false)
Offset position = null)
pointer,
kind,
device,
position,
delta,
down,
synthesized) {
pointer: pointer,
kind: kind,
device: device,
position: position,
down: false) {
public class PointerMoveEvent : PointerEvent {
public PointerMoveEvent(
public class PointerCancelEvent : PointerEvent {
public PointerCancelEvent(
Offset position = null,
Offset delta = null,
bool down = false,
bool synthesized = false)
Offset position = null)
pointer,
kind,
device,
position,
delta,
down,
synthesized) {
pointer: pointer,
kind: kind,
device: device,
position: position,
down: false) {
}
}
}

25
Assets/UIWidgets/rendering/binding.cs


using System;
using UIWidgets.foundation;
using UIWidgets.gestures;
public class RendererBinding {
public class RendererBinding : HitTestable {
public RendererBinding(Window window, SchedulerBinding schedulerBinding) {
this._window = window;

public void _handlePersistentFrameCallback(TimeSpan timeStamp) {
this.drawFrame();
}
public void hitTest(HitTestResult result, Offset position) {
D.assert(this.renderView != null);
this.renderView.hitTest(result, position: position);
}
public void drawFrame() {
this.pipelineOwner.flushLayout();

public class RendererBindings {
public RendererBindings(Window window) {
this._window = window;
this._schedulerBinding = new SchedulerBinding(window);
this._rendererBinding = new RendererBinding(window, this._schedulerBinding);
this.window = window;
this.schedulerBinding = new SchedulerBinding(window);
this.rendererBinding = new RendererBinding(window, this.schedulerBinding);
this.gestureBinding = new GestureBinding(window, this.rendererBinding);
public readonly Window _window;
public readonly RendererBinding _rendererBinding;
public readonly SchedulerBinding _schedulerBinding;
public readonly Window window;
public readonly RendererBinding rendererBinding;
public readonly SchedulerBinding schedulerBinding;
public readonly GestureBinding gestureBinding;
this._rendererBinding.renderView.child = root;
this.rendererBinding.renderView.child = root;
}
}
}

22
Assets/UIWidgets/rendering/box.cs


public override Rect paintBounds {
get { return Offset.zero & this.size; }
}
int _debugActivePointers = 0;
protected bool debugHandleEvent(PointerEvent evt, HitTestEntry entry) {
D.assert(() =>{
if (D.debugPaintPointersEnabled) {
if (evt is PointerDownEvent) {
this._debugActivePointers += 1;
} else if (evt is PointerUpEvent || evt is PointerCancelEvent) {
this._debugActivePointers -= 1;
}
this.markNeedsPaint();
}
return true;
});
return true;
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Size>("size", this._size, missingIfNull: true));
}
}
public abstract class

33
Assets/UIWidgets/rendering/object.cs


}
}
public AbstractNode rootNode {
public AbstractNodeMixinDiagnosticableTree rootNode {
get { return this._rootNode; }
set {
if (this._rootNode == value) {

}
}
public AbstractNode _rootNode;
public AbstractNodeMixinDiagnosticableTree _rootNode;
public List<RenderObject> _nodesNeedingLayout = new List<RenderObject>();

ChildType nextSibling { get; set; }
}
public abstract class RenderObject : AbstractNode, HitTestTarget {
public abstract class RenderObject : AbstractNodeMixinDiagnosticableTree, HitTestTarget {
protected RenderObject() {
this._needsCompositing = this.isRepaintBoundary || this.alwaysNeedsCompositing;
}

}
}
public override void adoptChild(AbstractNode childNode) {
protected override void adoptChild(AbstractNodeMixinDiagnosticableTree childNode) {
var child = (RenderObject) childNode;
this.setupParentData(child);
base.adoptChild(child);

public override void dropChild(AbstractNode childNode) {
protected override void dropChild(AbstractNodeMixinDiagnosticableTree childNode) {
var child = (RenderObject) childNode;
child._cleanRelayoutBoundary();
child.parentData.detach();

public virtual void visitChildren(RenderObjectVisitor visitor) {
}
public object debugCreator;
public bool debugCanParentUseSize {
get { return this._debugCanParentUseSize; }
}
bool _debugCanParentUseSize;
public new PipelineOwner owner {
get { return (PipelineOwner) base.owner; }

}
public void _skippedPaintingOnLayer() {
AbstractNode ancestor = this.parent;
var ancestor = this.parent;
while (ancestor is RenderObject) {
var node = (RenderObject) ancestor;
if (node.isRepaintBoundary) {

public Matrix4x4 getTransformTo(RenderObject ancestor) {
if (ancestor == null) {
AbstractNode rootNode = this.owner.rootNode;
var rootNode = this.owner.rootNode;
if (rootNode is RenderObject) {
ancestor = (RenderObject) rootNode;
}

}
public virtual void handleEvent(PointerEvent evt, HitTestEntry entry) {
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
properties.add(new DiagnosticsProperty<object>(
"creator", this.debugCreator, defaultValue: Diagnostics.kNullDefaultValue,
level: DiagnosticLevel.debug));
properties.add(new DiagnosticsProperty<ParentData>("parentData", this.parentData,
tooltip: this._debugCanParentUseSize ? "can use size" : null, missingIfNull: true));
properties.add(new DiagnosticsProperty<Constraints>("constraints", this.constraints, missingIfNull: true));
properties.add(new DiagnosticsProperty<OffsetLayer>("layer", this._layer,
defaultValue: Diagnostics.kNullDefaultValue));
}
}
}

92
Assets/UIWidgets/rendering/proxy_box.cs


using UIWidgets.gestures;
using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.ui;
using UnityEngine;

}
public abstract class RenderProxyBoxWithHitTestBehavior : RenderProxyBox {
RenderProxyBoxWithHitTestBehavior(
protected RenderProxyBoxWithHitTestBehavior(
HitTestBehavior behavior = HitTestBehavior.deferToChild,
RenderBox child = null
) : base(child) {

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

if (this.position == DecorationPosition.foreground) {
this._painter.paint(context.canvas, offset, filledConfiguration);
}
}
}
public delegate void PointerDownEventListener(PointerDownEvent evt);
public delegate void PointerMoveEventListener(PointerMoveEvent evt);
public delegate void PointerUpEventListener(PointerUpEvent evt);
public delegate void PointerCancelEventListener(PointerCancelEvent evt);
public class RenderPointerListener : RenderProxyBoxWithHitTestBehavior {
public RenderPointerListener(
PointerDownEventListener onPointerDown = null,
PointerMoveEventListener onPointerMove = null,
PointerUpEventListener onPointerUp = null,
PointerCancelEventListener onPointerCancel = null,
HitTestBehavior behavior = HitTestBehavior.deferToChild,
RenderBox child = null
) : base(behavior: behavior, child: child) {
this.onPointerDown = onPointerDown;
this.onPointerMove = onPointerMove;
this.onPointerUp = onPointerUp;
this.onPointerCancel = onPointerCancel;
}
public PointerDownEventListener onPointerDown;
public PointerMoveEventListener onPointerMove;
public PointerUpEventListener onPointerUp;
public PointerCancelEventListener onPointerCancel;
public override void performResize() {
this.size = this.constraints.biggest;
}
public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
D.assert(this.debugHandleEvent(evt, entry));
if (this.onPointerDown != null && evt is PointerDownEvent) {
this.onPointerDown((PointerDownEvent) evt);
return;
}
if (this.onPointerMove != null && evt is PointerMoveEvent) {
this.onPointerMove((PointerMoveEvent) evt);
return;
}
if (this.onPointerUp != null && evt is PointerUpEvent) {
this.onPointerUp((PointerUpEvent) evt);
return;
}
if (this.onPointerCancel != null && evt is PointerCancelEvent) {
this.onPointerCancel((PointerCancelEvent) evt);
return;
}
}
protected internal override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
var listeners = new List<string>();
if (this.onPointerDown != null)
listeners.Add("down");
if (this.onPointerMove != null)
listeners.Add("move");
if (this.onPointerUp != null)
listeners.Add("up");
if (this.onPointerCancel != null)
listeners.Add("cancel");
if (listeners.isEmpty()) {
listeners.Add("<none>");
}
properties.add(new EnumerableProperty<string>("listeners", listeners));
}
}
}

2
Assets/UIWidgets/rendering/sliver_multi_box_adaptor.cs


public readonly Dictionary<int, RenderBox> _keepAliveBucket = new Dictionary<int, RenderBox>();
public override void adoptChild(AbstractNode childNode) {
protected override void adoptChild(AbstractNodeMixinDiagnosticableTree childNode) {
base.adoptChild(childNode);
var child = (RenderBox) childNode;
var childParentData = (SliverMultiBoxAdaptorParentData) child.parentData;

90
Assets/UIWidgets/Tests/Gestures.cs


using System;
using System.Linq;
using UIWidgets.editor;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.rendering;
using UIWidgets.ui;
using UnityEditor;
using UnityEngine;
using Color=UIWidgets.ui.Color;
namespace UIWidgets.Tests {
public class Gestures : EditorWindow {
private readonly Func<RenderBox>[] _options;
private readonly string[] _optionStrings;
private int _selected;
Gestures() {
this._options = new Func<RenderBox>[] {
this.tap,
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;
this.titleContent = new GUIContent("Gestures");
}
private WindowAdapter windowAdapter;
private RendererBindings rendererBindings;
[NonSerialized] private bool hasInvoked = false;
void OnGUI() {
var selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings);
if (selected != this._selected || !this.hasInvoked) {
this._selected = selected;
this.hasInvoked = true;
var renderBox = this._options[this._selected]();
this.rendererBindings.setRoot(renderBox);
}
if (this.windowAdapter != null) {
this.windowAdapter.OnGUI();
}
}
void Update() {
if (this.windowAdapter != null) {
this.windowAdapter.Update();
}
}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
this.rendererBindings = new RendererBindings(this.windowAdapter);
this._tapRecognizer = new TapGestureRecognizer(this.rendererBindings.gestureBinding);
this._tapRecognizer.onTap = () => { Debug.Log("tap"); };
}
void OnDestroy() {
this.windowAdapter = null;
this.rendererBindings = null;
}
TapGestureRecognizer _tapRecognizer;
void _handlePointerDown(PointerDownEvent evt) {
this._tapRecognizer.addPointer(evt);
}
RenderBox tap() {
return new RenderPointerListener(
onPointerDown: this._handlePointerDown,
behavior: HitTestBehavior.opaque,
child: new RenderConstrainedBox(
additionalConstraints: BoxConstraints.tight(Size.square(100)),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
color: new Color(0xFF00FF00)
)
))
);
}
}
}

3
Assets/UIWidgets/Tests/Gestures.cs.meta


fileFormatVersion: 2
guid: b6e93a3e08aa4ed49ebe367645f04fd9
timeCreated: 1536304600

163
Assets/UIWidgets/foundation/node.mixin.gen.cs


namespace UIWidgets.foundation {
public class AbstractNode {
public int depth {
get { return this._depth; }
}
int _depth = 0;
protected void redepthChild(AbstractNode child) {
D.assert(child.owner == this.owner);
if (child._depth <= this._depth) {
child._depth = this._depth + 1;
child.redepthChildren();
}
}
public virtual void redepthChildren() {
}
public object owner {
get { return this._owner; }
}
object _owner;
public bool attached {
get { return this._owner != null; }
}
public virtual void attach(object owner) {
D.assert(owner != null);
D.assert(this._owner == null);
this._owner = owner;
}
public virtual void detach() {
D.assert(this._owner != null);
this._owner = null;
}
public AbstractNode parent {
get { return this._parent; }
}
AbstractNode _parent;
protected virtual void adoptChild(AbstractNode child) {
D.assert(child != null);
D.assert(child._parent == null);
D.assert(() => {
var node = this;
while (node.parent != null)
node = node.parent;
D.assert(node != child); // indicates we are about to create a cycle
return true;
});
child._parent = this;
if (this.attached) {
child.attach(this._owner);
}
this.redepthChild(child);
}
protected virtual void dropChild(AbstractNode child) {
D.assert(child != null);
D.assert(child._parent == this);
D.assert(child.attached == this.attached);
child._parent = null;
if (this.attached) {
child.detach();
}
}
}
public class AbstractNodeMixinDiagnosticableTree : DiagnosticableTree {
public int depth {
get { return this._depth; }
}
int _depth = 0;
protected void redepthChild(AbstractNodeMixinDiagnosticableTree child) {
D.assert(child.owner == this.owner);
if (child._depth <= this._depth) {
child._depth = this._depth + 1;
child.redepthChildren();
}
}
public virtual void redepthChildren() {
}
public object owner {
get { return this._owner; }
}
object _owner;
public bool attached {
get { return this._owner != null; }
}
public virtual void attach(object owner) {
D.assert(owner != null);
D.assert(this._owner == null);
this._owner = owner;
}
public virtual void detach() {
D.assert(this._owner != null);
this._owner = null;
}
public AbstractNodeMixinDiagnosticableTree parent {
get { return this._parent; }
}
AbstractNodeMixinDiagnosticableTree _parent;
protected virtual void adoptChild(AbstractNodeMixinDiagnosticableTree child) {
D.assert(child != null);
D.assert(child._parent == null);
D.assert(() => {
var node = this;
while (node.parent != null)
node = node.parent;
D.assert(node != child); // indicates we are about to create a cycle
return true;
});
child._parent = this;
if (this.attached) {
child.attach(this._owner);
}
this.redepthChild(child);
}
protected virtual void dropChild(AbstractNodeMixinDiagnosticableTree child) {
D.assert(child != null);
D.assert(child._parent == this);
D.assert(child.attached == this.attached);
child._parent = null;
if (this.attached) {
child.detach();
}
}
}
}

11
Assets/UIWidgets/foundation/node.mixin.gen.cs.meta


fileFormatVersion: 2
guid: b7a18c2b3beb04ccba0b8585c1cdb618
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

88
Assets/UIWidgets/foundation/node.mixin.njk


namespace UIWidgets.foundation {
{% macro AbstractNodeMixin(with) %}
{% set className = 'AbstractNode' if with == '' else 'AbstractNodeMixin' + with %}
{% set extends = '' if with == '' else ' : ' + with %}
public class {{className}} {{extends}} {
public int depth {
get { return this._depth; }
}
int _depth = 0;
protected void redepthChild({{className}} child) {
D.assert(child.owner == this.owner);
if (child._depth <= this._depth) {
child._depth = this._depth + 1;
child.redepthChildren();
}
}
public virtual void redepthChildren() {
}
public object owner {
get { return this._owner; }
}
object _owner;
public bool attached {
get { return this._owner != null; }
}
public virtual void attach(object owner) {
D.assert(owner != null);
D.assert(this._owner == null);
this._owner = owner;
}
public virtual void detach() {
D.assert(this._owner != null);
this._owner = null;
}
public {{className}} parent {
get { return this._parent; }
}
{{className}} _parent;
protected virtual void adoptChild({{className}} child) {
D.assert(child != null);
D.assert(child._parent == null);
D.assert(() => {
var node = this;
while (node.parent != null)
node = node.parent;
D.assert(node != child); // indicates we are about to create a cycle
return true;
});
child._parent = this;
if (this.attached) {
child.attach(this._owner);
}
this.redepthChild(child);
}
protected virtual void dropChild({{className}} child) {
D.assert(child != null);
D.assert(child._parent == this);
D.assert(child.attached == this.attached);
child._parent = null;
if (this.attached) {
child.detach();
}
}
}
{% endmacro %}
{{ AbstractNodeMixin('') }}
{{ AbstractNodeMixin('DiagnosticableTree') }}
}

3
Assets/UIWidgets/foundation/node.mixin.njk.meta


fileFormatVersion: 2
guid: 3169ab76e1bc45cf92b23f07f2688b62
timeCreated: 1536301833
正在加载...
取消
保存