浏览代码

Change bounds into four floats.

/main
Yuncong Zhang 5 年前
当前提交
79e9b237
共有 3 个文件被更改,包括 43 次插入26 次删除
  1. 53
      Runtime/ui/painting/txt/text_blob.cs
  2. 8
      Runtime/ui/txt/layout.cs
  3. 8
      Tests/Editor/CanvasAndLayers.cs

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


namespace Unity.UIWidgets.ui {
using UnityEditor.Rendering;
namespace Unity.UIWidgets.ui {
internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions, Rect bounds,
TextStyle style) {
internal TextBlob(string text, int textOffset, int textSize, Vector2d[] positions,
float minX, float minY, float width, float height, TextStyle style) {
this.bounds = bounds;
this._minX = minX;
this._minY = minY;
this._width = width;
this._height = height;
get { return this.bounds.translate(this._positions[this.textOffset].x, this._positions[this.textOffset].y); }
get {
var pos = this._positions[this.textOffset];
return Rect.fromLTWH(this._minX + pos.x, this._minY + pos.y, this._width, this._height);
}
return this.bounds.translate(this._positions[this.textOffset].x + offset.dx,
this._positions[this.textOffset].y + offset.dy);
var pos = this._positions[this.textOffset];
pos.x += offset.dx;
pos.y += offset.dy;
return Rect.fromLTWH(this._minX + pos.x, this._minY + pos.y, this._width, this._height);
}
public Vector2d getPosition(int i) {

internal readonly int textOffset;
internal readonly int textSize;
internal readonly TextStyle style;
internal readonly Rect bounds; // bounds with positions[start] as origin
readonly float _minX, _minY, _width, _height; // bounds with positions[start] as origin
public Vector2d[] positions;
Vector2d[] _positions;
Rect _bounds;
float _minX, _minY, _width, _height;
public void allocRunPos(painting.TextStyle style, string text, int offset, int size,
float textScaleFactor = 1.0f) {

}
internal void allocPos(int size) {
if (this.positions == null || this.positions.Length < size) {
this.positions = new Vector2d[size];
if (this._positions == null || this._positions.Length < size) {
this._positions = new Vector2d[size];
this.positions[this._textOffset + i] = position;
this._positions[this._textOffset + i] = position;
public void setBounds(Rect bounds) {
this._bounds = bounds;
public void setPositions(Vector2d[] positions) {
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;
}
public void setBounds(UnityEngine.Rect bounds) {
this.setBounds(bounds.x, bounds.y, bounds.width, bounds.height);
this._size, this.positions, this._bounds, this._style);
this._size, this._positions, this._minX, this._minY, this._width, this._height, this._style);
return result;
}
}

8
Runtime/ui/txt/layout.cs


return this._advances[index];
}
public Rect getBounds() {
return Rect.fromLTWH(this._bounds.x, this._bounds.y, this._bounds.width, this._bounds.height);
}
public Rect translatedBounds() {
return Rect.fromLTWH(this._bounds.x - this._positions[0],
public UnityEngine.Rect translatedBounds() {
return new UnityEngine.Rect(this._bounds.x - this._positions[0],
this._bounds.y, this._bounds.width, this._bounds.height);
}
}

8
Tests/Editor/CanvasAndLayers.cs


canvas.scale(3);
TextBlobBuilder builder = new TextBlobBuilder();
string text = "This is a text blob";
builder.allocRunPos(new TextStyle(), text, 0, text.Length);
builder.setBounds(Unity.UIWidgets.ui.Rect.fromLTWH(-10, -20, 200, 50));
builder.positions = new Vector2d[] {
builder.setBounds(-10, -20, 200, 50);
builder.setPositions(new [] {
new Vector2d(10, 0),
new Vector2d(20, 0),
new Vector2d(30, 0),

new Vector2d(170, 0),
new Vector2d(180, 0),
new Vector2d(190, 0),
};
});
builder.allocRunPos(new TextStyle(), text, 0, text.Length);
var textBlob = builder.make();
canvas.drawTextBlob(textBlob, new Offset(100, 100), new Paint {

正在加载...
取消
保存