@@ -18,6 +18,7 @@ static BeginHorizontalGroupAttributeDrawer()
1818 /// </summary>
1919 private static readonly ControlDataStorage < Vector2 > storage ;
2020
21+ private static float lastFetchedWidth = 0.0f ;
2122
2223 private void HandleScrollView ( float fixedHeight )
2324 {
@@ -29,25 +30,33 @@ private void HandleScrollView(float fixedHeight)
2930 storage . AppendItem ( controlId , newScroll ) ;
3031 }
3132
32-
3333 protected override void OnGuiBeginSafe ( BeginHorizontalGroupAttribute attribute )
3434 {
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+ }
3939
4040 ToolboxLayoutHandler . BeginVertical ( Style . groupBackgroundStyle ) ;
4141 if ( attribute . HasLabel )
4242 {
4343 GUILayout . Label ( attribute . Label , EditorStyles . boldLabel ) ;
4444 }
4545
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 ) ;
4757 ToolboxLayoutHandler . BeginHorizontal ( ) ;
4858 }
4959
50-
5160 private static class Style
5261 {
5362 internal static readonly GUIStyle groupBackgroundStyle ;
0 commit comments