Layout computation is always awkward in immediate guis. You have to do an extra pass or throw away a frame.