Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 952718c

Browse files
author
Yuncong Zhang
committed
Code cleanup.
1 parent ba811f7 commit 952718c

File tree

8 files changed

+46
-54
lines changed

8 files changed

+46
-54
lines changed

Runtime/ui/painting/txt/text_blob.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace Unity.UIWidgets.ui {
22
public struct TextBlob {
3-
43
internal TextBlob(string text, int textOffset, int textSize, float[] positions,
54
UnityEngine.Rect bounds, TextStyle style) {
65
this.instanceId = ++_nextInstanceId;
@@ -16,14 +15,14 @@ public Rect boundsInText {
1615
get {
1716
var pos = this.getPosition(0);
1817
return Rect.fromLTWH(this._bounds.xMin + pos, this._bounds.yMin,
19-
this._bounds.width, this._bounds.height);
18+
this._bounds.width, this._bounds.height);
2019
}
2120
}
2221

2322
public Rect shiftedBoundsInText(Offset offset) {
2423
var pos = this.getPosition(0);
2524
return Rect.fromLTWH(this._bounds.xMin + pos + offset.dx, this._bounds.yMin + offset.dy,
26-
this._bounds.width, this._bounds.height);
25+
this._bounds.width, this._bounds.height);
2726
}
2827

2928
public float getPosition(int i) {

Runtime/ui/txt/emoji.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public static Image image {
233233
{0x2935, 1224}, {0x2b05, 1225}, {0x2b06, 1226}, {0x2b07, 1227}, {0x2b1b, 1228}, {0x2b1c, 1229},
234234
{0x2b50, 1230}, {0x2b55, 1231}, {0x3030, 1232}, {0x303d, 1233}, {0x3297, 1234}, {0x3299, 1235},
235235
};
236-
236+
237237
public static readonly HashSet<int> SingleCharEmojiCodePoints = new HashSet<int> {
238238
0x203c, 0x2049, 0x2122, 0x2139, 0x2194,
239239
0x2195, 0x2196, 0x2197, 0x2198, 0x2199, 0x21a9,

Runtime/ui/txt/layout_utils.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ public static bool isLineEndSpace(char c) {
1111
c == 0x205F || c == 0x3000;
1212
}
1313

14-
14+
1515
public static int getNextWordBreak(string text, int offset, int maxOffset) {
1616
int len = text.Length;
1717
if (len > maxOffset) {
1818
len = maxOffset + 1;
1919
}
20-
20+
2121
if (offset >= len) {
2222
return len;
2323
}
@@ -38,7 +38,7 @@ public static int getNextWordBreak(string text, int offset, int maxOffset) {
3838
public static bool isWordBreakAfter(ushort c) {
3939
return isWordSpace(c) || (c >= 0x2000 && c <= 0x200a) || c == 0x3000;
4040
}
41-
41+
4242
public static bool isWordBreakBefore(ushort c) {
4343
return isWordBreakAfter(c) || (c >= 0x3400 && c <= 0x9fff);
4444
}
@@ -53,6 +53,5 @@ public static int minPowerOfTwo(int i) {
5353
i = i | (i >> 16);
5454
return i + 1;
5555
}
56-
5756
}
5857
}

Runtime/ui/txt/linebreaker.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ public int lineLimit {
6868

6969
public static LineBreaker instance {
7070
get {
71-
if(_instance == null)
71+
if (_instance == null) {
7272
_instance = new LineBreaker();
73+
}
74+
7375
return _instance;
7476
}
7577
}
@@ -96,6 +98,7 @@ public static int[] newLinePositions(string text, out int count) {
9698
_newLinePositions[count++] = i;
9799
}
98100
}
101+
99102
_newLinePositions[count++] = text.Length;
100103

101104
return _newLinePositions;
@@ -121,7 +124,7 @@ public static int[] newLinePositions(string text, out int count) {
121124
int mFirstTabIndex;
122125
List<Candidate> _candidates = new List<Candidate>();
123126
int _candidatesCount = 0;
124-
127+
125128
public int computeBreaks() {
126129
int nCand = this._candidatesCount;
127130
if (nCand > 0 && (nCand == 1 || this._lastBreak != nCand - 1)) {
@@ -233,12 +236,11 @@ public void setTabStops(TabStops tabStops) {
233236

234237
void _addWordBreak(int offset, float preBreak, float postBreak, int preSpaceCount, int postSpaceCount,
235238
float penalty) {
236-
237239
float width = this._candidates[this._candidatesCount - 1].preBreak;
238240
if (postBreak - width > this._lineWidth) {
239241
this._addCandidatesInsideWord(width, offset, postSpaceCount);
240242
}
241-
243+
242244
this._addCandidate(new Candidate {
243245
offset = offset,
244246
preBreak = preBreak,
@@ -285,6 +287,7 @@ void _addCandidate(Candidate cand) {
285287
if (this._bestBreak == this._lastBreak) {
286288
this._bestBreak = candIndex;
287289
}
290+
288291
this._pushGreedyBreak();
289292
}
290293

@@ -296,9 +299,11 @@ void _addCandidate(Candidate cand) {
296299
this._bestScore = penalty;
297300
}
298301
}
302+
299303
if (this._bestBreak == this._lastBreak) {
300304
this._bestBreak = candIndex;
301305
}
306+
302307
this._pushGreedyBreak();
303308
}
304309

Runtime/ui/txt/paragraph.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4-
using System.Linq;
54
using Unity.UIWidgets.foundation;
65
using UnityEngine;
76

@@ -183,7 +182,9 @@ public LineRange(int start, int end, int endExcludingWhitespace, int endIncludin
183182

184183
ParagraphStyle _paragraphStyle;
185184
List<LineRange> _lineRanges = new List<LineRange>();
185+
186186
List<float> _lineWidths = new List<float>();
187+
187188
// float[] _lineBaseLines;
188189
GlyphLine[] _glyphLines;
189190
GlyphPosition[] _glyphPositions;
@@ -247,7 +248,7 @@ public float ideographicBaseline {
247248
public bool didExceedMaxLines {
248249
get { return this._didExceedMaxLines; }
249250
}
250-
251+
251252
static List<Paragraph> _paragraphs = new List<Paragraph>();
252253

253254
public static Paragraph create() {
@@ -256,7 +257,7 @@ public static Paragraph create() {
256257
}
257258

258259
Paragraph ret = _paragraphs.last();
259-
_paragraphs.RemoveAt(_paragraphs.Count-1);
260+
_paragraphs.RemoveAt(_paragraphs.Count - 1);
260261
return ret;
261262
}
262263

@@ -300,7 +301,7 @@ public void layout(ParagraphConstraints constraints) {
300301
this._width = Mathf.Floor(constraints.width);
301302

302303
int lineStyleRunsCount = this._computeLineBreak();
303-
304+
304305
if (this._glyphLines == null || this._glyphLines.Length < this._lineRangeCount) {
305306
this._glyphLines = new GlyphLine[LayoutUtils.minPowerOfTwo(this._lineRangeCount)];
306307
}
@@ -316,7 +317,7 @@ public void layout(ParagraphConstraints constraints) {
316317
if (this._paintRecords == null || this._paintRecords.Length < lineStyleRunsCount) {
317318
this._paintRecords = new PaintRecord[LayoutUtils.minPowerOfTwo(lineStyleRunsCount)];
318319
}
319-
320+
320321
this._paintRecordsCount = 0;
321322

322323
if (this._codeUnitRuns == null || this._codeUnitRuns.Length < lineStyleRunsCount) {
@@ -336,11 +337,12 @@ public void layout(ParagraphConstraints constraints) {
336337

337338
TextBlobBuilder builder = new TextBlobBuilder();
338339
int ellipsizedLength = this._text.Length + (this._paragraphStyle.ellipsis?.Length ?? 0);
339-
340+
340341
// All text blobs share a single position buffer, which is big enough taking ellipsis into consideration
341342
if (this._textBlobPositions == null || this._textBlobPositions.Length < ellipsizedLength) {
342343
this._textBlobPositions = new float[LayoutUtils.minPowerOfTwo(ellipsizedLength)];
343344
}
345+
344346
builder.setPositions(this._textBlobPositions);
345347
// this._glyphLines and this._codeUnitRuns will refer to this array for glyph positions
346348
if (this._glyphPositions == null || this._glyphPositions.Length < ellipsizedLength) {
@@ -349,7 +351,7 @@ public void layout(ParagraphConstraints constraints) {
349351

350352
// Pointer to the _glyphPositions array, to keep track of where the next glyph is stored
351353
int pGlyphPositions = 0;
352-
354+
353355
// Compute max(NumberOfWords(line) for line in lines), to determine the size of word buffers
354356
int maxWordCount = this._computeMaxWordCount();
355357

@@ -387,6 +389,7 @@ public void layout(ParagraphConstraints constraints) {
387389
(lineNumber == lineLimit - 1 || this._paragraphStyle.maxLines == null)) {
388390
maxTextCount += ellipsis.Length;
389391
}
392+
390393
// Allocate the advances and positions to store the layout result
391394
// TODO: find a way to compute the maxTextCount for the entire paragraph, so that this allocation
392395
// happens only once
@@ -439,13 +442,14 @@ public void layout(ParagraphConstraints constraints) {
439442
int truncateCount = Layout.computeTruncateCount(runXOffset, text, textStart,
440443
textCount, style, this._width - ellipsisWidth, this._tabStops);
441444

442-
if(!(this._ellipsizedLength == textStart + textCount - truncateCount &&
443-
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
444-
this._ellipsizedText.EndsWith(ellipsis))) {
445+
if (!(this._ellipsizedLength == textStart + textCount - truncateCount &&
446+
this._ellipsizedText.Length == this._ellipsizedLength + ellipsis.Length &&
447+
this._ellipsizedText.EndsWith(ellipsis))) {
445448
this._ellipsizedText =
446449
text.Substring(0, textStart + textCount - truncateCount) + ellipsis;
447450
this._ellipsizedLength = this._ellipsizedText.Length - ellipsis.Length;
448451
}
452+
449453
text = this._ellipsizedText;
450454
textCount = text.Length - textStart;
451455
D.assert(textCount != 0);
@@ -511,7 +515,7 @@ public void layout(ParagraphConstraints constraints) {
511515
this._codeUnitRuns[this._codeUnitRunsCount++] = new CodeUnitRun(
512516
new Range<int>(start, end),
513517
new Range<float>(this._glyphPositions[glyphPositionStyleRunStart].xPos.start,
514-
this._glyphPositions[pGlyphPositions-1].xPos.end),
518+
this._glyphPositions[pGlyphPositions - 1].xPos.end),
515519
lineNumber, TextDirection.ltr, glyphPositionStyleRunStart, textCount);
516520

517521
lineStyleRunIndex++;
@@ -562,7 +566,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
562566
}
563567

564568
this._lineHeights[lineNumber] = ((lineNumber == 0 ? 0 : this._lineHeights[lineNumber - 1])
565-
+ Mathf.Round(maxLineSpacing + maxDescent));
569+
+ Mathf.Round(maxLineSpacing + maxDescent));
566570
// this._lineBaseLines[lineNumber] = this._lineHeights[lineNumber] - maxDescent;
567571
yOffset += Mathf.Round(maxLineSpacing + preMaxDescent);
568572
preMaxDescent = maxDescent;
@@ -578,7 +582,7 @@ void updateLineMetrics(FontMetrics metrics, float styleHeight) {
578582
int nextLineStart = lineNumber < this._lineRangeCount - 1
579583
? this._lineRanges[lineNumber + 1].start
580584
: this._text.Length;
581-
this._glyphLines[lineNumber] =
585+
this._glyphLines[lineNumber] =
582586
new GlyphLine(glyphPositionLineStart, count, nextLineStart - lineStart);
583587
for (int i = 0; i < lineStyleRunCount; i++) {
584588
var paintRecord = this._paintRecords[this._paintRecordsCount - 1 - i];
@@ -751,6 +755,7 @@ internal PositionWithAffinity getGlyphPositionAtCoordinate(float dx, float dy) {
751755
for (int i = 0; i < yIndex; i++) {
752756
lineStartIndex += this._glyphLines[i].totalCountUnits;
753757
}
758+
754759
return new PositionWithAffinity(lineStartIndex, TextAffinity.downstream);
755760
}
756761

@@ -843,18 +848,20 @@ int _computeLineBreak() {
843848
if (lineLimit != 0 && this._lineRangeCount >= lineLimit) {
844849
break;
845850
}
851+
846852
var blockStart = newlineIndex > 0 ? newLinePositions[newlineIndex - 1] + 1 : 0;
847853
var blockEnd = newLinePositions[newlineIndex];
848854
var blockSize = blockEnd - blockStart;
849855
if (blockSize == 0) {
850856
this._addEmptyLine(blockStart, blockEnd);
851857
continue;
852858
}
859+
853860
if (lineLimit != 0 && this._lineRangeCount >= lineLimit) {
854861
break;
855862
}
856863

857-
this._resetLineBreaker(lineBreaker, blockStart, blockSize,
864+
this._resetLineBreaker(lineBreaker, blockStart, blockSize,
858865
lineLimit == 0 ? 0 : lineLimit - this._lineRangeCount);
859866
countRuns += this._addStyleRuns(lineBreaker, ref runIndex, blockStart, blockEnd);
860867

Runtime/ui/txt/text_buff.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Unity.UIWidgets.foundation;
32

43
namespace Unity.UIWidgets.ui {

Runtime/ui/txt/wordbreaker.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
namespace Unity.UIWidgets.ui {
32
struct WordBreaker {
43
public const uint U16_SURROGATE_OFFSET = ((0xd800 << 10) + 0xdc00 - 0x10000);
@@ -97,9 +96,9 @@ int _findNextBoundaryNormal() {
9796
if (preBoundaryChar) {
9897
return this._current;
9998
}
100-
99+
101100
this._findBoundaryCharOrTypeChange(preWhiteSpace);
102-
101+
103102
return this._current;
104103
}
105104

@@ -119,10 +118,11 @@ void _findBoundaryCharOrTypeChange(bool preWhiteSpace) {
119118
if (currentType != preWhiteSpace) {
120119
break;
121120
}
121+
122122
preWhiteSpace = currentType;
123123
}
124124
}
125-
125+
126126
void _detectEmailOrUrl() {
127127
}
128128

@@ -163,17 +163,17 @@ public static bool isTrailSurrogate(uint c) {
163163
}
164164

165165
public static uint getSupplementary(uint lead, uint trail) {
166-
return (char) ((lead << 10) + (trail - U16_SURROGATE_OFFSET));
166+
return (char) ((lead << 10) + (trail - U16_SURROGATE_OFFSET));
167167
}
168168

169169
public static bool isBoundaryChar(char code) {
170170
return (code >= 0x4E00 && code <= 0x9FFF) || (code >= 0x3040 && code <= 0x30FF) || char.IsPunctuation(code);
171171
}
172-
172+
173173
void nextUntilCodePoint() {
174174
while (this._current < this._text.size
175-
&& (char.IsLowSurrogate(this._text.charAt(this._current))
176-
|| char.IsHighSurrogate(this._text.charAt(this._current)))) {
175+
&& (char.IsLowSurrogate(this._text.charAt(this._current))
176+
|| char.IsHighSurrogate(this._text.charAt(this._current)))) {
177177
this._current++;
178178
}
179179
}

Tests/Editor/CanvasAndLayers.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -266,25 +266,8 @@ void drawLine() {
266266
string text = "This is a text blob";
267267
builder.setBounds(new Rect(-10, -20, 200, 50));
268268
builder.setPositions(new float[] {
269-
10,
270-
20,
271-
30,
272-
40,
273-
50,
274-
60,
275-
70,
276-
80,
277-
90,
278-
100,
279-
110,
280-
120,
281-
130,
282-
140,
283-
150,
284-
160,
285-
170,
286-
180,
287-
190
269+
10, 20, 30, 40, 50, 60, 70, 80, 90, 100,
270+
110, 120, 130, 140, 150, 160, 170, 180, 190
288271
});
289272
builder.allocRunPos(new TextStyle(), text, 0, text.Length);
290273

0 commit comments

Comments
 (0)