浏览代码

[1.5.4] Upgrade editable.

/main
Yuncong Zhang 5 年前
当前提交
8a58b721
共有 5 个文件被更改,包括 107 次插入8 次删除
  1. 5
      Runtime/painting/text_painter.cs
  2. 1
      Runtime/rendering/binding.cs
  3. 4
      Runtime/rendering/box.cs
  4. 98
      Runtime/rendering/editable.cs
  5. 7
      Runtime/ui/window.cs

5
Runtime/painting/text_painter.cs


return this._caretMetrics.offset;
}
public float getFullHeightForCaret(TextPosition position, Rect caretPrototype) {
this._computeCaretMetrics(position, caretPrototype);
return this._caretMetrics.fullHeight ?? 0;
}
_CaretMetrics _caretMetrics;
TextPosition _previousCaretPosition;

1
Runtime/rendering/binding.cs


Window.instance.onMetricsChanged += this.handleMetricsChanged;
Window.instance.onTextScaleFactorChanged += this.handleTextScaleFactorChanged;
Window.instance.onPlatformBrightnessChanged += this.handlePlatformBrightnessChanged;
this.initRenderView();
D.assert(this.renderView != null);
this.addPersistentFrameCallback(this._handlePersistentFrameCallback);

4
Runtime/rendering/box.cs


if (this.constraints.hasBoundedWidth) {
testIntrinsicsForValues(this.getMinIntrinsicWidth, this.getMaxIntrinsicWidth, "Width",
this.constraints.maxWidth);
this.constraints.maxHeight);
this.constraints.maxHeight);
this.constraints.maxWidth);
}
debugCheckingIntrinsics = false;

98
Runtime/rendering/editable.cs


using System.Collections.Generic;
using System.Xml.Schema;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;

TextPainter _textPainter;
Color _cursorColor;
int? _maxLines;
int? _minLines;
bool _expands;
Color _selectionColor;
ViewportOffset _offset;
ValueNotifier<bool> _showCursor;

Color backgroundCursorColor = null,
bool? hasFocus = null,
int? maxLines = 1,
int? minLines = null,
bool expands = false,
StrutStyle strutStyle = null,
Color selectionColor = null,
TextSelection selection = null,

bool ignorePointer = false,
float cursorWidth = 1.0f,
Radius cursorRadius = null,
bool? enableInteractiveSelection = null,
bool? enableInteractiveSelection = null,
D.assert(minLines == null || minLines > 0);
D.assert((minLines == null) || maxLines >= minLines, () => "minLines can't be greater than maxLines");
this._textPainter = new TextPainter(text: text, textAlign: textAlign, textDirection: textDirection,
textScaleFactor: textScaleFactor, strutStyle: strutStyle);
this._cursorColor = cursorColor;

this._maxLines = maxLines;
this._minLines = minLines;
this._expands = expands;
this._selectionColor = selectionColor;
this._selection = selection;
this._obscureText = obscureText;

}
readonly ValueNotifier<bool> _selectionEndInViewport = new ValueNotifier<bool>(true);
void _updateSelectionExtentsVisibility(Offset effectiveOffset) {
Rect visibleRegion = Offset.zero & this.size;
Offset startOffset = this._textPainter.getOffsetForCaret(
new TextPosition(offset: this._selection.start, affinity: this._selection.affinity),
Rect.zero
);
float visibleRegionSlop = 0.5f;
this._selectionStartInViewport.value = visibleRegion
.inflate(visibleRegionSlop)
.contains(startOffset + effectiveOffset);
Offset endOffset = this._textPainter.getOffsetForCaret(
new TextPosition(offset: this._selection.end, affinity: this._selection.affinity),
Rect.zero
);
this._selectionEndInViewport.value = visibleRegion
.inflate(visibleRegionSlop)
.contains(endOffset + effectiveOffset);
}
int _extentOffset = -1;

}
}
bool _hasFocus;
bool _hasFocus = false;
bool _listenerAttached = false;
public bool hasFocus {

}
}
public int? minLines {
get { return this._minLines; }
set {
D.assert(value == null || value > 0);
if (this._minLines == value) {
return;
}
this._minLines = value;
this.markNeedsTextLayout();
}
}
public bool expands {
get { return this._expands; }
set {
if (this.expands == value) {
return;
}
this._expands = value;
this.markNeedsTextLayout();
}
}
public Color selectionColor {
get { return this._selectionColor; }
set {

}
public void handleTapDown(TapDownDetails details) {
this._lastTapDownPosition = details.globalPosition - this._paintOffset;
this._lastTapDownPosition = details.globalPosition;
if (!Application.isMobilePlatform) {
this.selectPosition(SelectionChangedCause.tap);
}

D.assert(this._lastTapDownPosition != null);
if (this.onSelectionChanged != null) {
TextPosition position =
this._textPainter.getPositionForOffset(this.globalToLocal(this._lastTapDownPosition));
this._textPainter.getPositionForOffset(this.globalToLocal(this._lastTapDownPosition - this._paintOffset));
TextRange word = this._textPainter.getWordBoundary(position);
if (position.offset - word.start <= 1) {
this.onSelectionChanged(

void _paintCaret(Canvas canvas, Offset effectiveOffset, TextPosition textPosition) {
D.assert(this._textLayoutLastWidth == this.constraints.maxWidth);
var caretOffset = this._textPainter.getOffsetForCaret(textPosition, this._caretPrototype);
var caretOffset = this._textPainter.getOffsetForCaret(textPosition, this._caretPrototype) + effectiveOffset;
#if !UNITY_IOS
if (this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype) != null) {
caretRect = Rect.fromLTWH(
caretRect.left,
caretRect.top - _kCaretHeightOffset,
caretRect.width,
this._textPainter.getFullHeightForCaret(textPosition, this._caretPrototype)
);
}
#endif
caretRect = caretRect.shift(this._getPixelPerfectCursorOffset(caretRect));
if (this.cursorRadius == null) {
canvas.drawRect(caretRect, paint);

}
float _preferredHeight(float width) {
if (this.maxLines != null) {
bool lockedMax = this.maxLines != null && this.minLines == null;
bool lockedBoth = this.maxLines != null && this.minLines == this.maxLines;
bool singleLine = this.maxLines == 1;
if (singleLine || lockedMax || lockedBoth) {
}
bool minLimited = this.minLines != null && this.minLines > 1;
bool maxLimited = this.maxLines != null;
if (minLimited || maxLimited) {
this._layoutText(width);
if (minLimited && this._textPainter.height < this.preferredLineHeight * this.minLines.Value) {
return this.preferredLineHeight * this.minLines.Value;
}
if (maxLimited && this._textPainter.height > this.preferredLineHeight * this.maxLines.Value) {
return this.preferredLineHeight * this.maxLines.Value;
}
}
if (!width.isFinite()) {

properties.add(new DiagnosticsProperty<Color>("cursorColor", this.cursorColor));
properties.add(new DiagnosticsProperty<ValueNotifier<bool>>("showCursor", this.showCursor));
properties.add(new DiagnosticsProperty<int?>("maxLines", this.maxLines));
properties.add(new DiagnosticsProperty<int?>("minLines", this.minLines));
properties.add(new DiagnosticsProperty<bool>("expands", this.expands));
properties.add(new DiagnosticsProperty<Color>("selectionColor", this.selectionColor));
properties.add(new DiagnosticsProperty<float>("textScaleFactor", this.textScaleFactor));
properties.add(new DiagnosticsProperty<TextSelection>("selection", this.selection));

7
Runtime/ui/window.cs


VoidCallback _onTextScaleFactorChanged;
public VoidCallback onPlatformBrightnessChanged {
get { return this._onPlatformBrightnessChanged; }
set { this._onPlatformBrightnessChanged = value; }
}
VoidCallback _onPlatformBrightnessChanged;
public FrameCallback onBeginFrame {
get { return this._onBeginFrame; }
set { this._onBeginFrame = value; }

正在加载...
取消
保存