Skip to content

Commit

Permalink
Try #2 of temp fix for fyne-io#4998
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jul 28, 2024
1 parent 91d99b1 commit 7abcad1
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions widget/richtext.go
Original file line number Diff line number Diff line change
Expand Up @@ -958,14 +958,6 @@ func lineBounds(seg *TextSegment, wrap fyne.TextWrap, trunc fyne.TextTruncation,
widthChecker := func(low int, high int) bool {
return measurer(text[low:high]).Width <= measureWidth
}
// Supersonic: temporary fix for https://github.com/fyne-io/fyne/issues/4998
widthCheckerEllipsis := func(low, high int) bool {
if low == 0 && high == len(text)-1 {
return measurer(text[low:high]).Width <= measureWidth
}
return measurer(text[low:high]).Width+
measurer([]rune{'…'}).Width <= measureWidth
}

reuse := 0
yPos := float32(0)
Expand Down Expand Up @@ -1071,9 +1063,19 @@ func lineBounds(seg *TextSegment, wrap fyne.TextWrap, trunc fyne.TextTruncation,
}
default:
if trunc == fyne.TextTruncateEllipsis {
// Supersonic: temporary fix for https://github.com/fyne-io/fyne/issues/4998
high = binarySearch(widthCheckerEllipsis, low, high)
bounds = append(bounds, rowBoundary{[]RichTextSegment{seg}, reuse, low, high, high < len(text)})
// Supersonic: tmp fix for https://github.com/fyne-io/fyne/issues/4998
high = binarySearch(widthChecker, low, high)
ellipsis := high < len(text)
if ellipsis && high > 0 && low < high {
// trim off up to 2 characters to make room for ellipsis
ellipsisWidth := fyne.MeasureText("…", seg.size(), seg.Style.TextStyle).Width
if fyne.MeasureText(string(text[high-1:high]), seg.size(), seg.Style.TextStyle).Width < ellipsisWidth && high > 1 && low < high-1 {
high -= 2
} else {
high -= 1
}
}
bounds = append(bounds, rowBoundary{[]RichTextSegment{seg}, reuse, low, high, ellipsis})
reuse++

/* orig Fyne code:
Expand Down

0 comments on commit 7abcad1

Please sign in to comment.