Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: custom hyperlink callback #2979

Closed
sloumdrone opened this issue May 16, 2022 · 2 comments
Closed

Feature request: custom hyperlink callback #2979

sloumdrone opened this issue May 16, 2022 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@sloumdrone
Copy link

This is my first time opening an issue here (I don't usually use github). I read the docs, but wasn't sure about feature requests. My apologies if this is out of scope or incorrectly formatted (I'm happy to update if needed).

Feature request description

This is not a bug, but is a gap that I think is unhandled. At present there is a hyperlink widget. It opens the given link in the default handler. I have verified that this works for http, gopher, gemini, finger etc. The correct handler based on my system configuration opens the link.

What I would like to be able to do it essentially catch the click and handle what happens within application code rather than passing control to an outside application. This can be done with a button, which is great. However, it doesn't solve for something like creating an internet client or having rich documentation of multiple pages within the application itself. I would like to be able to have a hypertext document (whether html or otherwise) render (not in scope of this, the rich text from markdown function works fine for this purpose) and be able to handle the click in my own code rather than port out to another application. I would think this could be solved by adding access to the hyperlink click event and letting a custom function be added to the widget that if nil will open in the default handler and if present the default handler will not be used and the given function will be called (with access to the underlying widget's link text and link url).

Adding this functionality in the hyperlink widget as well as the hyperlink segment of rich text objects could be very useful for building applications that can have linked content within the application or for the development of custom protocols for navigating around an application.

It is likely that the callback would need to be triggered by enter as well.

Example code:

type Hyperlink struct {
	BaseWidget
	Text      string
	URL       *url.URL
	Alignment fyne.TextAlign
	Wrapping  fyne.TextWrap
	TextStyle fyne.TextStyle 
        Callback func(text, url string) // <--- add this, if nil default behavior will be used
}
@sloumdrone sloumdrone added the unverified A bug that has been reported but not verified label May 16, 2022
@sloumdrone sloumdrone changed the title Feature request: custom hyperlink handling via click event Feature request: custom hyperlink callback May 16, 2022
@andydotxyz
Copy link
Member

This is a good point, it has not really become useful until the RichText handling added the possibility of multiple marked up content in an all. Let's see what we can do!

@andydotxyz andydotxyz added enhancement New feature or request good first issue Good for newcomers and removed unverified A bug that has been reported but not verified labels May 18, 2022
andydotxyz added a commit to andydotxyz/fyne that referenced this issue Jun 2, 2022
@andydotxyz
Copy link
Member

Fixed on develop, this will be in v2.2.0 shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants