浏览代码

Cleanup. Use UnityEngine.Rect in textblob.

/main
Yuncong Zhang 5 年前
当前提交
7353e4c5
共有 5 个文件被更改,包括 10 次插入58 次删除
  1. 2
      Runtime/painting/text_painter.cs
  2. 26
      Runtime/ui/painting/txt/text_blob.cs
  3. 12
      Runtime/ui/text.cs
  4. 26
      Runtime/ui/txt/layout_utils.cs
  5. 2
      Tests/Editor/CanvasAndLayers.cs

2
Runtime/painting/text_painter.cs


var prevCodeUnit = this._text.codeUnitAt(offset);
if (prevCodeUnit == null) // out of upper bounds
{
TextBox? rectNextLine = this._paragraph.getNextLineStartRect();
var rectNextLine = this._paragraph.getNextLineStartRect();
if (rectNextLine != null) {
return new Offset(((TextBox) rectNextLine).start, ((TextBox) rectNextLine).top);
}

26
Runtime/ui/painting/txt/text_blob.cs


namespace Unity.UIWidgets.ui {
public struct TextBlob {
internal TextBlob(string text, int textOffset, int textSize, float[] positions,
float minX, float minY, float width, float height, TextStyle style) {
UnityEngine.Rect bounds, TextStyle style) {
this._minX = minX;
this._minY = minY;
this._width = width;
this._height = height;
this._bounds = bounds;
this._positions = positions;
}

return Rect.fromLTWH(this._minX + pos, this._minY, this._width, this._height);
return Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin, this._bounds.width, this._bounds.height);
return Rect.fromLTWH(this._minX + pos + offset.dx, this._minY + offset.dy, this._width, this._height);
return Rect.fromLTWH(this._bounds.xMin + pos + offset.dx, this._bounds.yMin + offset.dy, this._bounds.width, this._bounds.height);
}
public float getPosition(int i) {

internal readonly int textOffset;
internal readonly int textSize;
internal readonly TextStyle style;
readonly float _minX, _minY, _width, _height; // bounds with positions[start] as origin
readonly UnityEngine.Rect _bounds; // bounds with positions[start] as origin
readonly float[] _positions;
}

string _text;
int _textOffset;
int _size;
float _minX, _minY, _width, _height;
UnityEngine.Rect _bounds;
public void allocRunPos(painting.TextStyle style, string text, int offset, int size,
float textScaleFactor = 1.0f) {

this._positions = positions;
}
public void setBounds(float minX, float minY, float width, float height) {
this._minX = minX;
this._minY = minY;
this._width = width;
this._height = height;
}
this.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
this._bounds = bounds;
this._size, this._positions, this._minX, this._minY, this._width, this._height, this._style);
this._size, this._positions, this._bounds, this._style);
return result;
}
}

12
Runtime/ui/text.cs


}
public bool Equals(TextBox other) {
if (ReferenceEquals(null, other)) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
return this.left.Equals(other.left) && this.top.Equals(other.top) && this.right.Equals(other.right) &&
this.bottom.Equals(other.bottom) && this.direction == other.direction;
}

return false;
}
if (ReferenceEquals(this, obj)) {
return true;
}
if (obj.GetType() != this.GetType()) {

26
Runtime/ui/txt/layout_utils.cs


c == 0x205F || c == 0x3000;
}
public static int getPrevWordBreakForCache(TextBuff buff, int offset) {
int len = buff.size;
if (offset == 0) {
return 0;
}
if (offset > len) {
offset = len;
}
if (isWordBreakBefore(buff.charAt(offset - 1))) {
return offset - 1;
}
for (int i = offset - 1; i > 0; i--) {
// Since i steps down, isWordBreakAfter(i) has already been checked in the previous step
// isWordBreakBeforeNotAfter cuts that part out to save time.
if (isWordBreakBeforeNotAfter(buff.charAt(i)) || isWordBreakAfter(buff.charAt(i - 1))) {
return i;
}
}
return 0;
}
public static int getNextWordBreak(string text, int offset, int maxOffset) {
int len = text.Length;

public static bool isWordBreakBefore(ushort c) {
return isWordBreakAfter(c) || (c >= 0x3400 && c <= 0x9fff);
}
public static bool isWordBreakBeforeNotAfter(ushort c) {
return c >= 3400 && c <= 0x9fff;
}
public static int minPowerOfTwo(int i) {

2
Tests/Editor/CanvasAndLayers.cs


canvas.scale(3);
TextBlobBuilder builder = new TextBlobBuilder();
string text = "This is a text blob";
builder.setBounds(-10, -20, 200, 50);
builder.setBounds(new Rect(-10, -20, 200, 50));
builder.setPositions(new float[] {
10,
20,

正在加载...
取消
保存