Skip to content

Commit d5d14ee

Browse files
committed
Hide foldout for properties without children
1 parent 0d7de3d commit d5d14ee

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

Assets/Editor Toolbox/Editor/Drawers/Toolbox/PropertySelf/ReferencePickerAttributeDrawer.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ namespace Toolbox.Editor.Drawers
1010

1111
public class ReferencePickerAttributeDrawer : ToolboxSelfPropertyDrawer<ReferencePickerAttribute>
1212
{
13-
private const float neededLabelWidth = 100.0f;
1413
private const float labelWidthOffset = -80.0f;
1514

1615
private static readonly TypeConstraintContext sharedConstraint = new TypeConstraintReference(null);
@@ -89,12 +88,9 @@ private Rect PrepareTypePropertyPosition(in Rect labelPosition, in Rect inputPos
8988
if (isPropertyExpanded)
9089
{
9190
//property is expanded and we have place to move it to the next row
92-
if (labelWidth < neededLabelWidth)
93-
{
94-
position = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
95-
position = EditorGUI.IndentedRect(position);
96-
return position;
97-
}
91+
position = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
92+
position = EditorGUI.IndentedRect(position);
93+
return position;
9894
}
9995

10096
//adjust position to already rendered label

Assets/Editor Toolbox/Editor/Internal/PropertyScope.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@ private void HandleEvents(Rect rect)
3333

3434
private void TryDrawLabel(Rect rect, GUIContent label)
3535
{
36-
LabelRect = rect;
3736
InputRect = rect;
38-
if (property.hasChildren)
37+
var size = EditorStyles.label.CalcSize(label);
38+
rect.xMax = rect.xMin + size.x;
39+
LabelRect = rect;
40+
if (property.hasVisibleChildren)
3941
{
40-
var size = EditorStyles.label.CalcSize(label);
41-
size.x = Mathf.Max(EditorGuiUtility.FoldoutOffset, size.x);
42-
rect.xMax = rect.xMin + size.x;
43-
LabelRect = rect;
44-
property.isExpanded = EditorGUI.Foldout(rect, property.isExpanded, label, true);
42+
var labelRect = LabelRect;
43+
labelRect.xMax += EditorGuiUtility.FoldoutOffset;
44+
LabelRect = labelRect;
45+
property.isExpanded = EditorGUI.Foldout(labelRect, property.isExpanded, label, true);
4546
}
4647
else
4748
{

Assets/Examples/Scenes/SampleScene.unity

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ MonoBehaviour:
583583
id: 1
584584
var3:
585585
id: 2
586+
vars: []
586587
references:
587588
version: 1
588589
00000000:

0 commit comments

Comments
 (0)