Various fixes for empty text blocks + don't add ellipsis if last line includes all text.
This commit is contained in:
Родитель
e4e5420d91
Коммит
ef354674d9
|
@ -7,7 +7,7 @@ namespace SandboxDriver
|
|||
{
|
||||
public class SandboxDriver
|
||||
{
|
||||
public int ContentModeCount = 10;
|
||||
public int ContentModeCount = 11;
|
||||
public int ContentMode = 0;
|
||||
public TextDirection BaseDirection = TextDirection.LTR;
|
||||
public TextAlignment TextAlignment = TextAlignment.Auto;
|
||||
|
@ -185,6 +185,10 @@ namespace SandboxDriver
|
|||
_textBlock.AddText("Hello World", styleNormal);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
_textBlock.AddText("", styleNormal);
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
var sw = new Stopwatch();
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace Topten.RichTextKit
|
|||
/// <summary>
|
||||
/// The X-coordinate where the caret should be displayed for this code point.
|
||||
/// </summary>
|
||||
public float CaretXCoord => FontRun.GetXCoordOfCodePointIndex(CodePointIndex);
|
||||
public float CaretXCoord => CodePointIndex < 0 ? 0 : FontRun.GetXCoordOfCodePointIndex(CodePointIndex);
|
||||
|
||||
/// <summary>
|
||||
/// A rectangle describing where the caret should be drawn, relative to the top-left
|
||||
|
@ -79,6 +79,9 @@ namespace Topten.RichTextKit
|
|||
{
|
||||
get
|
||||
{
|
||||
if (CodePointIndex < 0)
|
||||
return SKRect.Empty;
|
||||
|
||||
// Get the font run to be used for caret metrics
|
||||
var fr = GetFontRunForCaretMetrics();
|
||||
|
||||
|
|
|
@ -248,14 +248,18 @@ namespace Topten.RichTextKit
|
|||
_minLeftMargin = 0;
|
||||
_requiredLeftMargin = null;
|
||||
|
||||
// Build font runs
|
||||
BuildFontRuns();
|
||||
// Only layout if actually have some text
|
||||
if (_codePoints.Length != 0)
|
||||
{
|
||||
// Build font runs
|
||||
BuildFontRuns();
|
||||
|
||||
// Break font runs into lines
|
||||
BreakLines();
|
||||
// Break font runs into lines
|
||||
BreakLines();
|
||||
|
||||
// Finalize lines
|
||||
FinalizeLines();
|
||||
// Finalize lines
|
||||
FinalizeLines();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -609,6 +613,18 @@ namespace Topten.RichTextKit
|
|||
/// <returns>A CaretInfo struct</returns>
|
||||
public CaretInfo GetCaretInfo(int codePointIndex)
|
||||
{
|
||||
if (_codePoints.Length == 0 || codePointIndex < 0)
|
||||
{
|
||||
return new CaretInfo()
|
||||
{
|
||||
CodePointIndex = -1,
|
||||
NextCodePointIndex = -1,
|
||||
PreviousCodePointIndex = -1,
|
||||
FontRun = null,
|
||||
StyleRun = null,
|
||||
};
|
||||
}
|
||||
|
||||
// Look up the caret index
|
||||
int cpii = LookupCaretIndex(codePointIndex);
|
||||
|
||||
|
@ -1476,6 +1492,11 @@ namespace Topten.RichTextKit
|
|||
{
|
||||
var lastRun = line.Runs[line.Runs.Count - 1];
|
||||
|
||||
// Don't add ellipsis if the last run actually
|
||||
// has all the text...
|
||||
if (lastRun.End == _codePoints.Length)
|
||||
return;
|
||||
|
||||
// Remove all trailing whitespace from the line
|
||||
for (int i = line.Runs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче