浏览代码

add diagnostics.

/main
kg 6 年前
当前提交
039631a5
共有 12 个文件被更改,包括 1228 次插入17 次删除
  1. 9
      Assets/UIWidgets/foundation/basic_types.cs
  2. 8
      Assets/UIWidgets/foundation/debug.cs
  3. 14
      Assets/UIWidgets/gestures/hit_test.cs
  4. 51
      Assets/UIWidgets/rendering/box.cs
  5. 9
      Assets/UIWidgets/rendering/object.cs
  6. 38
      Assets/UIWidgets/rendering/proxy_box.cs
  7. 10
      Assets/UIWidgets/rendering/view.cs
  8. 4
      Assets/UIWidgets/ui/geometry.cs
  9. 1001
      Assets/UIWidgets/foundation/diagnostics.cs
  10. 3
      Assets/UIWidgets/foundation/diagnostics.cs.meta
  11. 95
      Assets/UIWidgets/foundation/print.cs
  12. 3
      Assets/UIWidgets/foundation/print.cs.meta

9
Assets/UIWidgets/foundation/basic_types.cs


public static bool isNotEmpty<TKey, TValue>(this IDictionary<TKey, TValue> it) {
return it.Count != 0;
}
public static bool isEmpty(this string it) {
return string.IsNullOrEmpty(it);
}
public static bool isNotEmpty(this string it) {
return !string.IsNullOrEmpty(it);
}
}
}

8
Assets/UIWidgets/foundation/debug.cs


namespace UIWidgets.foundation {
public static class D {
[Conditional("UIWidgets_DEBUG")]
public static void assert(Func<bool> result) {
D.assert(result());
public static void assert(Func<bool> result, string message = null) {
D.assert(result(), message);
public static void assert(bool result) {
public static void assert(bool result, string message = null) {
throw new Exception("assertion failed. check stacktrace.");
throw new Exception(message ?? "assertion failed.");
}
}

14
Assets/UIWidgets/gestures/hit_test.cs


}
public interface HitTestDispatcher {
void dispatchEvent(PointerEvent @event, HitTestResult result);
void dispatchEvent(PointerEvent evt, HitTestResult result);
void handleEvent(PointerEvent @event, HitTestEntry entry);
void handleEvent(PointerEvent evt, HitTestEntry entry);
this.target = target;
this._target = target;
public readonly HitTestTarget target;
public virtual HitTestTarget target {
get { return this._target; }
}
readonly HitTestTarget _target;
return this.target.ToString();
return this._target.ToString();
}
}

51
Assets/UIWidgets/rendering/box.cs


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

}
}
public class BoxHitTestEntry : HitTestEntry {
public BoxHitTestEntry(RenderBox target, Offset localPosition)
: base(target) {
D.assert(localPosition != null);
this.localPosition = localPosition;
}
public new RenderBox target {
get { return (RenderBox) base.target; }
}
public readonly Offset localPosition;
public override string ToString() {
return string.Format("{0}@{1}",
Diagnostics.describeIdentity(this.target), this.localPosition);
}
}
public class BoxParentData : ParentData {
public Offset offset = Offset.zero;
}

public override void performLayout() {
}
public virtual bool hitTest(HitTestResult result, Offset position) {
D.assert(() => {
if (!this.hasSize) {
throw new Exception("has no size during hitTest");
}
return true;
});
if (this._size.contains(position)) {
if (this.hitTestChildren(result, position: position) || this.hitTestSelf(position)) {
result.add(new BoxHitTestEntry(this, position));
return true;
}
}
return false;
}
protected virtual bool hitTestSelf(Offset position) {
return false;
}
protected bool hitTestChildren(HitTestResult result, Offset position = null) {
return false;
}
public override void applyPaintTransform(RenderObject child, ref Matrix4x4 transform) {
var childParentData = (BoxParentData) child.parentData;
var offset = childParentData.offset;

candidate += childParentData.offset.dy;
if (result != null) {
result = Math.Min(result.Value, candidate.Value);
}
else {
} else {
result = candidate;
}
}

9
Assets/UIWidgets/rendering/object.cs


using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UIWidgets.gestures;
using UnityEditor.Rendering;
using UnityEngine.XR.WSA.Persistence;
using Canvas = UIWidgets.ui.Canvas;
using Rect = UIWidgets.ui.Rect;

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

}
return transform;
}
public virtual void handleEvent(PointerEvent evt, HitTestEntry entry) {
}
}
}

38
Assets/UIWidgets/rendering/proxy_box.cs


using UIWidgets.painting;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.ui;
using UnityEngine;

this.child = child;
}
}
public enum HitTestBehavior {
deferToChild,
opaque,
translucent,
}
public abstract class RenderProxyBoxWithHitTestBehavior : RenderProxyBox {
RenderProxyBoxWithHitTestBehavior(
HitTestBehavior behavior = HitTestBehavior.deferToChild,
RenderBox child = null
) : base(child) {
this.behavior = behavior;
}
public HitTestBehavior behavior;
public override bool hitTest(HitTestResult result, Offset position = null) {
bool hitTarget = false;
if (this.size.contains(position)) {
hitTarget = this.hitTestChildren(result, position: position) || this.hitTestSelf(position);
if (hitTarget || this.behavior == HitTestBehavior.translucent) {
result.add(new BoxHitTestEntry(this, position));
}
}
return hitTarget;
}
public override bool hitTestSelf(Offset position) {
return this.behavior == HitTestBehavior.opaque;
}
}

background,
foreground,
}
public class RenderDecoratedBox : RenderProxyBox {
public RenderDecoratedBox(
Decoration decoration,

10
Assets/UIWidgets/rendering/view.cs


using System;
using UIWidgets.gestures;
using UIWidgets.ui;
using UnityEngine;
using Rect = UIWidgets.ui.Rect;

if (this.child != null) {
this.child.layout(BoxConstraints.tight(this._size));
}
}
public bool hitTest(HitTestResult result, Offset position = null) {
if (this.child != null) {
this.child.hitTest(result, position: position);
}
result.add(new HitTestEntry(this));
return true;
}
public override bool isRepaintBoundary {

4
Assets/UIWidgets/ui/geometry.cs


get { return Math.Max(Math.Abs(this.width), Math.Abs(this.height)); }
}
public bool contains(Offset offset) {
return offset.dx >= 0.0 && offset.dx < this.width && offset.dy >= 0.0 && offset.dy < this.height;
}
public bool Equals(Size other) {
return this._dx.Equals(other._dx) && this._dy.Equals(other._dy);
}

1001
Assets/UIWidgets/foundation/diagnostics.cs
文件差异内容过多而无法显示
查看文件

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


fileFormatVersion: 2
guid: 16aaa3f0f74a4188b49c27f602b4341d
timeCreated: 1536203150

95
Assets/UIWidgets/foundation/print.cs


using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace UIWidgets.foundation {
enum _WordWrapParseMode {
inSpace,
inWord,
atBreak
}
public static class DebugPrint {
static readonly Regex _indentPattern = new Regex("^ *(?:[-+*] |[0-9]+[.):] )?");
public static IEnumerable<string> debugWordWrap(string message, int width, string wrapIndent = "") {
if (message.Length < width || message.TrimStart()[0] == '#') {
yield return message;
yield break;
}
Match prefixMatch = _indentPattern.Match(message);
string prefix = wrapIndent + new string(' ', prefixMatch.Groups[0].Value.Length);
int start = 0;
int startForLengthCalculations = 0;
bool addPrefix = false;
int index = prefix.Length;
_WordWrapParseMode mode = _WordWrapParseMode.inSpace;
int lastWordStart = 0;
int? lastWordEnd = null;
while (true) {
switch (mode) {
case _WordWrapParseMode.inSpace:
// at start of break point (or start of line); can"t break until next break
while ((index < message.Length) && (message[index] == ' ')) {
index += 1;
}
lastWordStart = index;
mode = _WordWrapParseMode.inWord;
break;
case _WordWrapParseMode.inWord: // looking for a good break point
while ((index < message.Length) && (message[index] != ' ')) {
index += 1;
}
mode = _WordWrapParseMode.atBreak;
break;
case _WordWrapParseMode.atBreak: // at start of break point
if ((index - startForLengthCalculations > width) || (index == message.Length)) {
// we are over the width line, so break
if ((index - startForLengthCalculations <= width) || (lastWordEnd == null)) {
// we should use this point, because either it doesn"t actually go over the
// end (last line), or it does, but there was no earlier break point
lastWordEnd = index;
}
if (addPrefix) {
yield return prefix + message.Substring(start, lastWordEnd.Value - start);
} else {
yield return message.Substring(start, lastWordEnd.Value - start);
addPrefix = true;
}
if (lastWordEnd >= message.Length)
yield break;
// just yield returned a line
if (lastWordEnd == index) {
// we broke at current position
// eat all the spaces, then set our start point
while ((index < message.Length) && (message[index] == ' '))
index += 1;
start = index;
mode = _WordWrapParseMode.inWord;
} else {
// we broke at the previous break point, and we"re at the start of a new one
D.assert(lastWordStart > lastWordEnd);
start = lastWordStart;
mode = _WordWrapParseMode.atBreak;
}
startForLengthCalculations = start - prefix.Length;
D.assert(addPrefix);
lastWordEnd = null;
} else {
// save this break point, we"re not yet over the line width
lastWordEnd = index;
// skip to the end of this break point
mode = _WordWrapParseMode.inSpace;
}
break;
}
}
}
}
}

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


fileFormatVersion: 2
guid: 3c7a659f877d47afae10826010956757
timeCreated: 1536214859
正在加载...
取消
保存