Browse Source

properly handle HitTestPoint in skia FormattedTextImpl

pull/559/head
donandren 10 years ago
parent
commit
6c423ae4c8
  1. 17
      src/Skia/Avalonia.Skia/FormattedTextImpl.cs

17
src/Skia/Avalonia.Skia/FormattedTextImpl.cs

@ -100,21 +100,22 @@ namespace Avalonia.Skia
return new TextHitTestResult return new TextHitTestResult
{ {
IsInside = false, IsInside = false,
TextPosition = line.Start + line.Length > 0 ? line.Length - 1 : 0, TextPosition = line.Start + (line.Length > 0 ? line.Length - 1 : 0),
IsTrailing = true IsTrailing = line.Length > 0
}; };
} }
else else
{ {
return new TextHitTestResult return new TextHitTestResult
{ {
IsInside = line.Length > 0, IsInside = false,
TextPosition = line.Start, TextPosition = line.Start,
IsTrailing = false IsTrailing = false
}; };
} }
} }
bool end = point.X > _size.Width || point.Y > _size.Height;
bool end = point.X > _size.Width || point.Y > _lines.Sum(l => l.Height);
return new TextHitTestResult() { IsTrailing = end, TextPosition = end ? _text.Length - 1 : 0 }; return new TextHitTestResult() { IsTrailing = end, TextPosition = end ? _text.Length - 1 : 0 };
} }
@ -175,6 +176,7 @@ namespace Avalonia.Skia
var mLeading = metrics.Leading; // The recommended distance to add between lines of text (will be >= 0). var mLeading = metrics.Leading; // The recommended distance to add between lines of text (will be >= 0).
var mDescent = metrics.Descent; var mDescent = metrics.Descent;
var mAscent = metrics.Ascent; var mAscent = metrics.Ascent;
var lastLineDescent = mBottom - mDescent;
// This seems like the best measure of full vertical extent // This seems like the best measure of full vertical extent
LineHeight = mDescent - mAscent; LineHeight = mDescent - mAscent;
@ -246,15 +248,14 @@ namespace Avalonia.Skia
if (_skiaLines.Count == 0) if (_skiaLines.Count == 0)
{ {
_size = new Size(); _lines.Add(new FormattedTextLine(0, LineHeight));
_size = new Size(0, LineHeight + lastLineDescent);
} }
else else
{ {
var lastLine = _skiaLines[_skiaLines.Count - 1]; var lastLine = _skiaLines[_skiaLines.Count - 1];
_size = new Size(maxX, lastLine.Top + lastLine.Height + mBottom - mDescent); _size = new Size(maxX, lastLine.Top + lastLine.Height + lastLineDescent);
} }
BuildRects();
} }
private List<Rect> GetRects() private List<Rect> GetRects()

Loading…
Cancel
Save