Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GetControlRect

Get a rect for an Editor control.
Read time 5 minutesLast updated 10 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor

GetControlRect(GUILayoutOption[])

Get a rect for an Editor control.
public static Rect GetControlRect(params GUILayoutOption[] options)

Parameters

An optional list of layout options that specify extra layout 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

Rect

Remarks

When creating a new Editor control it is a sound design to implement the actual control without relying on GUILayout and instead have the control take a Rect as parameter, similar to the controls in the EditorGUI class. This ensures the control can also be used in for example a PropertyDrawer, which does not allow GUILayout.
Once a non-layout version of the control is implemented, a layout version can easily be made as well, which simply calls into the non-layout version. In order to get a rect fitting for the control, the GetControlRect function can be used.

GetControlRect(bool, GUILayoutOption[])

Get a rect for an Editor control.
public static Rect GetControlRect(bool hasLabel, params GUILayoutOption[] options)

Parameters

hasLabel

Optional boolean to specify if the control has a label. Default is true.

An optional list of layout options that specify extra layout 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

Rect

Remarks

When creating a new Editor control it is a sound design to implement the actual control without relying on GUILayout and instead have the control take a Rect as parameter, similar to the controls in the EditorGUI class. This ensures the control can also be used in for example a PropertyDrawer, which does not allow GUILayout.
Once a non-layout version of the control is implemented, a layout version can easily be made as well, which simply calls into the non-layout version. In order to get a rect fitting for the control, the GetControlRect function can be used.

GetControlRect(bool, float, GUILayoutOption[])

Get a rect for an Editor control.
public static Rect GetControlRect(bool hasLabel, float height, params GUILayoutOption[] options)

Parameters

hasLabel

Optional boolean to specify if the control has a label. Default is true.

height

The height in pixels of the control. Default is EditorGUIUtility.singleLineHeight.

An optional list of layout options that specify extra layout 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

Rect

Remarks

When creating a new Editor control it is a sound design to implement the actual control without relying on GUILayout and instead have the control take a Rect as parameter, similar to the controls in the EditorGUI class. This ensures the control can also be used in for example a PropertyDrawer, which does not allow GUILayout.
Once a non-layout version of the control is implemented, a layout version can easily be made as well, which simply calls into the non-layout version. In order to get a rect fitting for the control, the GetControlRect function can be used.

GetControlRect(bool, float, GUIStyle, GUILayoutOption[])

Get a rect for an Editor control.
public static Rect GetControlRect(bool hasLabel, float height, GUIStyle style, params GUILayoutOption[] options)

Parameters

hasLabel

Optional boolean to specify if the control has a label. Default is true.

height

The height in pixels of the control. Default is EditorGUIUtility.singleLineHeight.

Optional GUIStyle to use for the control.

An optional list of layout options that specify extra layout 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

Rect

Remarks

When creating a new Editor control it is a sound design to implement the actual control without relying on GUILayout and instead have the control take a Rect as parameter, similar to the controls in the EditorGUI class. This ensures the control can also be used in for example a PropertyDrawer, which does not allow GUILayout.
Once a non-layout version of the control is implemented, a layout version can easily be made as well, which simply calls into the non-layout version. In order to get a rect fitting for the control, the GetControlRect function can be used.