diff --git a/internal/ui/render.go b/internal/ui/render.go index 3cdeee0..d256975 100644 --- a/internal/ui/render.go +++ b/internal/ui/render.go @@ -250,24 +250,33 @@ func (r *Renderer) drawLineText(gtx layout.Context, shp *text.Shaper, x, y unit. m := op.Record(gtx.Ops) var glyphs [32]text.Glyph line := glyphs[:0] + var firstGlyph text.Glyph + first := true for g, ok := shp.NextGlyph(); ok; g, ok = shp.NextGlyph() { + if first { + firstGlyph = g + first = false + } line = append(line, g) if g.Flags&text.FlagLineBreak != 0 || cap(line)-len(line) == 0 { - r.drawLine(gtx, shp, line, x, y, col) + r.drawLine(gtx, shp, line, firstGlyph, x, y, col) line = line[:0] } } if len(line) > 0 { - r.drawLine(gtx, shp, line, x, y, col) + r.drawLine(gtx, shp, line, firstGlyph, x, y, col) } call := m.Stop() call.Add(gtx.Ops) } // drawLine draws a line of glyphs using shaper.Shape() and shaper.Bitmaps(). -func (r *Renderer) drawLine(gtx layout.Context, shp *text.Shaper, line []text.Glyph, x, y unit.Dp, col color.NRGBA) { - // Apply offset transform - off := f32.Point{X: float32(x), Y: float32(y)} +func (r *Renderer) drawLine(gtx layout.Context, shp *text.Shaper, line []text.Glyph, firstGlyph text.Glyph, x, y unit.Dp, col color.NRGBA) { + // Derive offset from first glyph position + desired position + // Gio's textView: lineOff = glyphPos - viewportMin + // We want: offset = (x, y) - firstGlyphPos + firstPos := f32.Point{X: float32(firstGlyph.X) / 64.0, Y: float32(firstGlyph.Y)} + off := f32.Point{X: float32(x), Y: float32(y)}.Sub(firstPos) t := op.Affine(f32.Affine2D{}.Offset(off)).Push(gtx.Ops) // Draw vector glyphs