Problem resizing a GUILayout window

I’m in need of resizing a GUILayout-based window (for mobile). Basically the user can choose small/medium/large UI depending on their device’s needs. (I change font and some other element sizes). The window needs to auto-calculate itself to fit itself to the new sizes.

I’ve been doing this by setting the window rect to something small (like 20x20) so that the next OnGUI will recalculate it. Which it does. Now the problem:

For one frame, I get a small window. The next frame repaints with a nice window size, but this flash is pretty annoying.

What’s the best way to tell a GUILayout window to recalculate itself without getting this type of flash?

This sounds like the sort of problem you get if you change the layout size during layout events. IIRC, you should only make such a change in the Repaint phase (the last phase):

if (GUILayout.Button("Big")) newSize = Size.Big;
...
if(Event.current.type == EventType.Repaint && newSize != Size.Unchanged) {
   switch (newSize) {
       case Size.Big: uiWidth = 100; ...
   }
}

May be best to post a summary of your code though.