Detect when text wraps to add custom behaviour?

I was checking how the source code does the line breaks in autowrap mode and it seems… complicated LOL.

It looks like you would need to make a similar loop to detect line breaks since there is no signal or method to get a line break position in the string.