Clickable text in paragraph

32 views
Skip to first unread message

supsm17

unread,
Mar 25, 2023, 3:57:58 AM3/25/23
to fltk.general
Hello wonderful people of fltk,
I am wondering what the best way of having clickable text in a paragraph is, similar to having a link on a webpage. However, I am not able to use Fl_Help_View because I need to call a specific function when the text is clicked, instead of opening a fixed link.
I currently plan on using a Fl_Button on top of the Fl_Box containing the text, but how can I align the button to the text below? This would need to account for text wrapping, alignment, etc. of the Fl_Box. Or is there a better way to achieve this goal?

Thanks,
supsm

imm

unread,
Mar 25, 2023, 8:53:12 AM3/25/23
to General FLTK
I wonder if you can subvert the Fl_Help_View::link() method to call your callback for you in this case, then just return null to skip the default handling behaviour?

--
Ian
From my Fairphone FP3

Matthias Melcher

unread,
Mar 25, 2023, 10:06:04 AM3/25/23
to fltk.general
Ian's suggestion is the easiest: https://fltk.gitlab.io/fltk/classFl__Help__View.html#a6407d2a4cc890b51f303ebf56450588e

As a much more complex alternative, you can use Fl_Text_Display and override handle(int). When the user clicks the text area, you can query the index of the letter that was clicked, and then check if the index is within the range of your link. You ca also use attributes here to visualise the different behaviour of that text segment.

supsm17

unread,
Mar 25, 2023, 4:49:49 PM3/25/23
to fltk.general
Interesting... thanks for the help!
Reply all
Reply to author
Forward
0 new messages