I write in C# and i cant seem to find how to get thecurrent window width and height. I want to resize the window so that the content stays in place.
For in-game Windows:
Rect windowPosition = new Rect(left:0, top:0, width:128, height:256);
void OnGUI()
{
windowPosition = GUI.Window(0, windowPosition, WindowMethod, "My Window");
}
void WindowMethod(int id)
{
GUILayout.BeginHorizontal();
if (GUILayout.Button("Change"))
{
windowPosition.width += 100;
windowPosition.height += 100;
}
GUILayout.FlexibleSpace();
GUILayout.Label("This label will always be against the right edge.");
GUILayout.EndHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("This label will always be against the bottom edge.");
}
For EditorWindows:
var window = EditorWindow.GetWindow<MyWindow>();
window.position = new Rect(x, y, width, height);
window.minSize = new Vector2(width, height);
window.maxSize = new Vector2(width, height);
Hope that helps.
Thanks ths info is usefull indeed, but actuallyi i wanted to get this code to work:
GUI.Window(0,new Rect(0,0,optionsX,optionsY),OptionsWindow,"Options");
...
void OptionsWindow(int windowID)
{
Rect position = new Rect(10,30,__[COLOR="red"]windowWidth[/COLOR]__,[COLOR="red"]__windowHeight__[/COLOR]);
Rect pageSize = new Rect(0,0,1024,768);// Actual Page Size
scrollPosition = GUI.BeginScrollView(position,scrollPosition,pageSize,false,true);
// Scroll Page content
toggle = GUI.Toggle(new Rect(10,600,100,25),toggle,"bottom toggle");
GUI.EndScrollView();
}
If you use GUILayout.Window, it will size itself to fit your Scroll View and all that. Just use GUILayout controls instead of GUI controls. If you want to stick with GUI controls, you need to modify optionsX and optionsY inside the OptionsWindow method to change the window’s size.
I love to resurrect this thread.
Especially since it was created the same year I have joined the community.
And after all this years IMGUI is still kicking my butt.
I just want my GUILayout.BeginScrollView to fit inside my GUILayout.window.
And additionaly even when I have specified alwaysShowVertical = false and alawaysShowHorizontal = false I have this scrollbars visible.
This is my code after many different attempts:
using UnityEngine;
public class DeveloperMenuComponent : MonoBehaviour {
Rect winRect = new Rect(0, 0, 500, Screen.height);
private void OnGUI() {
winRect = GUILayout.Window(0, winRect, WinProc, "Developer Menu");
}
Vector2 scrollPosition;
void WinProc(int id) {
scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false);
GUILayout.Label("Text");
GUILayout.Button("Button");
GUILayout.EndScrollView();
}
}
I rage quitted unity3d today !!!