Skip to content

Commit

Permalink
Merge pull request #78 from SirLpc/master
Browse files Browse the repository at this point in the history
Add label width attribute to change fields label width.
  • Loading branch information
arimger committed Jun 17, 2023
2 parents 102bee4 + 92efa3a commit 555c8a4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using UnityEditor;
using UnityEngine;

namespace Toolbox.Editor.Drawers
{
[CustomPropertyDrawer(typeof(LabelWidthAttribute))]
public class LabelWidthAttributeDrawer : PropertyDrawerBase
{
protected override void OnGUISafe(Rect position, SerializedProperty property, GUIContent label)
{
var previousWidth = EditorGUIUtility.labelWidth;
EditorGUIUtility.labelWidth = Attribute.Width;
EditorGUI.PropertyField(position, property, label, property.isExpanded);
EditorGUIUtility.labelWidth = previousWidth;
}

private LabelWidthAttribute Attribute => attribute as LabelWidthAttribute;
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Diagnostics;

namespace UnityEngine
{
/// <summary>
/// Change field label width.
/// <para>Label width</para>
/// </summary>
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
[Conditional("UNITY_EDITOR")]
public class LabelWidthAttribute : PropertyAttribute
{
public LabelWidthAttribute(float width = 120)
{
Width = width;
}

public float Width { get; private set; }
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 555c8a4

Please sign in to comment.