Add op.Record/Stop macro wrapping to drawLineText (matches Gio's textView)
Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
parent
1acad99450
commit
1ee75c1cd1
|
|
@ -94,28 +94,29 @@ func (r *Renderer) drawStatusBar(gtx layout.Context, sb StatusBar) {
|
||||||
|
|
||||||
// Truncate filename only if it doesn't fit
|
// Truncate filename only if it doesn't fit
|
||||||
displayFilename := sb.Filename
|
displayFilename := sb.Filename
|
||||||
availableWidth := int(reg.W - unit.Dp(8) - unit.Dp(40)) // left margin + right icons in DP
|
//availableWidth := int(reg.W - unit.Dp(8) - unit.Dp(40)) // left margin + right icons in DP
|
||||||
|
|
||||||
// Layout ellipsis once and get its width
|
// Layout ellipsis once and get its width
|
||||||
th.Shaper.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(r.theme.FontSize))}, "...")
|
//th.Shaper.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(r.theme.FontSize))}, "...")
|
||||||
var ellipsisWidths []int
|
//var ellipsisWidths []int
|
||||||
for {
|
//for {
|
||||||
g, ok := th.Shaper.NextGlyph()
|
// g, ok := th.Shaper.NextGlyph()
|
||||||
if !ok {
|
// if !ok {
|
||||||
break
|
// break
|
||||||
}
|
// }
|
||||||
if len(ellipsisWidths) == 0 {
|
// if len(ellipsisWidths) == 0 {
|
||||||
ellipsisWidths = append(ellipsisWidths, int(g.Advance>>6))
|
// ellipsisWidths = append(ellipsisWidths, int(g.Advance>>6))
|
||||||
} else {
|
// } else {
|
||||||
ellipsisWidths = append(ellipsisWidths, ellipsisWidths[len(ellipsisWidths)-1]+int(g.Advance>>6))
|
// ellipsisWidths = append(ellipsisWidths, ellipsisWidths[len(ellipsisWidths)-1]+int(g.Advance>>6))
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
ellipsisWidth := ellipsisWidths[len(ellipsisWidths)-1]
|
//ellipsisWidth := ellipsisWidths[len(ellipsisWidths)-1]
|
||||||
// Measure how wide "..." is, then find how many chars fit in availableWidth - ellipsisWidth
|
// Measure how wide "..." is, then find how many chars fit in availableWidth - ellipsisWidth
|
||||||
spaceForText := availableWidth - ellipsisWidth
|
//spaceForText := availableWidth - ellipsisWidth
|
||||||
|
|
||||||
// Layout filename, measure widths, and draw in a single pass
|
// Layout filename, measure widths, and draw in a single pass
|
||||||
r.drawTruncatedText(gtx, th.Shaper, displayFilename, r.theme.FontSize, reg.X+unit.Dp(8), filenameLineY, availableWidth, spaceForText, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
//r.drawTruncatedText(gtx, th.Shaper, displayFilename, r.theme.FontSize, reg.X+unit.Dp(8), filenameLineY, availableWidth, spaceForText, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
||||||
|
r.drawText(gtx, th.Shaper, displayFilename, r.theme.FontSize, reg.X+unit.Dp(8), filenameLineY, color.NRGBA{R: 0, G: 0, B: 0, A: 255})
|
||||||
|
|
||||||
// Line 2: Icons
|
// Line 2: Icons
|
||||||
iconsLineY := filenameLineY + filenameLineH
|
iconsLineY := filenameLineY + filenameLineH
|
||||||
|
|
@ -245,6 +246,8 @@ func (r *Renderer) drawText(gtx layout.Context, shp *text.Shaper, str string, si
|
||||||
|
|
||||||
// drawLineText draws already-laid-out glyphs using shaper.Shape() and shaper.Bitmaps().
|
// 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) {
|
func (r *Renderer) drawLineText(gtx layout.Context, shp *text.Shaper, x, y unit.Dp, col color.NRGBA) {
|
||||||
|
// Match Gio's textView: record into a macro for clipping
|
||||||
|
m := op.Record(gtx.Ops)
|
||||||
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() {
|
||||||
|
|
@ -257,6 +260,8 @@ func (r *Renderer) drawLineText(gtx layout.Context, shp *text.Shaper, x, y unit.
|
||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
r.drawLine(gtx, shp, line, x, y, col)
|
r.drawLine(gtx, shp, line, x, y, col)
|
||||||
}
|
}
|
||||||
|
call := m.Stop()
|
||||||
|
call.Add(gtx.Ops)
|
||||||
}
|
}
|
||||||
|
|
||||||
// drawLine draws a line of glyphs using shaper.Shape() and shaper.Bitmaps().
|
// drawLine draws a line of glyphs using shaper.Shape() and shaper.Bitmaps().
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user