protected void Rebuild ()
{
if (isValid)
{
// Although we could simply use UILabel.Wrap, it would mean setting the same data
// over and over every paragraph, which is not ideal. It's faster to only do it once
// and then do wrapping ourselves in the 'for' loop below.
textLabel.UpdateNGUIText();
NGUIText.rectHeight = 1000000;
mTotalLines = 0;
bool success = true;
for (int i = 0; i < mParagraphs.size; ++i)
{
string final;
Paragraph p = mParagraphs.buffer[i];
if (NGUIText.WrapText(p.text, out final))
{
p.lines = final.Split('\n');
mTotalLines += p.lines.Length;
}
else
{
success = false;
break;
}
}
// Recalculate the total number of lines
mTotalLines = 0;
if (success)
{
for (int i = 0, imax = mParagraphs.size; i < imax; ++i)
mTotalLines += mParagraphs.buffer[i].lines.Length;
}
// Update the bar's size
if (scrollBar != null)
{
UIScrollBar sb = scrollBar as UIScrollBar;
if (sb != null) sb.barSize = (mTotalLines == 0) ? 1f : 1f - (float)scrollHeight / mTotalLines;
}
// Update the visible text
UpdateVisibleText();
}
}