Skip to content

Commit

Permalink
Don't create a new text segment slice on hyperlink refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Feb 6, 2024
1 parent b86be42 commit e8d3f88
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions widget/hyperlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/driver/desktop"
"fyne.io/fyne/v2/internal/widget"
"fyne.io/fyne/v2/theme"
)

Expand Down Expand Up @@ -263,16 +264,25 @@ func (hl *Hyperlink) syncSegments() {

hl.provider.Wrapping = hl.Wrapping
hl.provider.Truncation = hl.Truncation
hl.provider.Segments = []RichTextSegment{&TextSegment{
Style: RichTextStyle{
Alignment: hl.Alignment,
ColorName: theme.ColorNameHyperlink,
Inline: true,
TextStyle: hl.TextStyle,
},
Text: hl.Text,
}}

style := RichTextStyle{
Alignment: hl.Alignment,
ColorName: theme.ColorNameHyperlink,
Inline: true,
TextStyle: hl.TextStyle,
}

hl.textSize = fyne.MeasureText(hl.Text, theme.TextSize(), hl.TextStyle)

if len(hl.provider.Segments) == 0 {
hl.provider.Scroll = widget.ScrollNone
hl.provider.Segments = []RichTextSegment{&TextSegment{Style: style, Text: hl.Text}}
return
}

segment := hl.provider.Segments[0].(*TextSegment)
segment.Style = style
segment.Text = hl.Text
}

var _ fyne.WidgetRenderer = (*hyperlinkRenderer)(nil)
Expand Down

0 comments on commit e8d3f88

Please sign in to comment.