Circular Bounding Box for Labels

Godot Version

4.5

Question

Hi all, I am reaching a limit of my current understanding of Godot programming and could use some help. I am trying to implement a circular bounding box for Labels (for text wrapping), as opposed to the default rectangular one. Thankfully, I just have to deal with perfect circles for my purposes and not ellipses.

My intuition is that I should not reinvent the wheel for Labels, and try to reuse the existing system as much as possible. I imagine I would just need to extend the class, and overwrite the bit of code which determines if a line should wrap with one that is checking circular conditions, and also add a parameter for the bounding box circle’s radius. The calculation I plan on using is, in a coordinate system relative to the Label, for a line at position y above or below the center, the max line length is determined by r-abs(y)/r * d. Plus or minus some padding. While not essential, I’d also like to visually display the circular bounding box, too.

The thing is, I’m not sure how to do this. Extending and overwriting existing Nodes like Labels isn’t something that comes up much in tutorials, so I would appreciate some guidance.

You’ll likely need to use TextServer and/or TextLine and TextParagraph objects. Inheriting Label may not be sufficient.