How to ensure a text tooltip never appears offscreen?

I’m attempting to create a tooltip using 4.6 UI that appears at the bottom-right of my mouse cursor. When I point at something toward the right-hand side of the screen, I would like the tooltip to stop following my mouse cursor’s X axis to prevent the text from appearing partway off the screen. It would be easy to do this if I knew how large my text was in pixels, but I haven’t figured out a way of doing this.

What would be the best way to achieve the sort of behavior that I described?

You can get the Renderer component and check its bound property. This will help you to find the dimension of the Tooltip. Also, you can use Camera.main.ViewPortToWorlPoint() to see if your mouse pointer is going off the screen. Using this way you can hopefully get it.