浏览代码

refine code

/main
xingwei.zhu 6 年前
当前提交
7f02481a
共有 7 个文件被更改,包括 50 次插入40 次删除
  1. 6
      Runtime/gestures/binding.cs
  2. 10
      Runtime/gestures/hover.cs
  3. 2
      Runtime/painting/basic_types.cs
  4. 5
      Runtime/painting/text_span.cs
  5. 63
      Runtime/rendering/paragraph.cs
  6. 2
      Samples/UIWidgetSample/MaterialSample.cs
  7. 2
      Samples/UIWidgetSample/txt/TextSpanGesture.cs

6
Runtime/gestures/binding.cs


timeStamp: evt.timeStamp,
pointer: evt.pointer,
device: evt.device,
kind: evt.kind,
position: evt.position
kind: evt.kind
), null);
}

timeStamp: evt.timeStamp,
pointer: evt.pointer,
device: evt.device,
kind: evt.kind,
position: evt.position
kind: evt.kind
), hitTestEntry);
}

10
Runtime/gestures/hover.cs


namespace Unity.UIWidgets.gestures {
public delegate void PointerHoverEnterCallback(PointerHoverEvent evt);
public delegate void PointerHoverLeaveCallback();
public class HoverRecognizer : DiagnosticableTree {
public HoverRecognizer(object debugOwner = null) {
this.debugOwner = debugOwner;

public Action OnPointerEnter = () => {};
public PointerHoverEnterCallback OnPointerEnter;
public Action OnPointerLeave = () => {};
public PointerHoverLeaveCallback OnPointerLeave;
}
}

2
Runtime/painting/basic_types.cs


public enum RenderComparison {
identical,
metadata,
hoverCallback,
function,
paint,
layout,
}

5
Runtime/painting/text_span.cs


}
}
public bool needHoverRecognizer {
public bool hasHoverRecognizer {
get {
bool need = false;
this.visitTextSpan((text) => {

}
return true;
});
return need;
}
}

: RenderComparison.metadata;
if (!Equals(this.recognizer, other.recognizer)) {
result = RenderComparison.hoverCallback > result ? RenderComparison.hoverCallback : result;
result = RenderComparison.function > result ? RenderComparison.function : result;
}
if (this.style != null) {

63
Runtime/rendering/paragraph.cs


this._selection = null;
this.onSelectionChanged = onSelectionChanged;
this.selectionColor = selectionColor;
this._listenToHoverEvent = this._textPainter.text.needHoverRecognizer;
this._previousHoverSpan = null;
this._pointerHoverInside = false;
this._resetHoverHandler();
}
public Action onSelectionChanged;

case RenderComparison.identical:
case RenderComparison.metadata:
return;
case RenderComparison.hoverCallback:
case RenderComparison.function:
this._textPainter.text = value;
break;
case RenderComparison.paint:

break;
}
this._listenToHoverEvent = this._textPainter.text.needHoverRecognizer;
this._previousHoverSpan = null;
this._pointerHoverInside = false;
this._resetHoverHandler();
}
}

}
}
TextSpan _previousHoverSpan;
bool _pointerHoverInside;
bool _hasHoverRecognizer;
void _resetHoverHandler() {
this._hasHoverRecognizer = this._textPainter.text.hasHoverRecognizer;
this._previousHoverSpan = null;
this._pointerHoverInside = false;
}
void _handleKeyEvent(RawKeyEvent keyEvent) {
//only allow KCommand.copy
if (keyEvent is RawKeyUpEvent) {

this.onSelectionChanged?.Invoke();
}
TextSpan _previousHoverSpan = null;
bool _pointerHoverInside = false;
bool _listenToHoverEvent = false;
public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
D.assert(this.debugHandleEvent(evt, entry));
if (evt is PointerDownEvent) {
this._layoutTextWithConstraints(this.constraints);
Offset offset = ((BoxHitTestEntry) entry).localPosition;
TextPosition position = this._textPainter.getPositionForOffset(offset);
TextSpan span = this._textPainter.text.getSpanForPosition(position);
span?.recognizer?.addPointer((PointerDownEvent) evt);
}
if (!this._listenToHoverEvent) {
void _handlePointerHover(PointerEvent evt) {
if (!this._hasHoverRecognizer) {
} else if (evt is PointerLeaveEvent) {
}
else if (evt is PointerLeaveEvent) {
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave();
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave?.Invoke();
this._previousHoverSpan = null;
}
else if (evt is PointerHoverEvent && this._pointerHoverInside) {

TextSpan span = this._textPainter.text.getSpanForPosition(position);
if (this._previousHoverSpan != span) {
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave();
span?.hoverRecognizer?.OnPointerEnter();
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave?.Invoke();
span?.hoverRecognizer?.OnPointerEnter?.Invoke((PointerHoverEvent) evt);
}
public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
D.assert(this.debugHandleEvent(evt, entry));
if (evt is PointerDownEvent) {
this._layoutTextWithConstraints(this.constraints);
Offset offset = ((BoxHitTestEntry) entry).localPosition;
TextPosition position = this._textPainter.getPositionForOffset(offset);
TextSpan span = this._textPainter.text.getSpanForPosition(position);
span?.recognizer?.addPointer((PointerDownEvent) evt);
return;
}
this._handlePointerHover(evt);
}
protected override void performLayout() {

foreach (var box in this._selectionRects) {
barPath.addRect(box.toRect().shift(effectiveOffset));
}
canvas.drawPath(barPath, paint);
}

2
Samples/UIWidgetSample/MaterialSample.cs


Debug.Log("Tap");
};
this._hoverRecognizer = new HoverRecognizer();
this._hoverRecognizer.OnPointerEnter = () => { Debug.Log("Pointer Enter"); };
this._hoverRecognizer.OnPointerEnter = (evt) => { Debug.Log("Pointer Enter"); };
this._hoverRecognizer.OnPointerLeave = () => { Debug.Log("Pointer Leave"); };
}

2
Samples/UIWidgetSample/txt/TextSpanGesture.cs


Debug.Log("Tap");
};
this._hoverRecognizer = new HoverRecognizer();
this._hoverRecognizer.OnPointerEnter = () => { Debug.Log("Pointer Enter"); };
this._hoverRecognizer.OnPointerEnter = (evt) => { Debug.Log("Pointer Enter"); };
this._hoverRecognizer.OnPointerLeave = () => { Debug.Log("Pointer Leave"); };
}

正在加载...
取消
保存