- Home /
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?
It sounds like you're drawing your 20x20 rectangle in the first frame, then it resizes in the next and subsequent frames. Is that correct? You might try something that automatically calculates the size on the first frame, or start with a 0x0 window... Do you have a bit of your OnGUI()/rectangle initialization code you can share?
Answer by Waz · Jun 24, 2011 at 12:25 AM
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.
Thanks. I knew there was something about a repaint phase somewhere but forgot where it was in the docs. I'll try that. Although, reading the EventType for Layout, sounds like that IS where I'd want to do this? I'll try.
Yeah actually it works better if I reset the size during the Layout event, not the Repaint. But you led me to it, cheers!
Your answer
Follow this Question
Related Questions
Force aspect ratio of window (standalone Windows) 1 Answer
Windows that do not take priority over other GUI elements 0 Answers
4.6 UI : How to automatically set the size of a pannel from the size of inner text or other elements 1 Answer
GUI Window Render Priority 1 Answer
Margin not working on UILayout.BeginVertical("Window") 0 Answers