您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
69 行
2.3 KiB
69 行
2.3 KiB
namespace Unity.UIWidgets.ui {
|
|
public class TextBlob {
|
|
|
|
internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions, Rect bounds, TextStyle style) {
|
|
this.instanceId = ++_nextInstanceId;
|
|
this.positions = positions;
|
|
this.text = text;
|
|
this.textOffset = textOffset;
|
|
this.textSize = textSize;
|
|
this.style = style;
|
|
this.bounds = bounds;
|
|
}
|
|
|
|
public Rect boundsInText {
|
|
get {
|
|
if (this._boundsInText == null) {
|
|
this._boundsInText = this.bounds.shift(new Offset(this.positions[0].x, this.positions[0].y));
|
|
}
|
|
|
|
return this._boundsInText;
|
|
}
|
|
}
|
|
|
|
static long _nextInstanceId = 0;
|
|
internal readonly long instanceId;
|
|
internal readonly string text;
|
|
internal readonly int textOffset;
|
|
internal readonly int textSize;
|
|
internal readonly Vector2d[] positions;
|
|
internal readonly TextStyle style;
|
|
internal readonly Rect bounds; // bounds with positions[start] as origin
|
|
|
|
Rect _boundsInText;
|
|
}
|
|
|
|
public class TextBlobBuilder {
|
|
TextStyle _style;
|
|
public Vector2d[] positions;
|
|
string _text;
|
|
int _textOffset;
|
|
int _size;
|
|
Rect _bounds;
|
|
|
|
public void allocRunPos(painting.TextStyle style, string text, int offset, int size, float textScaleFactor = 1.0f) {
|
|
this.allocRunPos(TextStyle.applyStyle(null, style, textScaleFactor), text, offset, size);
|
|
}
|
|
|
|
internal void allocRunPos(TextStyle style, string text, int offset, int size) {
|
|
this._style = style;
|
|
this._text = text;
|
|
this._textOffset = offset;
|
|
this._size = size;
|
|
if (this.positions == null || this.positions.Length < size) {
|
|
this.positions = new Vector2d[size];
|
|
}
|
|
}
|
|
|
|
public void setBounds(Rect bounds) {
|
|
this._bounds = bounds;
|
|
}
|
|
|
|
public TextBlob make() {
|
|
var result = new TextBlob(this._text, this._textOffset,
|
|
this._size, this.positions, this._bounds, this._style);
|
|
this.positions = null;
|
|
return result;
|
|
}
|
|
}
|
|
}
|