Fix filename rendering: split drawText into layout + drawLineText to avoid triple LayoutString calls
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
0f62ef32fa
commit
1acad99450
|
|
@ -230,9 +230,9 @@ func (r *Renderer) drawTruncatedText(gtx layout.Context, shp *text.Shaper, str s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-layout truncated text and draw
|
// Re-layout truncated text and draw glyphs directly
|
||||||
shp.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(size))}, fullStr)
|
shp.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(size))}, fullStr)
|
||||||
r.drawText(gtx, shp, fullStr, size, x, y, col)
|
r.drawLineText(gtx, shp, x, y, col)
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawText draws text using the same approach as Gio's textView:
|
// drawText draws text using the same approach as Gio's textView:
|
||||||
|
|
@ -240,8 +240,11 @@ func (r *Renderer) drawTruncatedText(gtx layout.Context, shp *text.Shaper, str s
|
||||||
func (r *Renderer) drawText(gtx layout.Context, shp *text.Shaper, str string, size unit.Sp, x, y unit.Dp, col color.NRGBA) {
|
func (r *Renderer) drawText(gtx layout.Context, shp *text.Shaper, str string, size unit.Sp, x, y unit.Dp, col color.NRGBA) {
|
||||||
// Layout text
|
// Layout text
|
||||||
shp.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(size))}, str)
|
shp.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(size))}, str)
|
||||||
|
r.drawLineText(gtx, shp, x, y, col)
|
||||||
|
}
|
||||||
|
|
||||||
// Draw glyphs using the same approach as Gio's textView
|
// drawLineText draws already-laid-out glyphs using shaper.Shape() and shaper.Bitmaps().
|
||||||
|
func (r *Renderer) drawLineText(gtx layout.Context, shp *text.Shaper, x, y unit.Dp, col color.NRGBA) {
|
||||||
var glyphs [32]text.Glyph
|
var glyphs [32]text.Glyph
|
||||||
line := glyphs[:0]
|
line := glyphs[:0]
|
||||||
for g, ok := shp.NextGlyph(); ok; g, ok = shp.NextGlyph() {
|
for g, ok := shp.NextGlyph(); ok; g, ok = shp.NextGlyph() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user