I’m using GUILayout (not GUI) for GUI rendering, and I’ve pics to print on screen, but they aren’t all at the same resolution, and the available space for printing them is also variable.
Is there a way to know where the current GUILayout printing (Box, Label…) is on screen ?
i.e. to get a result saying that the next thing printed will be at (450px, 375px), so that I can calculate how much pixels I have left on screen’s width/height to resize my pics.
I’ve tried GUILayoutUtility.GetLastRect() but the rect returned doesn’t seem very accurate.
GetLastRect is probably what you want, but a couple things to keep in mind:
If you’re in an Area or Window, the coords returned may be relative to that (though the size should be correct).
If you’re saving the Rect between frames, remember that OnGUI is run multiple times per frame (once per GUI event), and GetLastRect is not ‘right’ in every event, i.e. if you’re saving the Rect between frames you’ll probably need to wrap it in: