Skip to content

Commit

Permalink
Merge pull request #49 from JohannesDeml/bugfix/avoid-label-overlap
Browse files Browse the repository at this point in the history
Fix label overlapping button
  • Loading branch information
mackysoft authored Feb 16, 2024
2 parents 97c4e63 + c9b5193 commit 69830f3
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
EditorGUI.BeginProperty(position,label,property);

if (property.propertyType == SerializedPropertyType.ManagedReference) {
// Draw the subclass selector popup.
Rect popupPosition = new Rect(position);
popupPosition.width -= EditorGUIUtility.labelWidth;
popupPosition.x += EditorGUIUtility.labelWidth;
popupPosition.height = EditorGUIUtility.singleLineHeight;

// render label first to avoid label overlap for lists
Rect foldoutLabelRect = new Rect(position);
foldoutLabelRect.height = EditorGUIUtility.singleLineHeight;
foldoutLabelRect.x += EditorGUI.indentLevel * 12;
Rect popupPosition = EditorGUI.PrefixLabel(foldoutLabelRect, label);

// Draw the subclass selector popup.
if (EditorGUI.DropdownButton(popupPosition,GetTypeName(property),FocusType.Keyboard)) {
TypePopupCache popup = GetTypePopup(property);
m_TargetProperty = property;
Expand All @@ -54,8 +56,8 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
// Draw the property with custom property drawer.
Rect foldoutRect = new Rect(position);
foldoutRect.height = EditorGUIUtility.singleLineHeight;
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label, true);
property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none, true);

if (property.isExpanded)
{
using (new EditorGUI.IndentLevelScope())
Expand All @@ -70,7 +72,7 @@ public override void OnGUI (Rect position,SerializedProperty property,GUIContent
}
else
{
EditorGUI.PropertyField(position, property, label, true);
EditorGUI.PropertyField(position, property, GUIContent.none, true);
}
} else {
EditorGUI.LabelField(position,label,k_IsNotManagedReferenceLabel);
Expand All @@ -95,7 +97,7 @@ TypePopupCache GetTypePopup (SerializedProperty property) {

if (!m_TypePopups.TryGetValue(managedReferenceFieldTypename,out TypePopupCache result)) {
var state = new AdvancedDropdownState();

Type baseType = ManagedReferenceUtility.GetType(managedReferenceFieldTypename);
var popup = new AdvancedTypePopup(
TypeCache.GetTypesDerivedFrom(baseType).Append(baseType).Where(p =>
Expand All @@ -118,7 +120,7 @@ TypePopupCache GetTypePopup (SerializedProperty property) {

object obj = individualProperty.SetManagedReference(type);
individualProperty.isExpanded = (obj != null);

individualObject.ApplyModifiedProperties();
individualObject.Update();
}
Expand Down

0 comments on commit 69830f3

Please sign in to comment.