@@ -30,12 +30,13 @@ public enum NormalizationMode
3030 }
3131
3232 //const int kToolbarHeight = 17;
33- const int kPresetsHeight = 46 ;
33+ const int kPresetsHeight = 50 ;
3434
3535 static CurveEditorWindow s_SharedCurveEditor ;
3636
3737 internal CurveEditor m_CurveEditor ;
3838
39+ Vector2 m_PresetScrollPosition ;
3940 AnimationCurve m_Curve ;
4041 Color m_Color ;
4142
@@ -476,20 +477,38 @@ void OnGUI()
476477 m_CurveEditor . OnGUI ( ) ;
477478
478479 // Preset swatch area
479- GUI . Box ( new Rect ( 0 , position . height - kPresetsHeight , position . width , kPresetsHeight ) , "" , ms_Styles . curveSwatchArea ) ;
480+ var presetRect = new Rect ( 0 , position . height - kPresetsHeight , position . width , kPresetsHeight ) ;
481+ GUI . Box ( presetRect , "" , ms_Styles . curveSwatchArea ) ;
482+
480483 Color curveColor = m_Color ;
481484 curveColor . a *= 0.6f ;
482- const float margin = 45f ;
483485 const float width = 40f ;
484486 const float height = 25f ;
485- float yPos = position . height - kPresetsHeight + ( kPresetsHeight - height ) * 0.5f ;
487+ const float spaceBetweenSwatches = 5f ;
488+ const float presetDropdownSize = 16f ;
489+ const float horizontalScrollbarHeight = 15f ;
490+ const float presetDropdownCenteringOffset = 2f ;
491+ float yPos = ( kPresetsHeight - height ) * 0.5f ;
486492 InitCurvePresets ( ) ;
487493 CurvePresetLibrary curveLibrary = m_CurvePresets . GetPresetLibraryEditor ( ) . GetCurrentLib ( ) ;
488494 if ( curveLibrary != null )
489495 {
490- for ( int i = 0 ; i < curveLibrary . Count ( ) ; i ++ )
496+ var numPresets = curveLibrary . Count ( ) ;
497+ var presetDropDownRect = new Rect ( spaceBetweenSwatches , yPos + presetDropdownCenteringOffset , presetDropdownSize , presetDropdownSize ) ;
498+ Rect contentRect = new Rect ( 0 , 0 , numPresets * ( width + spaceBetweenSwatches ) + presetDropDownRect . xMax , presetRect . height - horizontalScrollbarHeight ) ;
499+ m_PresetScrollPosition = GUI . BeginScrollView (
500+ presetRect , // Rectangle of the visible area
501+ m_PresetScrollPosition , // Current scroll position
502+ contentRect , // Rectangle containing all content
503+ false , // Always show horizontal scrollbar
504+ false // Always show vertical scrollbar
505+ ) ;
506+
507+ PresetDropDown ( presetDropDownRect ) ;
508+
509+ Rect swatchRect = new Rect ( presetDropDownRect . xMax + spaceBetweenSwatches , yPos , width , height ) ;
510+ for ( int i = 0 ; i < numPresets ; i ++ )
491511 {
492- Rect swatchRect = new Rect ( margin + ( width + 5f ) * i , yPos , width , height ) ;
493512 m_GUIContent . tooltip = curveLibrary . GetName ( i ) ;
494513 if ( GUI . Button ( swatchRect , m_GUIContent , ms_Styles . curveSwatch ) )
495514 {
@@ -503,14 +522,11 @@ void OnGUI()
503522 if ( Event . current . type == EventType . Repaint )
504523 curveLibrary . Draw ( swatchRect , i ) ;
505524
506- if ( swatchRect . xMax > position . width - 2 * margin )
507- break ;
525+ swatchRect . x += width + spaceBetweenSwatches ;
508526 }
527+ GUI . EndScrollView ( ) ;
509528 }
510529
511- Rect presetDropDownButtonRect = new Rect ( margin - 20f , yPos + 5f , 20 , 20 ) ;
512- PresetDropDown ( presetDropDownButtonRect ) ;
513-
514530 // For adding default preset curves
515531 //if (EditorGUI.DropdownButton(new Rect (position.width -26, yPos, 20, 20), GUIContent.none, FocusType.Passive, "OL Plus"))
516532 // AddDefaultPresetsToCurrentLib ();
0 commit comments