mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-06 18:05:35 +00:00
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:
+3
-3
@@ -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
|
// 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.
|
// viewport and cut off the top pixel.
|
||||||
currentY := fixed.I(lines[0].ascent.Ceil())
|
currentY := lines[0].ascent.Ceil()
|
||||||
for i := range lines {
|
for i := range lines {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
currentY += lines[i].lineHeight
|
currentY += lines[i].lineHeight.Round()
|
||||||
}
|
}
|
||||||
lines[i].yOffset = currentY.Round()
|
lines[i].yOffset = currentY
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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: 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: 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(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(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: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 4, lineCol: screenPos{line: 3, col: 1}},
|
{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: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 5, lineCol: screenPos{line: 3, col: 2}},
|
{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: 74, ascent: fixed.Int26_6(968), descent: fixed.Int26_6(216), runes: 6, lineCol: screenPos{line: 3, col: 3}},
|
{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),
|
xOff: fixed.Int26_6(0),
|
||||||
yOff: 80,
|
yOff: 79,
|
||||||
glyphs: 4,
|
glyphs: 4,
|
||||||
width: fixed.Int26_6(2034),
|
width: fixed.Int26_6(2034),
|
||||||
ascent: fixed.Int26_6(968),
|
ascent: fixed.Int26_6(968),
|
||||||
@@ -380,7 +380,7 @@ func TestIndexPositionLines(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
xOff: fixed.Int26_6(0),
|
xOff: fixed.Int26_6(0),
|
||||||
yOff: 80,
|
yOff: 79,
|
||||||
glyphs: 4,
|
glyphs: 4,
|
||||||
width: fixed.Int26_6(2034),
|
width: fixed.Int26_6(2034),
|
||||||
ascent: fixed.Int26_6(968),
|
ascent: fixed.Int26_6(968),
|
||||||
@@ -419,7 +419,7 @@ func TestIndexPositionLines(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
xOff: fixed.Int26_6(8206),
|
xOff: fixed.Int26_6(8206),
|
||||||
yOff: 80,
|
yOff: 79,
|
||||||
glyphs: 4,
|
glyphs: 4,
|
||||||
width: fixed.Int26_6(2034),
|
width: fixed.Int26_6(2034),
|
||||||
ascent: fixed.Int26_6(968),
|
ascent: fixed.Int26_6(968),
|
||||||
@@ -458,7 +458,7 @@ func TestIndexPositionLines(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
xOff: fixed.Int26_6(8206),
|
xOff: fixed.Int26_6(8206),
|
||||||
yOff: 80,
|
yOff: 79,
|
||||||
glyphs: 4,
|
glyphs: 4,
|
||||||
width: fixed.Int26_6(2034),
|
width: fixed.Int26_6(2034),
|
||||||
ascent: fixed.Int26_6(968),
|
ascent: fixed.Int26_6(968),
|
||||||
|
|||||||
Reference in New Issue
Block a user