text,widget: remove fractional line height

The previous logic kept the y offset of a line as a fractional value
until the last possible moment in an effort to be as true to a fractional
line height as possible (minimize the error), but this interacts pathologically
with multi-line text selections, as the selections may have visibly different
gaps between lines. It's better to always shift lines by a fixed quantity of
whole pixels, even if it is technically less accurate to the desired line height.

Signed-off-by: Chris Waldon <christopher.waldon.dev@gmail.com>
This commit is contained in:
Chris Waldon
2023-07-21 13:14:42 -04:00
committed by Elias Naur
parent 1d8b54892a
commit 8dc03ed655
2 changed files with 11 additions and 11 deletions
+3 -3
View File
@@ -513,12 +513,12 @@ func calculateYOffsets(lines []line) {
}
// Ceil the first value to ensure that we don't baseline it too close to the top of the
// viewport and cut off the top pixel.
currentY := fixed.I(lines[0].ascent.Ceil())
currentY := lines[0].ascent.Ceil()
for i := range lines {
if i > 0 {
currentY += lines[i].lineHeight
currentY += lines[i].lineHeight.Round()
}
lines[i].yOffset = currentY.Round()
lines[i].yOffset = currentY
}
}
+8 -8
View File
@@ -167,10 +167,10 @@ func TestIndexPositionWhitespace(t *testing.T) {
{x: fixed.Int26_6(832), y: 16, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216)},
{x: fixed.Int26_6(832), y: 35, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 1, lineCol: screenPos{line: 1}},
{x: fixed.Int26_6(832), y: 54, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 2, lineCol: screenPos{line: 2}},
{x: fixed.Int26_6(6), y: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 3, lineCol: screenPos{line: 3}},
{x: fixed.Int26_6(576), y: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 4, lineCol: screenPos{line: 3, col: 1}},
{x: fixed.Int26_6(1146), y: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 5, lineCol: screenPos{line: 3, col: 2}},
{x: fixed.Int26_6(1658), y: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 6, lineCol: screenPos{line: 3, col: 3}},
{x: fixed.Int26_6(6), y: 73, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 3, lineCol: screenPos{line: 3}},
{x: fixed.Int26_6(576), y: 73, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 4, lineCol: screenPos{line: 3, col: 1}},
{x: fixed.Int26_6(1146), y: 73, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 5, lineCol: screenPos{line: 3, col: 2}},
{x: fixed.Int26_6(1658), y: 73, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 6, lineCol: screenPos{line: 3, col: 3}},
},
},
{
@@ -341,7 +341,7 @@ func TestIndexPositionLines(t *testing.T) {
},
{
xOff: fixed.Int26_6(0),
yOff: 80,
yOff: 79,
glyphs: 4,
width: fixed.Int26_6(2034),
ascent: fixed.Int26_6(968),
@@ -380,7 +380,7 @@ func TestIndexPositionLines(t *testing.T) {
},
{
xOff: fixed.Int26_6(0),
yOff: 80,
yOff: 79,
glyphs: 4,
width: fixed.Int26_6(2034),
ascent: fixed.Int26_6(968),
@@ -419,7 +419,7 @@ func TestIndexPositionLines(t *testing.T) {
},
{
xOff: fixed.Int26_6(8206),
yOff: 80,
yOff: 79,
glyphs: 4,
width: fixed.Int26_6(2034),
ascent: fixed.Int26_6(968),
@@ -458,7 +458,7 @@ func TestIndexPositionLines(t *testing.T) {
},
{
xOff: fixed.Int26_6(8206),
yOff: 80,
yOff: 79,
glyphs: 4,
width: fixed.Int26_6(2034),
ascent: fixed.Int26_6(968),