浏览代码

Merge remote-tracking branch 'origin/master' into image

/main
gewentao 6 年前
当前提交
8a70a724
共有 25 个文件被更改,包括 725 次插入193 次删除
  1. 11
      Assets/UIWidgets/Tests/Menu.cs
  2. 30
      Assets/UIWidgets/Tests/Widgets.cs
  3. 16
      Assets/UIWidgets/editor/editor_window.cs
  4. 19
      Assets/UIWidgets/foundation/diagnostics.cs
  5. 72
      Assets/UIWidgets/painting/text_painter.cs
  6. 23
      Assets/UIWidgets/painting/text_span.cs
  7. 24
      Assets/UIWidgets/painting/text_style.cs
  8. 30
      Assets/UIWidgets/rendering/editable.cs
  9. 23
      Assets/UIWidgets/service/text_input.cs
  10. 22
      Assets/UIWidgets/ui/painting/canvas_impl.cs
  11. 2
      Assets/UIWidgets/ui/painting/txt/font_manager.cs
  12. 13
      Assets/UIWidgets/ui/text.cs
  13. 60
      Assets/UIWidgets/ui/txt/paragraph.cs
  14. 4
      Assets/UIWidgets/ui/txt/word_separate.cs
  15. 2
      Assets/UIWidgets/widgets/basic.cs
  16. 2
      Assets/UIWidgets/widgets/binding.cs
  17. 81
      Assets/UIWidgets/widgets/editable_text.cs
  18. 55
      Assets/UIWidgets/widgets/framework.cs
  19. 2
      Assets/UIWidgets/widgets/sliver.cs
  20. 180
      Assets/UIWidgets/widgets/text.cs
  21. 4
      Assets/UIWidgets/widgets/text.cs.meta
  22. 158
      Assets/UIWidgets/Tests/SceneViewTests.cs
  23. 3
      Assets/UIWidgets/Tests/SceneViewTests.cs.meta
  24. 79
      Assets/UIWidgets/Tests/ScrollViews.cs
  25. 3
      Assets/UIWidgets/Tests/ScrollViews.cs.meta

11
Assets/UIWidgets/Tests/Menu.cs


EditorWindow.GetWindow(typeof(Widgets));
}
[MenuItem("UIWidgetsTests/ScrollViews")]
public static void renderScrollViews() {
EditorWindow.GetWindow(typeof(ScrollViews));
[MenuItem("UIWidgetsTests/Show SceneViewTests")]
public static void showSceneView() {
SceneViewTests.show();
}
[MenuItem("UIWidgetsTests/Hide SceneViewTests")]
public static void hideSceneView() {
SceneViewTests.hide();
}
}
}

30
Assets/UIWidgets/Tests/Widgets.cs


Widget _buildHeader(BuildContext context) {
return new Container(
padding: EdgeInsets.only(left: 16.0, right: 8.0),
// color: CLColors.blue,
height: headerHeight - _offsetY,
child: new Row(
children: new List<Widget> {

if (pixels <= headerHeight) {
setState(() => { _offsetY = pixels / 2.0; });
}
}
else {
} else {
if (_offsetY != 0.0) {
setState(() => { _offsetY = 0.0; });
}

return true;
},
child: new Flexible(
child: ListView.builder(
itemCount: 20,
itemExtent: 100,
physics: new AlwaysScrollableScrollPhysics(),
itemBuilder: (BuildContext context1, int index) => {
return new Container(
color: Color.fromARGB(255, (index * 10) % 256, (index * 10) % 256, (index * 10) % 256)
);
}
child: new Container(
// color: CLColors.green,
child: ListView.builder(
itemCount: 20,
itemExtent: 100,
physics: new AlwaysScrollableScrollPhysics(),
itemBuilder: (BuildContext context1, int index) => {
return new Container(
color: Color.fromARGB(255, (index * 10) % 256, (index * 20) % 256,
(index * 30) % 256)
);
}
)
)
)
);

var container = new Container(
color: CLColors.background1,
// color: CLColors.background1,
color: CLColors.background1,
// color: CLColors.background1,
child: new Column(
children: new List<Widget> {
this._buildHeader(context),

16
Assets/UIWidgets/editor/editor_window.cs


namespace UIWidgets.editor {
public class WindowAdapter : Window {
public WindowAdapter(EditorWindow editorWindow) {
this._editorWindow = editorWindow;
this._editorWindow.wantsMouseMove = false;
this._editorWindow.wantsMouseEnterLeaveWindow = false;
this.editorWindow = editorWindow;
this.editorWindow.wantsMouseMove = false;
this.editorWindow.wantsMouseEnterLeaveWindow = false;
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint;

}
}
readonly EditorWindow _editorWindow;
public readonly EditorWindow editorWindow;
readonly WidgetsBinding _binding;

dirty = true;
}
if (this._lastPosition != this._editorWindow.position) {
if (this._lastPosition != this.editorWindow.position) {
this._lastPosition = this._editorWindow.position;
this._lastPosition = this.editorWindow.position;
this._physicalSize = new Size(
this._lastPosition.width * EditorGUIUtility.pixelsPerPoint,
this._lastPosition.height * EditorGUIUtility.pixelsPerPoint);

}
public override void scheduleFrame() {
if (this._editorWindow != null) {
this._editorWindow.Repaint();
if (this.editorWindow != null) {
this.editorWindow.Repaint();
}
}

19
Assets/UIWidgets/foundation/diagnostics.cs


}
}
public class FlagProperty : DiagnosticsProperty<bool> {
public FlagProperty(String name,
bool value,
public class FlagProperty : DiagnosticsProperty<bool?> {
public FlagProperty(string name,
bool? value,
string ifTrue = null,
string ifFalse = null,
bool showName = false,

public readonly string ifFalse;
protected override string valueToString(TextTreeConfiguration parentConfiguration = null) {
if (this.value) {
if (this.value == true) {
} else if (!this.value) {
} else if (this.value == false) {
if (this.ifFalse != null) {
return this.ifFalse;
}

public override bool showName {
get {
if (this.value && this.ifTrue == null || !this.value == false && this.ifFalse == null) {
if (this.value == null || this.value == true && this.ifTrue == null || this.value == false && this.ifFalse == null) {
return true;
}

public override DiagnosticLevel level {
get {
if (this.value) {
if (this.value == true) {
if (!this.value) {
if (this.value == false) {
if (this.ifFalse == null) {
return DiagnosticLevel.hidden;
}

);
internal static readonly _NoDefaultValue kNoDefaultValue = new _NoDefaultValue();
internal static readonly _NullDefaultValue kNullDefaultValue = new _NullDefaultValue();
public static readonly object kNullDefaultValue = new _NullDefaultValue();
public static string shortHash(object o) {
return (o.GetHashCode() & 0xFFFFF).ToString("X").PadLeft(5, '0');

72
Assets/UIWidgets/painting/text_painter.cs


return null;
}
public List<TextBox> getBoxesForSelection(TextSelection selection)
{
D.assert(!_needsLayout);

D.assert(!_needsLayout);
var range = _paragraph.getWordBoundary(position.offset);
return new TextRange(range.start, range.end);
}
public TextPosition getPositionVerticalMove(TextPosition position, int move)
{
D.assert(!_needsLayout);
var offset = getOffsetForCaret(position, Rect.zero);
var line = _paragraph.getLine(position);
var targetLineStart = _paragraph.getLineStart(line + move);
var newLineOffset = getOffsetForCaret(targetLineStart, Rect.zero);
return getPositionForOffset(new Offset(offset.dx, newLineOffset.dy));
}
public int getLineIndex(TextPosition position)
{
D.assert(!_needsLayout);
return _paragraph.getLine(position);
public TextPosition getLineStartPosition(int line)
{
D.assert(!_needsLayout);
return _paragraph.getLineStart(line);
}
public TextPosition getLineEndPosition(int line)
{
D.assert(!_needsLayout);
return _paragraph.getLineEnd(line);
}
public TextPosition getWordRight(TextPosition position)
{
D.assert(!_needsLayout);
var offset = position.offset;
while(true)
{
var range = _paragraph.getWordBoundary(offset);
if (range.end == range.start)
{
break;
}
if (!char.IsWhiteSpace((char)(text.codeUnitAt(range.start)??0)))
{
return new TextPosition(range.end);
}
offset = range.end;
}
return new TextPosition(offset);
}
public TextPosition getWordLeft(TextPosition position)
{
D.assert(!_needsLayout);
var offset = Math.Max(position.offset - 1, 0);
while(true)
{
var range = _paragraph.getWordBoundary(offset);
if (!char.IsWhiteSpace((char)(text.codeUnitAt(range.start)??0)))
{
return new TextPosition(range.start);
}
offset = Math.Max(range.start - 1, 0);
if (offset == 0)
{
break;
}
}
return new TextPosition(offset);
}
private ParagraphStyle _createParagraphStyle(TextDirection defaultTextDirection = TextDirection.ltr)
{
if (_text.style == null)

23
Assets/UIWidgets/painting/text_span.cs


using System.Collections.Generic;
using System.Linq;
using System.Text;
using UIWidgets.foundation;
using UIWidgets.ui;
using UnityEditor;
using UnityEngine.Assertions;

{
}
public class TextSpan: IEquatable<TextSpan>
public class TextSpan: DiagnosticableTree, IEquatable<TextSpan>
{
public delegate bool Visitor(TextSpan span);
public readonly TextStyle style;

}
return left.SequenceEqual(right);
}
public override List<DiagnosticsNode> debugDescribeChildren() {
if (children == null)
{
return new List<DiagnosticsNode>();
}
return children.Select((child) =>
{
if (child != null)
{
return child.toDiagnosticsNode();
}
else
{
return DiagnosticsNode.message("<null child>");
}
}).ToList();
}
}
}

24
Assets/UIWidgets/painting/text_style.cs


base.debugFillProperties(properties);
List<DiagnosticsNode> styles = new List<DiagnosticsNode>();
styles.Add(new DiagnosticsProperty<Color>("color", color, defaultValue: null));
styles.Add(new StringProperty("family", fontFamily, defaultValue: null, quoted: false));
styles.Add(new DiagnosticsProperty<double?>("size", fontSize, defaultValue: null));
styles.Add(new DiagnosticsProperty<Color>("color", color, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new StringProperty("family", fontFamily, defaultValue: Diagnostics.kNullDefaultValue, quoted: false));
styles.Add(new DiagnosticsProperty<double?>("size", fontSize, defaultValue: Diagnostics.kNullDefaultValue));
string weightDescription = "";
if (fontWeight != null)
{

"weight",
fontWeight,
description: weightDescription,
defaultValue: null
defaultValue: Diagnostics.kNullDefaultValue
styles.Add(new EnumProperty<FontStyle?>("style", fontStyle, defaultValue: null));
styles.Add(new DiagnosticsProperty<double?>("letterSpacing", letterSpacing, defaultValue: null));
styles.Add(new DiagnosticsProperty<double?>("wordSpacing", wordSpacing, defaultValue: null));
styles.Add(new EnumProperty<TextBaseline?>("baseline", textBaseline, defaultValue: null));
styles.Add(new DiagnosticsProperty<double?>("height", height, defaultValue: null));
styles.Add(new StringProperty("background", background == null ? null : background.ToString(), defaultValue: null, quoted: false));
styles.Add(new EnumProperty<FontStyle?>("style", fontStyle, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<double?>("letterSpacing", letterSpacing, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<double?>("wordSpacing", wordSpacing, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new EnumProperty<TextBaseline?>("baseline", textBaseline, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new DiagnosticsProperty<double?>("height", height, defaultValue: Diagnostics.kNullDefaultValue));
styles.Add(new StringProperty("background", background == null ? null : background.ToString(), defaultValue: Diagnostics.kNullDefaultValue, quoted: false));
if (decoration != null)
{
List<string> decorationDescription = new List<string>();

}
styles.Add(new DiagnosticsProperty<Color>("decorationColor", decorationColor, defaultValue: null,
styles.Add(new DiagnosticsProperty<Color>("decorationColor", decorationColor, defaultValue: Diagnostics.kNullDefaultValue,
level: DiagnosticLevel.fine));
if (decorationColor != null)
{

styles.Add(new DiagnosticsProperty<TextDecoration>("decoration", decoration, defaultValue: null,
styles.Add(new DiagnosticsProperty<TextDecoration>("decoration", decoration, defaultValue: Diagnostics.kNullDefaultValue,
level: DiagnosticLevel.hidden));
if (decoration != null)
decorationDescription.Add("$decoration");

30
Assets/UIWidgets/rendering/editable.cs


var caretOffset = _textPainter.getOffsetForCaret(caretPosition, _caretPrototype);
return Rect.fromLTWH(0.0, 0.0, _kCaretWidth, preferredLineHeight).shift(caretOffset + _paintOffset);
}
public TextPosition getPositionDown(TextPosition position)
{
return _textPainter.getPositionVerticalMove(position, 1);
}
public TextPosition getPositionUp(TextPosition position)
{
return _textPainter.getPositionVerticalMove(position, -1);
}
public TextPosition getLineStartPosition(TextPosition position)
{
return _textPainter.getLineStartPosition(_textPainter.getLineIndex(position));
}
public TextPosition getLineEndPosition(TextPosition position)
{
return _textPainter.getLineEndPosition(_textPainter.getLineIndex(position));
}
public TextPosition getWordRight(TextPosition position)
{
return _textPainter.getWordRight(position);
}
public TextPosition getWordLeft(TextPosition position)
{
return _textPainter.getWordLeft(position);
}
protected override double computeMinIntrinsicWidth(double height) {
_layoutText(double.PositiveInfinity);
return _textPainter.minIntrinsicWidth;

23
Assets/UIWidgets/service/text_input.cs


);
}
public TextEditingValue deleteSelection()
public TextEditingValue deleteSelection(bool backDelete = true)
if (selection.start == 0)
if (backDelete)
{
if (selection.start == 0)
{
return this;
}
return this.copyWith(text: text.Substring(0, selection.start - 1) + selection.textAfter(this.text),
selection: TextSelection.collapsed(selection.start - 1));
}
if (selection.start >= text.Length)
return this.copyWith(text: text.Substring(0, selection.start - 1) + selection.textAfter(this.text),
selection: TextSelection.collapsed(selection.start - 1));
return this.copyWith(text: text.Substring(0, selection.start) + text.Substring(selection.start + 1));
}
else
{

public interface TextInputClient
{
void updateEditingValue(TextEditingValue value);
TextEditingValue getValueForOperation(TextEditOp operation);
// void performAction(TextInputAction action);
}

if (s_Keyactions.ContainsKey(e))
{
TextEditOp op = s_Keyactions[e];
var newValue = performOperation(op);
var newValue =_currentConnection._client.getValueForOperation(op);
if (_value != newValue)
{
_value = newValue;

}
}
internal enum TextEditOp
public enum TextEditOp
{
MoveLeft,
MoveRight,

22
Assets/UIWidgets/ui/painting/canvas_impl.cs


private ClipRec _clipRec;
private LayerRec _layerRec;
private Stack<CanvasRec> _stack;
private RenderTexture _defaultTexture;
private Stack<CanvasRec> stack {
get { return this._stack ?? (this._stack = new Stack<CanvasRec>()); }

1.0f / EditorGUIUtility.pixelsPerPoint,
1.0f / EditorGUIUtility.pixelsPerPoint,
1.0f));
this._defaultTexture = RenderTexture.active;
}
public void drawPloygon4(Offset[] points, Paint paint) {

GL.End();
}
}
public void drawRect(Rect rect, BorderWidth borderWidth, BorderRadius borderRadius, Paint paint) {
this.prepareGL(CanvasImpl.guiRoundedRectMat);

RenderTextureFormat.ARGB32, RenderTextureReadWrite.sRGB);
RenderTexture.active = texture;
GL.PushMatrix();
GL.LoadPixelMatrix((float) bounds.left, (float) bounds.right, (float) bounds.bottom, (float) bounds.top);
GL.Clear(true, true, new UnityEngine.Color(0, 0, 0, 0));

this._layerRec = state.layerRec;
if (layerRec != this._layerRec) {
RenderTexture.active = this._layerRec != null ? this._layerRec.texture : null;
var targetTexture = this._layerRec != null ? this._layerRec.texture : this._defaultTexture;
RenderTexture.active = targetTexture;
GL.PopMatrix();
this.prepareGL(CanvasImpl.guiTextureClipMat);

var font = FontManager.instance.getOrCreate(textBlob.style.fontFamily, textBlob.style.UnityFontSize);
prepareGL(font.material);
font.material.SetPass(0);
Matrix4x4 cameraMat = Matrix4x4.identity;
if (Camera.current != null) // draw mesh will use camera matrix, set to identity before draw mesh
{
cameraMat = Camera.current.worldToCameraMatrix;
Camera.current.worldToCameraMatrix = Matrix4x4.identity;
}
if (Camera.current != null)
{
Camera.current.worldToCameraMatrix = cameraMat;
Camera.current.ResetWorldToCameraMatrix();
}
}
private void pushClipRect(Rect clipRect, Matrix4x4 transform) {

2
Assets/UIWidgets/ui/painting/txt/font_manager.cs


public Font getOrCreate(string[] names, int fontSize)
{
_fonts = _fonts.FindAll((font) => font != null); // filter out destoryed fonts
(
font.fontSize == fontSize &&
(names == font.fontNames || (names != null && names.SequenceEqual(font.fontNames)))));

13
Assets/UIWidgets/ui/text.cs


{
public enum FontStyle
{
/// Use the upright glyphs
/// Use glyphs designed for slanting
italic,
}

public enum TextAlign
{
/// Align the text on the left edge of the container.
/// Align the text on the right edge of the container.
/// Align the text in the center of the container.
/// Stretch lines of text that end with a soft line break to fill the width of
/// the container.
///
/// Lines that end with hard line breaks are aligned towards the [start] edge.
justify,
}

60
Assets/UIWidgets/ui/txt/paragraph.cs


using System;
using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.ui.txt;
using UnityEngine;

_characterPositions, line.start, line.endExcludingWhitespace);
}
}
}
computeWidthMetrics(maxWordWidth);

double top = baseLine - run.fontMetrics.ascent;
double bottom = baseLine + run.fontMetrics.descent;
// double left, right;
var from = Math.Max(start, run.codeUnits.start);
var to = Math.Min(end, run.codeUnits.end);
if (from < to)

return new PositionWithAffinity(index, TextAffinity.downstream);
} else
{
return new PositionWithAffinity(index, TextAffinity.upstream);
return new PositionWithAffinity(index + 1, TextAffinity.upstream);
public int getLine(TextPosition position)
{
D.assert(!_needsLayout);
if (position.offset < 0)
{
return 0;
}
var offset = position.offset;
if (position.affinity == TextAffinity.upstream && offset > 0)
{
offset = _isUtf16Surrogate(_text[offset - 1]) ? offset - 2 : offset - 1;
}
var lineCount = getLineCount();
for (int lineIndex = 0; lineIndex < getLineCount(); ++lineIndex)
{
var line = _lineRanges[lineIndex];
if (offset >= line.start && offset <= line.end)
{
return lineIndex;
}
}
return Math.Max(lineCount - 1, 0);
}
public TextPosition getLineStart(int lineIndex)
{
lineIndex = Math.Min(getLineCount() - 1, Math.Max(lineIndex, 0));
return new TextPosition(_lineRanges[lineIndex].start);
}
public TextPosition getLineEnd(int lineIndex)
{
lineIndex = Math.Min(getLineCount() - 1, Math.Max(lineIndex, 0));
return new TextPosition(_lineRanges[lineIndex].end);
}
public IndexRange getWordBoundary(int offset)
{
WordSeparate s = new WordSeparate(_text);

}
}
}
public int getLineCount()
{
return _lineHeights.Count;
}
private void computeWidthMetrics(double maxWordWidth)
{

_alphabeticBaseline = maxAscent;
_ideographicBaseline = maxAscent; // todo Properly implement ideographic_baseline
}
lastDescent = maxDescent;
yOffset = Utils.PixelCorrectRound(yOffset + maxAscent + lastDescent);
foreach (var record in linePaintRecords)
{

for (var charIndex = line.start; charIndex < line.end; charIndex++)
{
_characterPositions[charIndex].y = yOffset;
_characterPositions[charIndex].y = yOffset;
lastDescent = maxDescent;
}
}

yOffset = yOffsetOriginal;
}
}
}
private static bool _isUtf16Surrogate(int value)
{
return (value & 0xF800) == 0xD800;
}
}

4
Assets/UIWidgets/ui/txt/word_separate.cs


public IndexRange findWordRange(int index)
{
if (index >= _text.Length)
{
return new IndexRange(0, 0);
}
var t = classifyChar(index);
int start = index;
for (int i = index; i >= 0; --i)

2
Assets/UIWidgets/widgets/basic.cs


}
}
public class Flexible : ParentDataWidget {
public class Flexible : ParentDataWidget<Flex> {
public Flexible(
Key key = null,
int flex = 1,

2
Assets/UIWidgets/widgets/binding.cs


get { return this._buildOwner; }
}
private readonly BuildOwner _buildOwner = new BuildOwner();
readonly BuildOwner _buildOwner = new BuildOwner();
public FocusManager focusManager {
get { return this._buildOwner.focusManager; }

81
Assets/UIWidgets/widgets/editable_text.cs


{
style.debugFillProperties(properties);
}
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: null));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: null));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor, defaultValue: null));
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor, defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DiagnosticsProperty<int>("maxLines", maxLines, defaultValue: 1));
properties.add(new DiagnosticsProperty<bool>("autofocus", autofocus, defaultValue: false));
}

_lastKnownRemoteTextEditingValue = value;
_formatAndSetValue(value);
}
public TextEditingValue getValueForOperation(TextEditOp operation)
{
TextPosition newPosition = null;
switch (operation)
{
case TextEditOp.MoveLeft:
return _value.moveLeft();
case TextEditOp.MoveRight:
return _value.moveRight();
case TextEditOp.MoveUp:
newPosition = this.renderEditable.getPositionUp(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveDown:
newPosition = this.renderEditable.getPositionDown(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveLineStart:
newPosition = this.renderEditable.getLineStartPosition(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveLineEnd:
newPosition = this.renderEditable.getLineEndPosition(new TextPosition(_value.selection.start, _value.selection.affinity));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveWordRight:
newPosition = this.renderEditable.getWordRight(new TextPosition(_value.selection.start));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
case TextEditOp.MoveWordLeft:
newPosition = this.renderEditable.getWordLeft(new TextPosition(_value.selection.start));
return _value.copyWith(selection: TextSelection.fromPosition(newPosition));
// case TextEditOp.MoveToStartOfNextWord: MoveToStartOfNextWord(); break;
// case TextEditOp.MoveToEndOfPreviousWord: MoveToEndOfPreviousWord(); break;
case TextEditOp.MoveTextStart:
return _value.copyWith(selection: TextSelection.collapsed(0));
case TextEditOp.MoveTextEnd:
return _value.copyWith(selection: TextSelection.collapsed(_value.text.Length));
// case TextEditOp.MoveParagraphForward: MoveParagraphForward(); break;
// case TextEditOp.MoveParagraphBackward: MoveParagraphBackward(); break;
// case TextEditOp.MoveGraphicalLineStart: MoveGraphicalLineStart(); break;
// case TextEditOp.MoveGraphicalLineEnd: MoveGraphicalLineEnd(); break;
case TextEditOp.SelectLeft:
return _value.extendLeft();
case TextEditOp.SelectRight:
return _value.extendRight();
case TextEditOp.SelectUp:
newPosition = this.renderEditable.getPositionUp(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
case TextEditOp.SelectDown:
newPosition = this.renderEditable.getPositionDown(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
case TextEditOp.SelectWordRight:
newPosition = this.renderEditable.getWordRight(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
case TextEditOp.SelectWordLeft:
newPosition = this.renderEditable.getWordLeft(_value.selection.extendPos);
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: newPosition.offset));
// case TextEditOp.SelectToEndOfPreviousWord: SelectToEndOfPreviousWord(); break;
// case TextEditOp.SelectToStartOfNextWord: SelectToStartOfNextWord(); break;
//
case TextEditOp.SelectTextStart:
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: 0));
case TextEditOp.SelectTextEnd:
return _value.copyWith(selection: _value.selection.copyWith(extentOffset: _value.text.Length));
// case TextEditOp.ExpandSelectGraphicalLineStart: ExpandSelectGraphicalLineStart(); break;
// case TextEditOp.ExpandSelectGraphicalLineEnd: ExpandSelectGraphicalLineEnd(); break;
// case TextEditOp.SelectParagraphForward: SelectParagraphForward(); break;
// case TextEditOp.SelectParagraphBackward: SelectParagraphBackward(); break;
// case TextEditOp.SelectGraphicalLineStart: SelectGraphicalLineStart(); break;
// case TextEditOp.SelectGraphicalLineEnd: SelectGraphicalLineEnd(); break;
case TextEditOp.Delete: return _value.deleteSelection(false);
case TextEditOp.Backspace:
return _value.deleteSelection();
}
return _value;
}
void _updateRemoteEditingValueIfNeeded()

55
Assets/UIWidgets/widgets/framework.cs


: base(key: key, child: child) {
}
public abstract bool debugIsValidAncestor(RenderObjectWidget ancestor);
public abstract string debugDescribeInvalidAncestorChain(
string description = null,
string ownershipChain = null,
bool foundValidAncestor = false,
IEnumerable<Widget> badAncestors = null
);
public abstract void applyParentData(RenderObject renderObject);
public virtual bool debugCanApplyOutOfTurn() {
return false;
}
}
public abstract class ParentDataWidget<T> : ParentDataWidget where T : RenderObjectWidget {
public ParentDataWidget(Key key = null, Widget child = null)
: base(key: key, child: child) {
}
public virtual bool debugIsValidAncestor(RenderObjectWidget ancestor) {
return ancestor is RenderObjectWidget;
public override bool debugIsValidAncestor(RenderObjectWidget ancestor) {
D.assert(typeof(T) != typeof(RenderObjectWidget));
return ancestor is T;
public virtual string debugDescribeInvalidAncestorChain(
String description = null, String ownershipChain = null, bool foundValidAncestor = false,
public override string debugDescribeInvalidAncestorChain(
string description = null,
string ownershipChain = null,
bool foundValidAncestor = false,
String result;
D.assert(typeof(T) != typeof(RenderObjectWidget));
string result;
result = string.Format("{0} widgets must be placed inside {1} widgets.\n" +
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(RenderObjectWidget), description);
result = string.Format(
"{0} widgets must be placed inside {1} widgets.\n" +
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(T), description);
result = string.Format("{0} widgets must be placed directly inside {1} widgets.\n" +
result = string.Format(
"{0} widgets must be placed directly inside {1} widgets.\n" +
this.GetType(), typeof(RenderObjectWidget), description);
this.GetType(), typeof(T), description);
foreach (Widget ancestor in badAncestors) {
if (ancestor.GetType() == this.GetType()) {

}
}
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(RenderObjectWidget) + ".\n";
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(T) + ".\n";
}
result += "The ownership chain for the parent of the offending "

public abstract void applyParentData(RenderObject renderObject);
public virtual bool debugCanApplyOutOfTurn() {
return false;
}
public abstract class InheritedWidget : ProxyWidget {
protected InheritedWidget(Key key = null, Widget child = null) : base(key, child) {

2
Assets/UIWidgets/widgets/sliver.cs


}
}
public class KeepAlive : ParentDataWidget{
public class KeepAlive : ParentDataWidget<SliverMultiBoxAdaptorWidget> {
public KeepAlive(
Key key = null,
bool keepAlive = true,

180
Assets/UIWidgets/widgets/text.cs


using TextStyle = UIWidgets.painting.TextStyle;
namespace UIWidgets.widgets {
public class Text : StatelessWidget {
public Text(string data,
public class DefaultTextStyle : InheritedWidget {
public DefaultTextStyle(
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool softWrap = true,
TextOverflow overflow = TextOverflow.clip,
int? maxLines = null,
Widget child = null
) : base(key, child) {
D.assert(style != null);
D.assert(maxLines == null || maxLines > 0);
D.assert(child != null);
this.style = style;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.overflow = overflow;
this.maxLines = maxLines;
}
private DefaultTextStyle() {
this.style = new TextStyle();
this.textAlign = null;
this.softWrap = true;
this.overflow = TextOverflow.clip;
this.maxLines = null;
}
public static DefaultTextStyle fallback() {
return new DefaultTextStyle();
}
public static Widget merge(
int? maxLines = null,
Widget child = null
) {
D.assert(child != null);
return new Builder(builder: (context => {
var parent = DefaultTextStyle.of(context);
return new DefaultTextStyle(
key: key,
style: parent.style.merge(style),
textAlign: textAlign ?? parent.textAlign,
softWrap: softWrap ?? parent.softWrap,
overflow: overflow ?? parent.overflow,
maxLines: maxLines ?? parent.maxLines,
child: child
);
}));
}
public readonly TextStyle style;
public readonly TextAlign? textAlign;
public readonly bool softWrap;
public readonly TextOverflow overflow;
public readonly int? maxLines;
public static DefaultTextStyle of(BuildContext context) {
var inherit = (DefaultTextStyle) context.inheritFromWidgetOfExactType(typeof(DefaultTextStyle));
return inherit ?? DefaultTextStyle.fallback();
}
public override bool updateShouldNotify(InheritedWidget w) {
var oldWidget = (DefaultTextStyle) w;
return this.style != oldWidget.style ||
this.textAlign != oldWidget.textAlign ||
this.softWrap != oldWidget.softWrap ||
this.overflow != oldWidget.overflow ||
this.maxLines != oldWidget.maxLines;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
if (this.style != null) {
this.style.debugFillProperties(properties);
}
properties.add(new EnumProperty<TextAlign?>("textAlign", this.textAlign,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new FlagProperty("softWrap", value: this.softWrap, ifTrue: "wrapping at box width",
ifFalse: "no wrapping except at line break characters", showName: true));
properties.add(new EnumProperty<TextOverflow>("overflow", this.overflow,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new IntProperty("maxLines", this.maxLines,
defaultValue: Diagnostics.kNullDefaultValue));
}
}
public class Text : StatelessWidget {
public Text(string data,
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
int? maxLines = null) : base(key: key) {
int? maxLines = null) : base(key) {
this.textSpan = null;
this.data = data;
this.style = style;
this.textAlign = textAlign;
this.softWrap = softWrap;
this.overflow = overflow;
this.textScaleFactor = textScaleFactor;
this.maxLines = maxLines;
}
this.data = data;
private Text(TextSpan textSpan,
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
double? textScaleFactor = null,
int? maxLines = null) : base(key) {
D.assert(textSpan != null);
this.textSpan = textSpan;
this.data = null;
this.style = style;
this.textAlign = textAlign;
this.softWrap = softWrap;

this.textSpan = null;
}
public static Text rich(TextSpan textSpan,
Key key = null,
TextStyle style = null,
TextAlign? textAlign = null,
bool? softWrap = null,
TextOverflow? overflow = null,
double? textScaleFactor = null,
int? maxLines = null) {
return new Text(
textSpan, key,
style,
textAlign,
softWrap,
overflow,
textScaleFactor,
maxLines);
}
public readonly string data;

public readonly int? maxLines;
public override Widget build(BuildContext context) {
DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(context);
Widget result = new RichText(
textAlign: this.textAlign ?? TextAlign.left,
softWrap: this.softWrap ?? false,
overflow: this.overflow ?? TextOverflow.clip,
textScaleFactor: this.textScaleFactor ?? 1.0,
maxLines: this.maxLines ?? null,
if (this.style == null || this.style.inherit) {
effectiveTextStyle = defaultTextStyle.style.merge(this.style);
}
return new RichText(
textAlign: this.textAlign ?? defaultTextStyle.textAlign ?? TextAlign.left,
softWrap: this.softWrap ?? defaultTextStyle.softWrap,
overflow: this.overflow ?? defaultTextStyle.overflow,
textScaleFactor: this.textScaleFactor ?? 1.0, // MediaQuery.textScaleFactorOf(context), todo
maxLines: this.maxLines ?? defaultTextStyle.maxLines,
text: new TextSpan(
style: effectiveTextStyle,
text: this.data,

return result;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new StringProperty("data", this.data, showName: false));
if (this.textSpan != null) {
properties.add(this.textSpan.toDiagnosticsNode(name: "textSpan", style: DiagnosticsTreeStyle.transition));
}
if (this.style != null) {
this.style.debugFillProperties(properties);
}
properties.add(new EnumProperty<TextAlign?>("textAlign", this.textAlign,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new FlagProperty("softWrap", value: this.softWrap, ifTrue: "wrapping at box width",
ifFalse: "no wrapping except at line break characters", showName: true));
properties.add(new EnumProperty<TextOverflow?>("overflow", this.overflow,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new DoubleProperty("textScaleFactor", this.textScaleFactor,
defaultValue: Diagnostics.kNullDefaultValue));
properties.add(new IntProperty("maxLines", this.maxLines, defaultValue: Diagnostics.kNullDefaultValue));
}
}
}

4
Assets/UIWidgets/widgets/text.cs.meta


fileFormatVersion: 2
guid: f0d4b5792cbf44c4b6dd2d9c4702b178
timeCreated: 1537816341
guid: a0782677b6674b2fa33872f1d9bb36db
timeCreated: 1537576563

158
Assets/UIWidgets/Tests/SceneViewTests.cs


using System;
using System.Linq;
using System.Reflection;
using UIWidgets.editor;
using UIWidgets.painting;
using UIWidgets.rendering;
using UIWidgets.widgets;
using UnityEditor;
using UnityEngine;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.Tests {
public class SceneViewTests {
public static void show() {
onPreSceneGUIDelegate += OnPreSceneGUI;
SceneView.onSceneGUIDelegate += OnSceneGUI;
EditorApplication.update += Update;
SceneView.RepaintAll();
_options = new Func<Widget>[] {
none,
listView,
eventsPage,
};
_optionStrings = _options.Select(x => x.Method.Name).ToArray();
_selected = 0;
}
public static void hide() {
onPreSceneGUIDelegate -= OnPreSceneGUI;
SceneView.onSceneGUIDelegate -= OnSceneGUI;
EditorApplication.update -= Update;
SceneView.RepaintAll();
}
public static SceneView.OnSceneFunc onPreSceneGUIDelegate {
get {
var field = typeof(SceneView).GetField("onPreSceneGUIDelegate",
BindingFlags.Static | BindingFlags.NonPublic);
return (SceneView.OnSceneFunc) field.GetValue(null);
}
set {
var field = typeof(SceneView).GetField("onPreSceneGUIDelegate",
BindingFlags.Static | BindingFlags.NonPublic);
field.SetValue(null, value);
}
}
private static Func<Widget>[] _options;
private static string[] _optionStrings;
private static int _selected;
[NonSerialized] private static bool hasInvoked = false;
private static EventType _lastEventType;
private static void OnPreSceneGUI(SceneView sceneView) {
_lastEventType = Event.current.rawType;
}
private static void OnSceneGUI(SceneView sceneView) {
//HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive));
Handles.BeginGUI();
if (windowAdapter == null) {
windowAdapter = new WindowAdapter(sceneView);
} else if (windowAdapter != null && windowAdapter.editorWindow != sceneView) {
windowAdapter = new WindowAdapter(sceneView);
}
var selected = EditorGUILayout.Popup("test case", _selected, _optionStrings);
if (selected != _selected || !hasInvoked) {
_selected = selected;
hasInvoked = true;
var widget = _options[_selected]();
windowAdapter.attachRootWidget(widget);
}
if (Event.current.type == EventType.Used) {
Event.current.type = SceneViewTests._lastEventType;
windowAdapter.OnGUI();
Event.current.type = EventType.Used;
} else {
windowAdapter.OnGUI();
}
Handles.EndGUI();
}
private static void Update() {
if (windowAdapter != null) {
windowAdapter.Update();
}
}
private static WindowAdapter windowAdapter;
public static Widget none() {
return null;
}
public static Widget listView() {
return ListView.builder(
itemExtent: 20.0,
itemBuilder: (context, index) => {
return new Container(
color: Color.fromARGB(255, (index * 10) % 256, (index * 10) % 256, (index * 10) % 256)
);
}
);
}
public static Widget eventsPage() {
return new EventsWaterfallScreen();
}
public static RenderBox flex() {
var flexbox = new RenderFlex(
direction: Axis.horizontal,
crossAxisAlignment: CrossAxisAlignment.center);
flexbox.add(new RenderConstrainedBox(
additionalConstraints: new BoxConstraints(minWidth: 300, minHeight: 200),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
color: new Color(0xFF00FF00)
)
)));
flexbox.add(new RenderConstrainedBox(
additionalConstraints: new BoxConstraints(minWidth: 100, minHeight: 300),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
color: new Color(0xFF00FFFF)
)
)));
flexbox.add(new RenderConstrainedBox(
additionalConstraints: new BoxConstraints(minWidth: 50, minHeight: 100),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
color: new Color(0xFF0000FF)
)
)));
return flexbox;
}
}
}

3
Assets/UIWidgets/Tests/SceneViewTests.cs.meta


fileFormatVersion: 2
guid: fc7ab0f913ef4bde95759153a732dbc0
timeCreated: 1537936714

79
Assets/UIWidgets/Tests/ScrollViews.cs


using System;
using System.Linq;
using UIWidgets.editor;
using UIWidgets.painting;
using UIWidgets.widgets;
using UnityEditor;
using UnityEngine;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.Tests {
public class ScrollViews : EditorWindow {
private readonly Func<Widget>[] _options;
private readonly string[] _optionStrings;
private int _selected;
ScrollViews() {
this._options = new Func<Widget>[] {
this.none,
this.listView,
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;
this.titleContent = new GUIContent("ScrollViews");
}
private WindowAdapter windowAdapter;
[NonSerialized] private bool hasInvoked = false;
void OnGUI() {
var selected = EditorGUILayout.Popup("test case", this._selected, this._optionStrings);
if (selected != this._selected || !this.hasInvoked) {
this._selected = selected;
this.hasInvoked = true;
var widget = this._options[this._selected]();
if (this.windowAdapter != null) {
this.windowAdapter.attachRootWidget(widget);
}
}
if (this.windowAdapter != null) {
this.windowAdapter.OnGUI();
}
}
void Update() {
if (this.windowAdapter != null) {
this.windowAdapter.Update();
}
}
private void OnEnable() {
this.windowAdapter = new WindowAdapter(this);
}
void OnDestroy() {
this.windowAdapter = null;
}
Widget none() {
return null;
}
Widget listView() {
return ListView.builder(
itemExtent: 20.0,
itemBuilder: (context, index) => {
return new Container(
color: Color.fromARGB(255, (index * 10) % 256, (index * 10) % 256, (index * 10) % 256)
);
}
);
}
}
}

3
Assets/UIWidgets/Tests/ScrollViews.cs.meta


fileFormatVersion: 2
guid: b14d32b9a23040969ca3316c86d899c3
timeCreated: 1537352615
正在加载...
取消
保存