[3.x] Add explicit URL property in LinkButton node#63855
[3.x] Add explicit URL property in LinkButton node#63855AndreaTerenz wants to merge 3 commits intogodotengine:3.xfrom AndreaTerenz:url-link-button
Conversation
|
Note that there's already a pull request implementing this feature in |
|
@Calinou I admit I didn't see it, but it seems to me that that PR opens the link by having the button listen to its own |
As a rule, we first accept features to the |
scene/gui/link_button.cpp
Outdated
There was a problem hiding this comment.
| xl_text = tr((text.is_empty()) ? url : text); | |
| xl_text = text.is_empty() ? url : tr(text); |
Probably should be like this, there's no reason to translate URL.
There was a problem hiding this comment.
That's a good point, will do. I also noticed that the is_empty method doesn't exist for Strings in G3 (but I saw it in the G4 related issue?), so I really need to make a few corrections anyway
There was a problem hiding this comment.
@bruvzg Actually, tr(...) doesn't return a String but a StringName, so the ternary operator doesn't work:
if (text.empty()) {
xl_text = url;
}
else {
xl_text = tr(text);
}
Open link when clicking LinkButton
This PR adds a
urlproperty toLinkButtonthat points to a resource (most likely a webpage) to be opened when the button is clicked. Such value will be used as the visible text of the button when thetextproperty isn't set.The idea is to have something simpler than a RichTextLabel, which requires figuring out the BBCode syntax for a link and manually writing a script to actually open the URL when clicking. At the same time, LinkButtons right now (in Godot 3.x at least) are simply flat buttons with some underlined text which isn't actually treated as a link to anything (the dev is supposed to again manually write a script that opens the url when the button is pressed).
This PR aims at clarifying this system, where RichTextLabels may be used for complex text with multiple links (which could need to be treated separately in code) and where LinkButtons are a simple and quick way of displaying a single URL to (e.g.) one's GitHub profile.