Skip to content

Commit

Permalink
Wrap rich text on non-inline rather than on context change
Browse files Browse the repository at this point in the history
Fixes #2911
  • Loading branch information
andydotxyz committed May 31, 2023
1 parent a08e3dc commit 0121187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
15 changes: 10 additions & 5 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions widget/richtext_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 0121187

Please sign in to comment.