From 01211876282d892295f3c3efff2457c68c4f34fd Mon Sep 17 00:00:00 2001 From: Andy Williams Date: Sun, 28 May 2023 21:44:36 +0100 Subject: [PATCH] Wrap rich text on non-inline rather than on context change Fixes #2911 --- widget/richtext.go | 15 ++++++++++----- widget/richtext_objects.go | 14 ++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/widget/richtext.go b/widget/richtext.go index 36eb4d7a38..54756e1aea 100644 --- a/widget/richtext.go +++ b/widget/richtext.go @@ -352,14 +352,16 @@ func (t *RichText) updateRowBounds() { maxWidth := t.size.Width - 2*innerPadding + 2*t.inset.Width wrapWidth := maxWidth + var currentBound *rowBoundary var iterateSegments func(segList []RichTextSegment) iterateSegments = func(segList []RichTextSegment) { - var currentBound *rowBoundary for _, seg := range segList { if parent, ok := seg.(RichTextBlock); ok { - iterateSegments(parent.Segments()) - if !seg.Inline() { + segs := parent.Segments() + iterateSegments(segs) + if len(segs) > 0 && !segs[len(segs)-1].Inline() { wrapWidth = maxWidth + currentBound = nil } continue } @@ -464,7 +466,8 @@ func (r *textRenderer) Layout(size fyne.Size) { innerPadding := theme.InnerPadding() lineSpacing := theme.LineSpacing() - left := innerPadding - r.obj.inset.Width + xInset := innerPadding - r.obj.inset.Width + left := xInset yPos := innerPadding - r.obj.inset.Height lineWidth := size.Width - left*2 var rowItems []fyne.CanvasObject @@ -483,12 +486,14 @@ func (r *textRenderer) Layout(size fyne.Size) { if len(rowItems) != 0 { width, _ := r.layoutRow(rowItems, rowAlign, left, yPos, lineWidth) left += width + rowItems = nil } height := obj.MinSize().Height obj.Move(fyne.NewPos(left, yPos)) obj.Resize(fyne.NewSize(lineWidth, height)) - yPos += height + lineSpacing + yPos += height + left = xInset continue } rowItems = append(rowItems, obj) diff --git a/widget/richtext_objects.go b/widget/richtext_objects.go index 04aed4ca55..bc78488019 100644 --- a/widget/richtext_objects.go +++ b/widget/richtext_objects.go @@ -233,16 +233,10 @@ func (l *ListSegment) Segments() []RichTextSegment { txt = strconv.Itoa(i+1) + "." } bullet := &TextSegment{Text: txt + " ", Style: RichTextStyleStrong} - if para, ok := in.(*ParagraphSegment); ok { - seg := &ParagraphSegment{Texts: []RichTextSegment{bullet}} - seg.Texts = append(seg.Texts, para.Texts...) - out[i] = seg - } else { - out[i] = &ParagraphSegment{Texts: []RichTextSegment{ - bullet, - in, - }} - } + out[i] = &ParagraphSegment{Texts: []RichTextSegment{ + bullet, + in, + }} } return out }