浏览代码

text overflow ellipsis

/main
fzhangtj 6 年前
当前提交
8dfa86bc
共有 1 个文件被更改,包括 34 次插入2 次删除
  1. 36
      Runtime/ui/txt/paragraph.cs

36
Runtime/ui/txt/paragraph.cs


List<PaintRecord> paintRecords = new List<PaintRecord>();
for (int i = 0; i < lineRuns.Count; ++i) {
var run = lineRuns[i];
string text = this._text;
layout.doLayout(runXOffset, this._text, textStart, textCount, run.style);
string ellipsis = this._paragraphStyle.ellipsis;
if (!string.IsNullOrEmpty(ellipsis) && !this._width.isInfinite() && !lineRange.hardBreak
&& i == lineRuns.Count - 1 && (lineNumber == lineLimit - 1 || this._paragraphStyle.maxLines == null)) {
float ellipsisWidth = Layout.measureText(runXOffset, ellipsis, 0,
ellipsis.Length, run.style, null, 0, this._tabStops);
List<float> textAdvances = new List<float>(textCount);
for (int index = 0; index < textCount;++index) {
textAdvances.Add(0);
}
float textWidth = Layout.measureText(runXOffset, this._text, textStart, textCount,
run.style, textAdvances, 0, this._tabStops);
int truncateCount = 0;
while (truncateCount < textCount &&
runXOffset + textWidth + ellipsisWidth > this._width) {
textWidth -= textAdvances[textCount - truncateCount - 1];
truncateCount++;
}
var ellipsizedText = this._text.Substring(textStart, textCount - truncateCount) + ellipsis;
textStart = 0;
textCount = ellipsizedText.Length;
text = ellipsizedText;
if (this._paragraphStyle.maxLines == null) {
lineLimit = lineNumber + 1;
this._didExceedMaxLines = true;
}
}
layout.doLayout(runXOffset, text, textStart, textCount, run.style);
if (layout.nGlyphs() == 0) {
continue;
}

builder.allocRunPos(run.style, this._text, textStart, textCount);
builder.allocRunPos(run.style, text, textStart, textCount);
builder.setBounds(layout.getBounds());
glyphPositions.Clear();

正在加载...
取消
保存