@@ -18,6 +18,7 @@ static BeginHorizontalGroupAttributeDrawer()
18
18
/// </summary>
19
19
private static readonly ControlDataStorage < Vector2 > storage ;
20
20
21
+ private static float lastFetchedWidth = 0.0f ;
21
22
22
23
private void HandleScrollView ( float fixedHeight )
23
24
{
@@ -29,25 +30,33 @@ private void HandleScrollView(float fixedHeight)
29
30
storage . AppendItem ( controlId , newScroll ) ;
30
31
}
31
32
32
-
33
33
protected override void OnGuiBeginSafe ( BeginHorizontalGroupAttribute attribute )
34
34
{
35
- var fixedWidth = EditorGUIUtility . currentViewWidth ;
36
- var fixedHeight = attribute . Height ;
37
- EditorGUIUtility . labelWidth = fixedWidth * attribute . LabelToWidthRatio ;
38
- EditorGUIUtility . fieldWidth = fixedWidth * attribute . FieldToWidthRatio ;
35
+ if ( GuiLayoutUtility . TryGetLayoutWidth ( out var layoutWidth ) )
36
+ {
37
+ lastFetchedWidth = layoutWidth ;
38
+ }
39
39
40
40
ToolboxLayoutHandler . BeginVertical ( Style . groupBackgroundStyle ) ;
41
41
if ( attribute . HasLabel )
42
42
{
43
43
GUILayout . Label ( attribute . Label , EditorStyles . boldLabel ) ;
44
44
}
45
45
46
- HandleScrollView ( fixedHeight ) ;
46
+ EditorGUIUtility . labelWidth = attribute . LabelWidth ;
47
+ if ( attribute . ControlFieldWidth && attribute . ElementsInLayout > 0 )
48
+ {
49
+ var width = lastFetchedWidth ;
50
+ width -= attribute . WidthOffset ;
51
+ width -= ( attribute . LabelWidth + attribute . WidthOffsetPerElement + EditorGUIUtility . standardVerticalSpacing * 4 ) * attribute . ElementsInLayout ;
52
+ width /= attribute . ElementsInLayout ;
53
+ EditorGUIUtility . fieldWidth = width ;
54
+ }
55
+
56
+ HandleScrollView ( attribute . Height ) ;
47
57
ToolboxLayoutHandler . BeginHorizontal ( ) ;
48
58
}
49
59
50
-
51
60
private static class Style
52
61
{
53
62
internal static readonly GUIStyle groupBackgroundStyle ;
0 commit comments