浏览代码

Use a pool to manage the paragraphs.

/main
Yuncong Zhang 5 年前
当前提交
396535c6
共有 4 个文件被更改,包括 32 次插入7 次删除
  1. 16
      Runtime/painting/text_painter.cs
  2. 2
      Runtime/rendering/paragraph.cs
  3. 19
      Runtime/ui/txt/paragraph.cs
  4. 2
      Runtime/ui/txt/paragraph_builder.cs

16
Runtime/painting/text_painter.cs


this._ellipsis = ellipsis;
}
public void releaseParagraph() {
Paragraph.release(ref this._paragraph);
}
public float textScaleFactor {
get { return this._textScaleFactor; }

}
this._textScaleFactor = value;
this._paragraph = null;
Paragraph.release(ref this._paragraph);
}
}

}
this._ellipsis = value;
this._paragraph = null;
Paragraph.release(ref this._paragraph);
this._needsLayout = true;
}
}

}
this._text = value;
this._paragraph = null;
Paragraph.release(ref this._paragraph);
this._needsLayout = true;
}
}

}
this._textDirection = value;
this._paragraph = null;
Paragraph.release(ref this._paragraph);
this._layoutTemplate = null;
this._needsLayout = true;
}

}
this._textAlign = value;
this._paragraph = null;
Paragraph.release(ref this._paragraph);
this._needsLayout = true;
}
}

}
this._maxLines = value;
this._paragraph = null;
Paragraph.release(ref this._paragraph);
this._needsLayout = true;
}
}

2
Runtime/rendering/paragraph.cs


if (this._hoverAnnotation != null) {
RendererBinding.instance.mouseTracker.detachAnnotation(this._hoverAnnotation);
}
this._textPainter?.releaseParagraph();
}
TextSelection _selection;

19
Runtime/ui/txt/paragraph.cs


public bool didExceedMaxLines {
get { return this._didExceedMaxLines; }
}
static List<Paragraph> _paragraphs = new List<Paragraph>();
public static Paragraph create() {
if (_paragraphs.isEmpty()) {
return new Paragraph();
}
Paragraph ret = _paragraphs.last();
_paragraphs.RemoveAt(_paragraphs.Count-1);
return ret;
}
public static void release(ref Paragraph paragraph) {
if (paragraph != null) {
_paragraphs.Add(paragraph);
paragraph = null;
}
}
public void paint(Canvas canvas, Offset offset) {
for (int i = 0; i < this._paintRecordsCount; i++) {

2
Runtime/ui/txt/paragraph_builder.cs


public Paragraph build() {
this._runs.endRunIfNeeded(this._text.Length);
var paragraph = new Paragraph();
var paragraph = Paragraph.create();
paragraph.setText(this._text.ToString(), this._runs);
paragraph.setParagraphStyle(this._paragraphStyle);
return paragraph;

正在加载...
取消
保存