"hover" and "press" signals for sections of text in LineEdit/TextEdit/RichTextLabel, etc.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Will Nations
:warning: Old Version Published before Godot 3 was released.

Was wondering if anyone knew if it were possible to get functionality to trigger off of specific segments of a text block in the Godot UI somehow (a Control node).

Something like putting tags around text in a text field and then signals get triggered off of any text between those tags that you can then attach functions to.

# text field content having SOME means of defining a name for a segment
<a name="talk">TALK</a> to <a name="bob">Bob</a>.


# in script
func _on_talk_hover:
    pass # display a tooltip explaining the "talk" action

func _on_talk_press:
    pass # trigger behavior that moves the story forward

func _on_bob_hover:
    pass # trigger another UI element to display information about Bob

I’d rather have a way of automatically generating these signals for any given segment of text rather than having to manually place an invisible button over very particular positions in a Control node (which I would have to readjust any time the text is changed). Perhaps this is better submitted as a simple feature request for the engine?

If nothing else, I could probably spend a couple of days writing a tool script that could generate all of this stuff from the editor by parsing the text content of an exported node, identifying segments, generating new signal connections passing in the name of the segments and generating invisible buttons with positions calculated somehow.

sigh

:bust_in_silhouette: Reply From: breadbox

What you’re describing sounds awfully close to what the [url] tag does in the RichTextLabel bbcode. Well, for “press” anyway. I don’t think there’s currently a way to get hover. events.

e.g. create a RichTextLabel and set the text to ‘Would you like to play a game?’ The url-marked bit of text will have an underline added to it, and clicking on it will generate a “meta_clicked”. The callback function will get passed the url as an argument.

:bust_in_silhouette: Reply From: wombatstampede

The RichTextLabel control supports links. And clicks on these links generate a signal which you can handle. There’s no mouse hover signal though.

The TextEdit control is equal to Godots Script editor (as far as I know). So no urls, no hover but syntax highlighting, etc.

What you could probably do:
Add a label for each word. If you use get_combined_minimum_size() on the label after set_text().
( https://forum.godotengine.org/2674/how-do-i-get-the-size-of-a-expanded-label )
You’ll get the size that the word needs and can arrange them accordingly.
(Maybe there’s also a container which does this, I don’t know)

Labels support some mouse events (enter/exit) so you can also identify them on hover or if you catch a global mouse click.

So I think, Labels are the way to go if you don’t need the hover signals in a text editor itself.

I’m setting this one has the “correct” answer just because it was a bit more detailed about possible workarounds. Thanks.

Will Nations | 2017-07-01 18:32