diff --git a/widget/label.go b/widget/label.go index a8842be2..6f0e6b1d 100644 --- a/widget/label.go +++ b/widget/label.go @@ -134,7 +134,7 @@ type textIterator struct { // processGlyph checks whether the glyph is visible within the iterator's configured // viewport and (if so) updates the iterator's text dimensions to include the glyph. -func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visibleOrBefore bool) { +func (it *textIterator) processGlyph(g text.Glyph, ok bool) (visibleOrBefore bool) { if it.maxLines > 0 { if g.Flags&text.FlagTruncator != 0 && g.Flags&text.FlagClusterBreak != 0 { // A glyph carrying both of these flags provides the count of truncated runes. @@ -144,7 +144,7 @@ func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visib it.linesSeen++ } if it.linesSeen == it.maxLines && g.Flags&text.FlagParagraphBreak != 0 { - return g, false + return false } } // Compute the maximum extent to which glyphs overhang on the horizontal @@ -191,7 +191,7 @@ func (it *textIterator) processGlyph(g text.Glyph, ok bool) (_ text.Glyph, visib it.bounds.Max.X = max(it.bounds.Max.X, logicalBounds.Max.X) it.bounds.Max.Y = max(it.bounds.Max.Y, logicalBounds.Max.Y) } - return g, ok && !below + return ok && !below } func fixedToFloat(i fixed.Int26_6) float32 { @@ -206,7 +206,7 @@ func fixedToFloat(i fixed.Int26_6) float32 { // This design is awkward, but prevents the line slice from escaping // to the heap. func (it *textIterator) paintGlyph(gtx layout.Context, shaper *text.Shaper, glyph text.Glyph, line []text.Glyph) ([]text.Glyph, bool) { - _, visibleOrBefore := it.processGlyph(glyph, true) + visibleOrBefore := it.processGlyph(glyph, true) if it.visible { if len(line) == 0 { it.lineOff = f32.Point{X: fixedToFloat(glyph.X), Y: float32(glyph.Y)}.Sub(layout.FPt(it.viewport.Min)) diff --git a/widget/label_test.go b/widget/label_test.go index ca3e6c2a..87c0a6fc 100644 --- a/widget/label_test.go +++ b/widget/label_test.go @@ -146,10 +146,7 @@ func TestGlyphIterator(t *testing.T) { glyphs := getGlyphs(16, 0, maxWidth, text.Start, tc.str) it := textIterator{viewport: tc.viewport, maxLines: tc.maxLines} for i, g := range glyphs { - gOut, ok := it.processGlyph(g, true) - if gOut != g { - t.Errorf("textIterator modified glyphs[%d], original:\n%#+v, modified:\n%#+v", i, g, gOut) - } + ok := it.processGlyph(g, true) if !ok && i != tc.stopAtGlyph { t.Errorf("expected iterator to stop at glyph %d, stopped at %d", tc.stopAtGlyph, i) } diff --git a/widget/text.go b/widget/text.go index d1a843d2..fca325c7 100644 --- a/widget/text.go +++ b/widget/text.go @@ -492,14 +492,19 @@ func (e *textView) layoutText(lt *text.Shaper) { it := textIterator{viewport: image.Rectangle{Max: image.Point{X: math.MaxInt, Y: math.MaxInt}}} if lt != nil { lt.Layout(e.params, r) - for glyph, ok := it.processGlyph(lt.NextGlyph()); ok; glyph, ok = it.processGlyph(lt.NextGlyph()) { - e.index.Glyph(glyph) + for { + g, ok := lt.NextGlyph() + if !it.processGlyph(g, ok) { + break + } + e.index.Glyph(g) } } else { // Make a fake glyph for every rune in the reader. b := bufio.NewReader(r) for _, _, err := b.ReadRune(); err != io.EOF; _, _, err = b.ReadRune() { - g, _ := it.processGlyph(text.Glyph{Runes: 1, Flags: text.FlagClusterBreak}, true) + g := text.Glyph{Runes: 1, Flags: text.FlagClusterBreak} + _ = it.processGlyph(g, true) e.index.Glyph(g) } }