From 8dc03ed655e7ddff3d8c8508932933001b16de0d Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Fri, 21 Jul 2023 13:14:42 -0400 Subject: [PATCH] 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 --- text/gotext.go | 6 +++--- widget/index_test.go | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/text/gotext.go b/text/gotext.go index 700370b2..e0a2de92 100644 --- a/text/gotext.go +++ b/text/gotext.go @@ -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 } } diff --git a/widget/index_test.go b/widget/index_test.go index 7442245a..1bf8836f 100644 --- a/widget/index_test.go +++ b/widget/index_test.go @@ -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),