Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


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

content

The content to make room for displaying.

The GUIStyle to layout for.

Returns

Type

Description

RectA 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

content

The content to make room for displaying.

The GUIStyle to layout for.

An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the
style
.
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

Type

Description

RectA 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

width

The width of the area you want.

height

The height of the area you want.

Returns

Type

Description

RectThe 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

width

The width of the area you want.

height

The height of the area you want.

An optional GUIStyle to layout for. If specified, the style's
padding
value will be added to your sizes & its
margin
value will be used for spacing.

Returns

Type

Description

RectThe 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

width

The width of the area you want.

height

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
style
.
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

Type

Description

RectThe 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

width

The width of the area you want.

height

The height of the area you want.

An optional GUIStyle to layout for. If specified, the style's
padding
value will be added to your sizes & its
margin
value will be used for spacing.

An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the
style
.
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

Type

Description

RectThe 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

minWidth

The minimum width of the area passed back.

maxWidth

The maximum width of the area passed back.

minHeight

The minimum width of the area passed back.

maxHeight

The maximum width of the area passed back.

Returns

Type

Description

RectA 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

minWidth

The minimum width of the area passed back.

maxWidth

The maximum width of the area passed back.

minHeight

The minimum width of the area passed back.

maxHeight

The maximum width of the area passed back.

An optional style. If specified, the style's
padding
value will be added to the sizes requested & the style's
margin
values will be used for spacing.

Returns

Type

Description

RectA 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

minWidth

The minimum width of the area passed back.

maxWidth

The maximum width of the area passed back.

minHeight

The minimum width of the area passed back.

maxHeight

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
style
.
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

Type

Description

RectA 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

minWidth

The minimum width of the area passed back.

maxWidth

The maximum width of the area passed back.

minHeight

The minimum width of the area passed back.

maxHeight

The maximum width of the area passed back.

An optional style. If specified, the style's
padding
value will be added to the sizes requested & the style's
margin
values will be used for spacing.

An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the
style
.
Additional Resources: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

Type

Description

RectA rectangle with size between minWidth & maxWidth on both axes.

Remarks

The rectangle's size will be between the min & max values.