浏览代码

Merge pull request #122 from UnityTech/yczhang

Fix some style issues.
/main
GitHub 6 年前
当前提交
2cae7c65
共有 6 个文件被更改,包括 171 次插入115 次删除
  1. 18
      Runtime/material/text_field.cs
  2. 3
      Runtime/material/tooltip.cs
  3. 15
      Runtime/painting/text_span.cs
  4. 165
      Runtime/rendering/editable.cs
  5. 63
      Runtime/ui/text.cs
  6. 22
      Samples/UIWidgetsGallery/demo/shrine/shrine_types.cs

18
Runtime/material/text_field.cs


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

namespace Unity.UIWidgets.material {
public class TextField : StatefulWidget {
public TextField(Key key = null, TextEditingController controller = null, FocusNode focusNode = null,
InputDecoration decoration = null, bool noDecoration = false, TextInputType keyboardType = null,
TextInputAction? textInputAction = null,

public readonly VoidCallback onEditingComplete;
public readonly ValueChanged<String> onSubmitted;
public readonly ValueChanged<string> onSubmitted;
public readonly List<TextInputFormatter> inputFormatters;

ifTrue: "max length enforced"));
properties.add(new DiagnosticsProperty<GestureTapCallback>("onTap", this.onTap, defaultValue: null));
}
readonly GlobalKey<EditableTextState> _editableTextKey = new LabeledGlobalKey<EditableTextState>();
HashSet<InteractiveInkFeature> _splashes;

if (this._splashes != null) {
D.assert(this._splashes.Contains(splash));
this._splashes.Remove(splash);
if (this._currentSplash == splash) this._currentSplash = null;
if (this._currentSplash == splash) {
this._currentSplash = null;
}
this.updateKeepAlive();
} // else we're probably in deactivate()
}

}
RenderEditable _renderEditable {
get {
return this._editableTextKey.currentState.renderEditable;
}
}
get { return this._editableTextKey.currentState.renderEditable; }
}
void _handleTapDown(TapDownDetails details) {
this._renderEditable.handleTapDown(details);

child: child
)
);
}
}
}

3
Runtime/material/tooltip.cs


void _handleLongPress() {
bool tooltipCreated = this.ensureTooltipVisible();
if (tooltipCreated)
if (tooltipCreated) {
}
}

15
Runtime/painting/text_span.cs


public readonly List<TextSpan> children;
public readonly GestureRecognizer recognizer;
public TextSpan(string text = "", TextStyle style = null, List<TextSpan> children = null,
public TextSpan(string text = "", TextStyle style = null, List<TextSpan> children = null,
GestureRecognizer recognizer = null) {
this.text = text;
this.style = style;

});
return result;
}
public string toPlainText() {
var sb = new StringBuilder();
this.visitTextSpan((span) => {

if (!this.visitTextSpan(span => {
if (span.children != null) {
foreach (TextSpan child in span.children) {
if (child == null)
if (child == null) {
}
"The full text in question was:\n" +
this.toStringDeep(prefixLineOne:" "));
"The full text in question was:\n" +
this.toStringDeep(prefixLineOne: " "));
public RenderComparison compareTo(TextSpan other) {
if (this.Equals(other)) {
return RenderComparison.identical;

165
Runtime/rendering/editable.cs


int _previousCursorLocation;
bool _resetCursor = false;
void _handleKeyEvent(RawKeyEvent keyEvent) {
if (keyEvent is RawKeyUpEvent) {
return;

this._extentOffset = this.selection.extentOffset;
this._baseOffset = this.selection.baseOffset;
}
bool shift = (modifiers & (int)EventModifiers.Shift) > 0;
bool ctrl = (modifiers & (int)EventModifiers.Control) > 0;
bool alt = (modifiers & (int)EventModifiers.Alt) > 0;
bool cmd = (modifiers & (int)EventModifiers.Command) > 0;
bool shift = (modifiers & (int) EventModifiers.Shift) > 0;
bool ctrl = (modifiers & (int) EventModifiers.Control) > 0;
bool alt = (modifiers & (int) EventModifiers.Alt) > 0;
bool cmd = (modifiers & (int) EventModifiers.Command) > 0;
bool rightArrow = pressedKeyCode == KeyCode.RightArrow;
bool leftArrow = pressedKeyCode == KeyCode.LeftArrow;
bool upArrow = pressedKeyCode == KeyCode.UpArrow;

bool del = pressedKeyCode == KeyCode.Delete;
bool isMac = SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX;
if (keyEvent is RawKeyCommandEvent) { // editor case
this._handleShortcuts(((RawKeyCommandEvent)keyEvent).command);
if (keyEvent is RawKeyCommandEvent) {
// editor case
this._handleShortcuts(((RawKeyCommandEvent) keyEvent).command);
if ((ctrl || (isMac && cmd)) && (xKey || vKey || cKey || aKey)) { // runtime case
if ((ctrl || (isMac && cmd)) && (xKey || vKey || cKey || aKey)) {
// runtime case
} else if (aKey) {
}
else if (aKey) {
} else if (vKey) {
}
else if (vKey) {
} else if (cKey) {
}
else if (cKey) {
if (arrow) {
int newOffset = this._extentOffset;
var word = (isMac && alt) || ctrl;

if (downArrow || upArrow)
if (downArrow || upArrow) {
}
newOffset = this._handleShift(rightArrow, leftArrow, shift, newOffset);
this._extentOffset = newOffset;

// If control is pressed, we will decide which way to look for a word
// based on which arrow is pressed.
if (leftArrow && this._extentOffset > 2) {
TextSelection textSelection = this._selectWordAtOffset(new TextPosition(offset: this._extentOffset - 2));
TextSelection textSelection =
this._selectWordAtOffset(new TextPosition(offset: this._extentOffset - 2));
} else if (rightArrow && this._extentOffset < this.text.text.Length - 2) {
TextSelection textSelection = this._selectWordAtOffset(new TextPosition(offset: this._extentOffset + 1));
}
else if (rightArrow && this._extentOffset < this.text.text.Length - 2) {
TextSelection textSelection =
this._selectWordAtOffset(new TextPosition(offset: this._extentOffset + 1));
int _handleHorizontalArrows(bool rightArrow, bool leftArrow, bool shift, int newOffset) {
if (rightArrow && this._extentOffset < this.text.text.Length) {
newOffset += 1;

}
if (leftArrow && this._extentOffset > 0) {
newOffset -= 1;
if (shift) {

Offset caretOffset = this._textPainter.getOffsetForCaret(new TextPosition(offset: this._extentOffset), this._caretPrototype);
Offset caretOffset =
this._textPainter.getOffsetForCaret(new TextPosition(offset: this._extentOffset), this._caretPrototype);
if (downArrow)
if (downArrow) {
else if (upArrow)
}
else if (upArrow) {
}
} else if (this._resetCursor && shift) {
}
else if (this._resetCursor && shift) {
} else {
}
else {
if (this.onSelectionChanged == null)
if (this.onSelectionChanged == null) {
}
if (shift) {
if (this._baseOffset < newOffset) {
this.onSelectionChanged(

this,
SelectionChangedCause.keyboard
);
} else {
}
else {
this.onSelectionChanged(
new TextSelection(
baseOffset: newOffset,

SelectionChangedCause.keyboard
);
}
} else {
}
else {
if (leftArrow)
if (leftArrow) {
else if (rightArrow)
}
else if (rightArrow) {
}
}
this.onSelectionChanged(

SelectionChangedCause.keyboard
);
}
return newOffset;
}

Clipboard.setData(
new ClipboardData(text: this.selection.textInside(this.text.text)));
}
break;
case KeyCommand.Cut:
if (!this.selection.isCollapsed) {

selection: TextSelection.collapsed(offset: this.selection.start)
);
}
break;
case KeyCommand.Paste:
TextEditingValue value = this.textSelectionDelegate.textEditingValue;

);
}
});
break;
case KeyCommand.SelectAll:
this._baseOffset = 0;

+ selection.textAfter(this.text.text).Substring(1),
selection: TextSelection.collapsed(offset: selection.start)
);
} else {
}
else {
this.textSelectionDelegate.textEditingValue = new TextEditingValue(
text: selection.textBefore(this.text.text),
selection: TextSelection.collapsed(offset: selection.start)

this._textLayoutLastWidth = null;
this.markNeedsLayout();
}
public TextSpan text {
get { return this._textPainter.text; }
set {

bool _hasFocus;
bool _listenerAttached = false;
public bool hasFocus {
get { return this._hasFocus; }
set {

RawKeyboard.instance.removeListener(this._handleKeyEvent);
this._listenerAttached = false;
}
this.markNeedsSemanticsUpdate();
}
}

this.markNeedsLayout();
}
}
set {
if (this._cursorWidth == value)
set {
if (this._cursorWidth == value) {
}
set {
if (this._cursorRadius == value)
set {
if (this._cursorRadius == value) {
}
set {
if (this._enableInteractiveSelection == value)
set {
if (this._enableInteractiveSelection == value) {
}
this._enableInteractiveSelection = value;
this.markNeedsTextLayout();
this.markNeedsSemanticsUpdate();

if (this._listenerAttached) {
RawKeyboard.instance.removeListener(this._handleKeyEvent);
}
base.detach();
}

this._longPress.addPointer((PointerDownEvent) evt);
}
}
this._lastTapDownPosition = details.globalPosition + - this._paintOffset;
this._lastTapDownPosition = details.globalPosition + -this._paintOffset;
public void handleTap() {
this.selectPosition(cause: SelectionChangedCause.tap);
}

D.assert(!this.ignorePointer);
this.handleDoubleTap(details);
}
public void handleDoubleTap(DoubleTapDetails details) {
// need set _lastTapDownPosition, otherwise it would be last single tap position
this._lastTapDownPosition = details.firstGlobalPosition - this._paintOffset;

public void handleLongPress() {
this.selectWord(cause: SelectionChangedCause.longPress);
}
TextPosition position = this._textPainter.getPositionForOffset(this.globalToLocal(this._lastTapDownPosition));
TextPosition position =
this._textPainter.getPositionForOffset(this.globalToLocal(this._lastTapDownPosition));
void selectWord(SelectionChangedCause? cause = null) {
this._layoutText(this.constraints.maxWidth);
D.assert(this._lastTapDownPosition != null);

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

);
} else {
}
else {
this.onSelectionChanged(
TextSelection.collapsed(offset: word.end, affinity: TextAffinity.upstream),
this,

}
}
TextSelection _selectWordAtOffset(TextPosition position) {
D.assert(this._textLayoutLastWidth == this.constraints.maxWidth);
var word = this._textPainter.getWordBoundary(position);

return new TextSelection(baseOffset: word.start, extentOffset: word.end);
}
void _layoutText(float constraintWidth) {
if (this._textLayoutLastWidth == constraintWidth) {
return;

this._textLayoutLastWidth = constraintWidth;
}
protected override void performLayout() {
this._layoutText(this.constraints.maxWidth);
this._caretPrototype = Rect.fromLTWH(0.0f, _kCaretHeightOffset, this.cursorWidth,

RRect caretRRect = RRect.fromRectAndRadius(caretRect, this.cursorRadius);
canvas.drawRRect(caretRRect, paint);
}
if (!caretRect.Equals(this._lastCaretRect)) {
this._lastCaretRect = caretRect;
if (this.onCaretChanged != null) {

public override Rect describeApproximatePaintClip(RenderObject child) {
return this._hasVisualOverflow ? Offset.zero & this.size : null;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Color>("cursorColor", this.cursorColor));

63
Runtime/ui/text.cs


}
}
internal class TextStyle : IEquatable<TextStyle> {
class TextStyle : IEquatable<TextStyle> {
public readonly Color color = Color.fromARGB(255, 0, 0, 0);
public readonly float fontSize = 14.0f;
public readonly FontWeight fontWeight = FontWeight.w400;

public static TextStyle applyStyle(TextStyle currentStyle, painting.TextStyle style, float textScaleFactor) {
if (currentStyle != null) {
return new ui.TextStyle(
return new TextStyle(
color: style.color ?? currentStyle.color,
fontSize: style.fontSize != null ? style.fontSize * textScaleFactor : currentStyle.fontSize,
fontWeight: style.fontWeight ?? currentStyle.fontWeight,

);
}
return new ui.TextStyle(
return new TextStyle(
color: style.color,
fontSize: style.fontSize * textScaleFactor,
fontWeight: style.fontWeight,

downstream,
}
public class FontWeight: IEquatable<FontWeight> {
private FontWeight(int index) {
public class FontWeight : IEquatable<FontWeight> {
FontWeight(int index) {
public static readonly FontWeight w100 = new FontWeight(0);
public static readonly FontWeight w200 = new FontWeight(1);
public static readonly FontWeight w300 = new FontWeight(2);
public static readonly FontWeight w400 = new FontWeight(3);
public static readonly FontWeight w500 = new FontWeight(4);
public static readonly FontWeight w600 = new FontWeight(5);
public static readonly FontWeight w700 = new FontWeight(6);
public static readonly FontWeight w800 = new FontWeight(7);
public static readonly FontWeight w900 = new FontWeight(8);
public static readonly FontWeight normal = w400;
public static readonly FontWeight bold = w700;
public static readonly List<FontWeight> values = new List<FontWeight>{
public static readonly FontWeight w100 = new FontWeight(0);
public static readonly FontWeight w200 = new FontWeight(1);
public static readonly FontWeight w300 = new FontWeight(2);
public static readonly FontWeight w400 = new FontWeight(3);
public static readonly FontWeight w500 = new FontWeight(4);
public static readonly FontWeight w600 = new FontWeight(5);
public static readonly FontWeight w700 = new FontWeight(6);
public static readonly FontWeight w800 = new FontWeight(7);
public static readonly FontWeight w900 = new FontWeight(8);
public static readonly FontWeight normal = w400;
public static readonly FontWeight bold = w700;
public static readonly List<FontWeight> values = new List<FontWeight> {
public static readonly Dictionary<int, int> indexToFontWeight = new Dictionary<int, int> {
{0, 100},
{1, 200},

{7, 800},
{8, 900},
};
public bool Equals(FontWeight other) {
if (ReferenceEquals(null, other)) {
return false;

public override string ToString() {
return $"FontWeight.w{this.weightValue}";
}
get {
return indexToFontWeight[this.index];
}
get { return indexToFontWeight[this.index]; }
}
}

22
Samples/UIWidgetsGallery/demo/shrine/shrine_types.cs


}
public override string ToString() {
return "Vendor($name)";
return $"Vendor({this.name})";
}
}

}
public static bool operator ==(Order left, Order right) {
if (left is null && right is null) return true;
if (left is null || right is null) return false;
if (left is null && right is null) {
return true;
}
if (left is null || right is null) {
return false;
}
if (left is null && right is null) return false;
if (left is null || right is null) return true;
if (left is null && right is null) {
return false;
}
if (left is null || right is null) {
return true;
}
return !left.Equals(right);
}

正在加载...
取消
保存