HandlePrefixLabel

示例程序
说明为控制区域生成一个前置标签

用法

HandlePrefixLabel 的作用和 PrefixLabel 基本相同,都是为某个控制区域生成一个前置的标签,并与该控制域合为一个整体。不同的是,HandlePrefixLabel 允许通过代码明确指定在整个区域中标签的具体位置,用 labelPosition 表示。

public static void HandlePrefixLabel(Rect totalPosition, Rect labelPosition, GUIContent label, int id = 0, GUIStyle style = EditorStyles.label);

参数

totalPosition

包含标签和空间的整体绘制区域。

labelPosition

标签的绘制区域。

label

标签内容。

id

控件的索引号。

style

(可选)由 GUIStyle 类型定义的 GUI 样式。

示例

void OnGUI () {
		EditorGUI.PrefixLabel (
				new Rect (5, 5, 500, 17),
				new GUIContent ("This is a prefix label and the related control.")
		);
		_int1 = EditorGUI.IntField (new Rect(400, 5, 100, 17), _int1);
	
		EditorGUI.HandlePrefixLabel (
				new Rect(5, 27, 500, 17),
				new Rect(5, 27, 400, 17),
				new GUIContent("This is a handled prefix label and the related control.")
		);
		_int2 = EditorGUI.IntField (new Rect(400, 27, 100, 17), _int2);
	
		EditorGUI.HandlePrefixLabel (
				new Rect (5, 49, 500, 17),
				new Rect (5, 49, 200, 17),
				new GUIContent ("This is another handled prefix label and the related control.")
		);
		_int3 = EditorGUI.IntField (new Rect (400, 49, 100, 17), _int3);
}

可以看出 PrefixLabel 已经包含了对标签区域尺寸的定义,修改整体的尺寸对标签区域没有影响,所以标签区域的部分文本没有显示。而在 HandlePrefixLabel 中可以通过单独定义标签区域的尺寸来解决这个问题。所以当自定义的标签尺寸比较大时可以选用 HandlePrefixLabel