How do I get the size of an inactive panel in the new UI?

I want to make my own tooltips (the new unity UI has some builtin … but they only take richtext by the looks of it… I want embedded images etc). I’d also like to use the new unity UI as it should be more more efficient and I believe it’s the “right” way to do this (not the legacy GUI).

The base for my tooltip is a UI panel with a Content Size Fitter. I want to move the panel with the mouse so that it never extends beyond the screen bounds. Some time after the user mouses over a collider the tooltip panel is activated and then displayed. Because the content of the tooltip is dynamic I suspect the size of the tooltip panel is not known till rendering time? Tooltip placement is done something like the approach described here here but I have to check if the tooltip +/- half the tooltip panel width is out of the game windows bounds (< 0, > Screen.width and vertically as well). It’s my intention that the content size is dynamic on a per object basis but does not change while the tooltip is active.

So there are three possible solutions I can see.

  1. The information on the size of the inactive panel is available and I just don’t know how to get it, or
  2. I have to wait till the tooltip panel is rendered before the size information is accurate, or
  3. Have I got the wrong approach entirely here… should I be getting the size and then positioning the thing during mouse move events (to avoid exiting the tooltip by moving the mouse over the tooltip itself … generating a mouse exit for the original target)?

Now with i) I’ve tried some of the following:

 tooltipPanel.transform.GetComponent<RectTransform>().rect.width;
 tooltipPanel.transform.GetComponent<RectTransform>().sizeDelta[0];
 tooltipPanel.GetComponent<CanvasRenderer>().renderer.bounds.size.x;

But none of them seem to return the information I want (the last one doesn’t work… no renderer). I suspect that that info is not set at this stage so this is not a viable approach?

As far as ii) is concerned I’d like to avoid doing stuff in immediate mode but if it can’t be helped then I guess it’s ok. What would be the best way to do this? Will I get flicker when I draw the tooltip the first time so that I can get the size before moving it to the right place? Is there a callback where the tooltip panel is layed out with the right size but not yet displayed?

As for iii) it seems a little inefficient to recalculate the tooltip size all the time if it isn’t changing.

So… after a bit of snooping around. The size is reported incorrectly using the GetWorldCorners(corners) method above as (100, 100) in the OnEnable() and Start() methods (well it’s probably the correct size but the UI hasn’t been layed out yet). The size looks to be reported correctly in the Update() method, e.g. (168, 838). So the UI layout happens sometime after the OnEnable() call. If someone has a pointer to some documentation that points to when the UI layout happens that would be nice (it’d be nice not to have this code in the Update callback - in a perfect world). There doesn’t appear to be any useful events here.

So that makes me think that 2 is the answer. I just have to make sure that I only calculate the size of the tooltip when the content changes and the tooltip is active to keep the extra work in the Update() to a minimum.