Skip to content

Commit 555c8a4

Browse files
authored
Merge pull request #78 from SirLpc/master
Add label width attribute to change fields label width.
2 parents 102bee4 + 92efa3a commit 555c8a4

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Toolbox.Editor.Drawers
5+
{
6+
[CustomPropertyDrawer(typeof(LabelWidthAttribute))]
7+
public class LabelWidthAttributeDrawer : PropertyDrawerBase
8+
{
9+
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
10+
{
11+
var previousWidth = EditorGUIUtility.labelWidth;
12+
EditorGUIUtility.labelWidth = Attribute.Width;
13+
EditorGUI.PropertyField(position, property, label, property.isExpanded);
14+
EditorGUIUtility.labelWidth = previousWidth;
15+
}
16+
17+
private LabelWidthAttribute Attribute => attribute as LabelWidthAttribute;
18+
}
19+
}

Assets/Editor Toolbox/Editor/Drawers/Regular/LabelWidthAttributeDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace UnityEngine
5+
{
6+
/// <summary>
7+
/// Change field label width.
8+
/// <para>Label width</para>
9+
/// </summary>
10+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
11+
[Conditional("UNITY_EDITOR")]
12+
public class LabelWidthAttribute : PropertyAttribute
13+
{
14+
public LabelWidthAttribute(float width = 120)
15+
{
16+
Width = width;
17+
}
18+
19+
public float Width { get; private set; }
20+
}
21+
}

Assets/Editor Toolbox/Runtime/Attributes/Regular/LabelWidthAttribute.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)