浏览代码

fix a bug in flutter + reimport support to textSpan-level hoverrecognizer

/main
xingwei.zhu 6 年前
当前提交
35cd9ca1
共有 2 个文件被更改,包括 100 次插入59 次删除
  1. 99
      Runtime/rendering/paragraph.cs
  2. 60
      Runtime/rendering/proxy_box.cs

99
Runtime/rendering/paragraph.cs


return;
case RenderComparison.function:
this._textPainter.text = value;
this.markNeedsPaint();
break;
case RenderComparison.paint:
this._textPainter.text = value;

TextSpan _previousHoverSpan;
bool _pointerHoverInside;
bool _hasHoverRecognizer;
MouseTrackerAnnotation _hoverAnnotation;
if (this._hoverAnnotation != null && this.attached) {
RendererBinding.instance.mouseTracker.detachAnnotation(this._hoverAnnotation);
}
if (this._hasHoverRecognizer) {
this._hoverAnnotation = new MouseTrackerAnnotation(
onEnter: this._onPointerEnter,
onHover: this._onPointerHover,
onExit: this._onPointerExit);
if (this.attached) {
RendererBinding.instance.mouseTracker.attachAnnotation(this._hoverAnnotation);
}
}
else {
this._hoverAnnotation = null;
}
}
void _handleKeyEvent(RawKeyEvent keyEvent) {

}
}
public override void attach(object owner) {
base.attach(owner);
if (this._hoverAnnotation != null) {
RendererBinding.instance.mouseTracker.attachAnnotation(this._hoverAnnotation);
}
}
public override void detach() {
if (this._listenerAttached) {
RawKeyboard.instance.removeListener(this._handleKeyEvent);

if (this._hoverAnnotation != null) {
RendererBinding.instance.mouseTracker.detachAnnotation(this._hoverAnnotation);
}
}
TextSelection _selection;

this.onSelectionChanged?.Invoke();
}
void _onPointerEnter(PointerEvent evt) {
this._pointerHoverInside = true;
}
void _handlePointerHover(PointerEvent evt) {
if (!this._hasHoverRecognizer) {
return;
}
void _onPointerExit(PointerEvent evt) {
this._pointerHoverInside = false;
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave?.Invoke();
this._previousHoverSpan = null;
}
if (evt is PointerEnterEvent) {
this._pointerHoverInside = true;
}
else if (evt is PointerExitEvent) {
this._pointerHoverInside = false;
void _onPointerHover(PointerEvent evt) {
this._layoutTextWithConstraints(this.constraints);
Offset offset = this.globalToLocal(evt.position);
TextPosition position = this._textPainter.getPositionForOffset(offset);
TextSpan span = this._textPainter.text.getSpanForPosition(position);
if (this._previousHoverSpan != span) {
this._previousHoverSpan = null;
}
else if (evt is PointerHoverEvent && this._pointerHoverInside) {
this._layoutTextWithConstraints(this.constraints);
Offset offset = this.globalToLocal(evt.position);
TextPosition position = this._textPainter.getPositionForOffset(offset);
TextSpan span = this._textPainter.text.getSpanForPosition(position);
if (this._previousHoverSpan != span) {
this._previousHoverSpan?.hoverRecognizer?.OnPointerLeave?.Invoke();
span?.hoverRecognizer?.OnPointerEnter?.Invoke((PointerHoverEvent) evt);
this._previousHoverSpan = span;
}
span?.hoverRecognizer?.OnPointerEnter?.Invoke((PointerHoverEvent) evt);
this._previousHoverSpan = span;
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 (!(evt is PointerDownEvent)) {
this._handlePointerHover(evt);
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);
}
protected override void performLayout() {

this._selectionRects = null;
}
public override void paint(PaintingContext context, Offset offset) {
void paintParagraph(PaintingContext context, Offset offset) {
this._layoutTextWithConstraints(this.constraints);
var canvas = context.canvas;

this._textPainter.paint(canvas, offset);
if (this._hasVisualOverflow) {
canvas.restore();
}
}
public override void paint(PaintingContext context, Offset offset) {
if (this._hoverAnnotation != null) {
AnnotatedRegionLayer<MouseTrackerAnnotation> layer = new AnnotatedRegionLayer<MouseTrackerAnnotation>(
this._hoverAnnotation, size: this.size, offset: offset);
context.pushLayer(layer, this.paintParagraph, offset);
}
else {
this.paintParagraph(context, offset);
}
}

60
Runtime/rendering/proxy_box.cs


using System;
using System.Collections.Generic;
using System.Collections.Generic;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;

return base.hitTest(result, position: position);
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();

return base.hitTest(result, position: position);
}
public override void paint(PaintingContext context, Offset offset) {
if (this.child != null) {
this._updateClip();

}
else {
Canvas canvas = context.canvas;
if (this.elevation != 0.0) {
canvas.drawRect(
offsetBounds.inflate(20.0f),
_transparentPaint
);
canvas.drawShadow(
offsetPath,
this.shadowColor,
this.elevation,
this.color.alpha != 0xFF
);
}
if (this.elevation != 0.0) {
canvas.drawRect(
offsetBounds.inflate(20.0f),
_transparentPaint
);
canvas.drawShadow(
offsetPath,
this.shadowColor,
this.elevation,
this.color.alpha != 0xFF
);
}
Paint paint = new Paint {color = this.color, style = PaintingStyle.fill};
canvas.drawPath(offsetPath, paint);
context.clipPathAndPaint(offsetPath, this.clipBehavior,

}
}
}
PointerEnterEventListener _onPointerEnter;
public PointerHoverEventListener onPointerHover {

}
}
}
PointerHoverEventListener _onPointerHover;
public PointerExitEventListener onPointerExit {

}
}
}
PointerExitEventListener _onPointerExit;
public PointerUpEventListener onPointerUp;

MouseTrackerAnnotation _hoverAnnotation;
void _updateAnnotations() {
D.assert(this._onPointerEnter != this._hoverAnnotation.onEnter ||
D.assert(this._onPointerEnter != this._hoverAnnotation.onEnter ||
if (this._onPointerEnter != null || this._onPointerHover != null || this._onPointerExit != null)
{
if (this._onPointerEnter != null || this._onPointerHover != null || this._onPointerExit != null) {
this._hoverAnnotation = new MouseTrackerAnnotation(
onEnter: this._onPointerEnter,
onHover: this._onPointerHover,

else {
this._hoverAnnotation = null;
}
public override void attach(Object owner) {
public override void attach(object owner) {
base.attach(owner);
if (this._hoverAnnotation != null) {
RendererBinding.instance.mouseTracker.attachAnnotation(this._hoverAnnotation);

if (this._hoverAnnotation != null) {
AnnotatedRegionLayer<MouseTrackerAnnotation> layer = new AnnotatedRegionLayer<MouseTrackerAnnotation>(
this._hoverAnnotation, size: this.size, offset: offset);
base.paint(context, offset);
else {
base.paint(context, offset);
}
}
protected override void performResize() {

public override void paint(PaintingContext context, Offset offset) {
AnnotatedRegionLayer<T> layer =
new AnnotatedRegionLayer<T>(
value: this.value,
value: this.value,
context.pushLayer(layer, base.paint, offset);
}
}
正在加载...
取消
保存