Description
Checklist
- I have searched the issue tracker for open issues that relate to the same feature, before opening a new one.
- This issue only relates to a single feature. I will open new issues for any other features.
Is your feature request related to a problem?
I am working on a graphical browser for the Gemini protocol, and I am using the rich text widget to display page content. When I click a hyperlink in the rich text, I want to load the page within my application. However current behavior opens URL in the web browser by default with no way to customize the behavior for rich text hyperlinks AFAIK.
Is it possible to construct a solution with the existing API?
No response
Describe the solution you'd like to see.
I think it would be useful to have custom callbacks within rich text hyperlinks. Currently, while the Hyperlink widget supports a custom callback (#2979), this is not supported for HyperlinkSegments in the RichText widget.
One solution would be to add an OnTapped
field to HyperlinkSegment (following the design for Hyperlink) and pass it to the Hyperlink that gets generated in HyperlinkSegment.Visual()
:
type HyperlinkSegment struct {
Alignment fyne.TextAlign
Text string
URL *url.URL
// add
OnTapped func()
}
Example usage:
content := widget.NewRichTextFromMarkdown(`
[link 1](example.com)
[link 2](example.com)
`)
// Set callback for all top-level hyperlink segments
for _, s := range content.Segments {
if link, ok := s.(*HyperlinkSegment); ok {
link.OnTapped = func() {
fmt.Println(link.URL)
}
}
}
Activity