GetRect
Reserve layout space for a rectangle for displaying some contents with a specific style.
Read time 7 minutesLast updated 9 days ago
Definition
- Type: Method
- Namespace: UnityEngine
- Assembly: UnityEngine.IMGUIModule
GetRect(GUIContent, GUIStyle)
Reserve layout space for a rectangle for displaying some contents with a specific style.
public static Rect GetRect(GUIContent content, GUIStyle style)
Parameters
Returns
Type | Description |
|---|---|
| Rect | A rectangle that is large enough to contain content when rendered in style. |
Examples
using UnityEngine;public class ExampleScript : MonoBehaviour{ // Shows the button rect properties in a label when the mouse is over it GUIContent buttonText = new GUIContent("some button"); GUIStyle buttonStyle = GUIStyle.none; void OnGUI() { Rect rt = GUILayoutUtility.GetRect(buttonText, buttonStyle); if (rt.Contains(Event.current.mousePosition)) { GUI.Label(new Rect(0, 20, 200, 70), "PosX: " + rt.x + "\nPosY: " + rt.y + "\nWidth: " + rt.width + "\nHeight: " + rt.height); } GUI.Button(rt, buttonText, buttonStyle); }}
GetRect(GUIContent, GUIStyle, GUILayoutOption[])
Reserve layout space for a rectangle for displaying some contents with a specific style.
public static Rect GetRect(GUIContent content, GUIStyle style, params GUILayoutOption[] options)
Parameters
The content to make room for displaying.
An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the .
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
styleAdditional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Returns
Type | Description |
|---|---|
| Rect | A rectangle that is large enough to contain content when rendered in style. |
Examples
using UnityEngine;public class ExampleScript : MonoBehaviour{ // Shows the button rect properties in a label when the mouse is over it GUIContent buttonText = new GUIContent("some button"); GUIStyle buttonStyle = GUIStyle.none; void OnGUI() { Rect rt = GUILayoutUtility.GetRect(buttonText, buttonStyle); if (rt.Contains(Event.current.mousePosition)) { GUI.Label(new Rect(0, 20, 200, 70), "PosX: " + rt.x + "\nPosY: " + rt.y + "\nWidth: " + rt.width + "\nHeight: " + rt.height); } GUI.Button(rt, buttonText, buttonStyle); }}
GetRect(float, float)
Reserve layout space for a rectangle with a fixed content area.
public static Rect GetRect(float width, float height)
Parameters
Returns
Type | Description |
|---|---|
| Rect | The rectangle to put your control in. |
GetRect(float, float, GUIStyle)
Reserve layout space for a rectangle with a fixed content area.
public static Rect GetRect(float width, float height, GUIStyle style)
Parameters
Returns
Type | Description |
|---|---|
| Rect | The rectangle to put your control in. |
GetRect(float, float, GUILayoutOption[])
Reserve layout space for a rectangle with a fixed content area.
public static Rect GetRect(float width, float height, params GUILayoutOption[] options)
Parameters
The width of the area you want.
The height of the area you want.
An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the .
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
styleAdditional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Returns
Type | Description |
|---|---|
| Rect | The rectangle to put your control in. |
GetRect(float, float, GUIStyle, GUILayoutOption[])
Reserve layout space for a rectangle with a fixed content area.
public static Rect GetRect(float width, float height, GUIStyle style, params GUILayoutOption[] options)
Parameters
The width of the area you want.
The height of the area you want.
An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the .
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
styleAdditional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Returns
Type | Description |
|---|---|
| Rect | The rectangle to put your control in. |
GetRect(float, float, float, float)
Reserve layout space for a flexible rect.
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight)
Parameters
Returns
Type | Description |
|---|---|
| Rect | A rectangle with size between minWidth & maxWidth on both axes. |
Remarks
The rectangle's size will be between the min & max values.
GetRect(float, float, float, float, GUIStyle)
Reserve layout space for a flexible rect.
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style)
Parameters
The minimum width of the area passed back.
The maximum width of the area passed back.
The minimum width of the area passed back.
The maximum width of the area passed back.
An optional style. If specified, the style's value will be added to the sizes requested & the style's values will be used for spacing.
paddingmarginReturns
Type | Description |
|---|---|
| Rect | A rectangle with size between minWidth & maxWidth on both axes. |
Remarks
The rectangle's size will be between the min & max values.
GetRect(float, float, float, float, GUILayoutOption[])
Reserve layout space for a flexible rect.
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, params GUILayoutOption[] options)
Parameters
The minimum width of the area passed back.
The maximum width of the area passed back.
The minimum width of the area passed back.
The maximum width of the area passed back.
An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the .
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
styleAdditional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Returns
Type | Description |
|---|---|
| Rect | A rectangle with size between minWidth & maxWidth on both axes. |
Remarks
The rectangle's size will be between the min & max values.
GetRect(float, float, float, float, GUIStyle, GUILayoutOption[])
Reserve layout space for a flexible rect.
public static Rect GetRect(float minWidth, float maxWidth, float minHeight, float maxHeight, GUIStyle style, params GUILayoutOption[] options)
Parameters
The minimum width of the area passed back.
The maximum width of the area passed back.
The minimum width of the area passed back.
The maximum width of the area passed back.
An optional style. If specified, the style's value will be added to the sizes requested & the style's values will be used for spacing.
paddingmarginAn optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the .
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
styleAdditional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
Returns
Type | Description |
|---|---|
| Rect | A rectangle with size between minWidth & maxWidth on both axes. |
Remarks
The rectangle's size will be between the min & max values.