1- using System ;
1+ using System ;
22using System . Collections . Generic ;
33using System . Reflection ;
44using UnityEditor ;
@@ -142,15 +142,24 @@ protected override void OnGuiBeginSafe(BeginTabGroupAttribute attribute)
142142 if ( currentIndex == - 1 )
143143 currentIndex = 0 ;
144144
145+ //TODO: GroupId + Optional Label
145146 DrawGroupHeader ( attribute . GroupId ) ;
146- EditorGUILayout . BeginVertical ( EditorStyles . helpBox ) ;
147+
148+ //TODO: temp, make it static if needed
149+ var style = new GUIStyle ( EditorStyles . helpBox ) ;
150+ style . margin = new RectOffset ( 0 , 0 , 0 , 0 ) ;
151+ style . contentOffset = Vector2 . zero ;
152+ style . border = new RectOffset ( 0 , 0 , 0 , 0 ) ;
153+ style . padding = new RectOffset ( 1 , 1 , 1 , 1 ) ;
154+ EditorGUILayout . BeginVertical ( style ) ;
147155
148156 int newIndex = DrawResponsiveTabs ( currentIndex , tabs , attribute . Visual ) ;
149157
150158 if ( newIndex != currentIndex )
151159 {
152160 TabState . Set ( attribute . GroupId , tabs [ newIndex ] ) ;
153161
162+ //TODO: is it needed?
154163 GUI . FocusControl ( null ) ;
155164 EditorGUIUtility . keyboardControl = 0 ;
156165 EditorWindow . focusedWindow ? . Repaint ( ) ;
@@ -185,11 +194,7 @@ private static void DrawGroupHeader(string groupId)
185194 GUILayout . Space ( TopSpacing ) ;
186195 }
187196
188- private static int DrawResponsiveTabs (
189- int currentIndex ,
190- List < string > tabs ,
191- TabGroupVisual visual
192- )
197+ private static int DrawResponsiveTabs ( int currentIndex , List < string > tabs , TabGroupVisual visual )
193198 {
194199 float viewWidth = EditorGUIUtility . currentViewWidth - ViewWidthPadding ;
195200
@@ -198,16 +203,13 @@ TabGroupVisual visual
198203
199204 RotateRowsToShowActiveTabLast ( rows , currentIndex ) ;
200205
201- int newIndex = DrawTabRows ( rows , currentIndex , tabs , tabWidths , visual ) ;
206+ int newIndex = DrawTabRows ( rows , currentIndex , tabs , visual ) ;
202207
203208 return newIndex ;
204209 }
205210
206- private static List < float > CalculateTabWidths (
207- List < string > tabs ,
208- GUIStyle style ,
209- float viewWidth
210- )
211+ //TODO: remove it
212+ private static List < float > CalculateTabWidths ( List < string > tabs , GUIStyle style , float viewWidth )
211213 {
212214 var tabWidths = new List < float > ( tabs . Count ) ;
213215
@@ -297,41 +299,27 @@ private static int FindRowContainingTab(List<List<int>> rows, int tabIndex)
297299 return 0 ;
298300 }
299301
300- private static int DrawTabRows (
301- List < List < int > > rows ,
302- int currentIndex ,
303- List < string > tabs ,
304- List < float > tabWidths ,
305- TabGroupVisual visual
306- )
302+ private static int DrawTabRows ( List < List < int > > rows , int currentIndex , List < string > tabs , TabGroupVisual visual )
307303 {
308304 int newIndex = currentIndex ;
309-
310- EditorGUILayout . BeginVertical ( ) ;
311-
312- for ( int r = 0 ; r < rows . Count ; r ++ )
305+ using ( new EditorGUILayout . VerticalScope ( ) )
313306 {
314- var row = rows [ r ] ;
315-
316- EditorGUILayout . BeginHorizontal ( ) ;
317- GUILayout . FlexibleSpace ( ) ;
318-
319- newIndex = DrawTabRow ( row , currentIndex , newIndex , tabs , tabWidths , visual ) ;
320-
321- GUILayout . FlexibleSpace ( ) ;
322- EditorGUILayout . EndHorizontal ( ) ;
307+ for ( int r = 0 ; r < rows . Count ; r ++ )
308+ {
309+ var row = rows [ r ] ;
310+ GUILayout . BeginHorizontal ( ) ;
311+ newIndex = DrawTabButton ( row , currentIndex , newIndex , tabs , visual ) ;
312+ GUILayout . EndHorizontal ( ) ;
313+ }
323314
324- if ( r < rows . Count - 1 )
325- GUILayout . Space ( RowSpacing ) ;
315+ GUILayout . Space ( RowSpacing ) ;
326316 }
327317
328- GUILayout . Space ( RowSpacing ) ;
329- EditorGUILayout . EndVertical ( ) ;
330-
331318 return newIndex ;
332319 }
333320
334- private static int DrawTabRow (
321+ //TODO: old
322+ private static int DrawTabRowOld (
335323 List < int > row ,
336324 int currentIndex ,
337325 int newIndex ,
@@ -382,30 +370,72 @@ TabGroupVisual visual
382370 return newIndex ;
383371 }
384372
385- private static GUIStyle GetStyleForVisual (
386- TabGroupVisual visual ,
387- int index ,
388- int count ,
389- bool isActive
390- )
373+ private static int DrawTabButton ( List < int > row , int currentIndex , int newIndex , List < string > tabs , TabGroupVisual visual )
374+ {
375+ for ( int i = 0 ; i < row . Count ; i ++ )
376+ {
377+ int tabIndex = row [ i ] ;
378+ bool isActive = tabIndex == currentIndex ;
379+ var content = new GUIContent ( tabs [ tabIndex ] ) ;
380+
381+ GUIStyle style = GetStyleForVisual ( visual , i , row . Count , isActive ) ;
382+
383+ Color prevBg = GUI . backgroundColor ;
384+
385+ switch ( visual )
386+ {
387+ case TabGroupVisual . Flat :
388+ GUI . backgroundColor = isActive ? ActiveBgColor : GUI . backgroundColor ;
389+ break ;
390+
391+ case TabGroupVisual . Segmented :
392+
393+ GUI . backgroundColor = isActive
394+ ? ActiveBgColor
395+ : GUI . backgroundColor * InactiveBgMultiplier ;
396+ break ;
397+
398+ default :
399+ GUI . backgroundColor = isActive
400+ ? ActiveBgColor
401+ : GUI . backgroundColor * InactiveBgMultiplier ;
402+ style = isActive ? ActiveTabStyle : BaseTabStyle ;
403+ break ;
404+ }
405+
406+ bool pressed = GUILayout . Toggle ( isActive , content , style ) ;
407+ GUI . backgroundColor = prevBg ;
408+
409+ if ( pressed && ! isActive )
410+ newIndex = tabIndex ;
411+ }
412+
413+ return newIndex ;
414+ }
415+
416+ private static GUIStyle GetStyleForVisual ( TabGroupVisual visual , int index , int count , bool isActive )
391417 {
392418 switch ( visual )
393419 {
394420 case TabGroupVisual . Flat :
395421 return isActive ? FlatActiveStyle : FlatStyle ;
396-
397422 case TabGroupVisual . Segmented :
398423 if ( count == 1 )
424+ {
399425 return isActive ? SegmentActive : SegmentMid ;
426+ }
400427
401428 if ( index == 0 )
429+ {
402430 return SegmentLeft ;
431+ }
403432
404433 if ( index == count - 1 )
434+ {
405435 return SegmentRight ;
436+ }
406437
407438 return isActive ? SegmentActive : SegmentMid ;
408-
409439 default :
410440 return isActive ? ActiveTabStyle : BaseTabStyle ;
411441 }
0 commit comments