How to get the size of wrap box just after adding a child?

I am creating a vertical menu bar and each button in it will call the second-level menu(a border). However, the second-level menu may beyond the window’s boundry. One of solutions is to process the border’s position according to its size. And now I come across another question that I cannot get the position of the widget wrap box. Below is the demo to illustrate the problem and in the second picture, after I click the button , I can just get the height 0 even though I have add a child.