diff --git a/internal/ui/render.go b/internal/ui/render.go index ce6e84d..3cdeee0 100644 --- a/internal/ui/render.go +++ b/internal/ui/render.go @@ -94,28 +94,29 @@ func (r *Renderer) drawStatusBar(gtx layout.Context, sb StatusBar) { // Truncate filename only if it doesn't fit 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 - th.Shaper.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(r.theme.FontSize))}, "...") - var ellipsisWidths []int - for { - g, ok := th.Shaper.NextGlyph() - if !ok { - break - } - if len(ellipsisWidths) == 0 { - ellipsisWidths = append(ellipsisWidths, int(g.Advance>>6)) - } else { - ellipsisWidths = append(ellipsisWidths, ellipsisWidths[len(ellipsisWidths)-1]+int(g.Advance>>6)) - } - } - ellipsisWidth := ellipsisWidths[len(ellipsisWidths)-1] + //th.Shaper.LayoutString(text.Parameters{PxPerEm: fixed.I(gtx.Sp(r.theme.FontSize))}, "...") + //var ellipsisWidths []int + //for { + // g, ok := th.Shaper.NextGlyph() + // if !ok { + // break + // } + // if len(ellipsisWidths) == 0 { + // ellipsisWidths = append(ellipsisWidths, int(g.Advance>>6)) + // } else { + // ellipsisWidths = append(ellipsisWidths, ellipsisWidths[len(ellipsisWidths)-1]+int(g.Advance>>6)) + // } + //} + //ellipsisWidth := ellipsisWidths[len(ellipsisWidths)-1] // 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 - 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 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(). 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 line := glyphs[:0] 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 { 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().