A game about forced loneliness, made by TACStudios
at master 2.1 kB view raw
1using System; 2 3using UnityEditor; 4using UnityEngine; 5 6namespace Unity.PlasticSCM.Editor.UI 7{ 8 internal static class DrawActionButtonWithMenu 9 { 10 internal static GUIStyle ButtonStyle { get { return mButtonStyle; } } 11 12 internal static void For( 13 string text, 14 string tooltip, 15 Action buttonAction, 16 GenericMenu actionMenu) 17 { 18 float width = MeasureMaxWidth.ForTexts(mButtonStyle, text); 19 20 For(text, tooltip, width, buttonAction, actionMenu); 21 } 22 23 internal static void For( 24 string text, 25 string tooltip, 26 float width, 27 Action buttonAction, 28 GenericMenu actionMenu) 29 { 30 // Action button 31 GUIContent buttonContent = new GUIContent(text, tooltip); 32 33 Rect rt = GUILayoutUtility.GetRect( 34 buttonContent, 35 mButtonStyle, 36 GUILayout.MinWidth(width), 37 GUILayout.MaxWidth(width)); 38 39 if (GUI.Button(rt, buttonContent, mButtonStyle)) 40 { 41 buttonAction(); 42 } 43 44 // Menu dropdown 45 GUIContent dropDownContent = new GUIContent( 46 string.Empty, Images.GetDropDownIcon()); 47 48 Rect dropDownRect = GUILayoutUtility.GetRect( 49 dropDownContent, 50 mDropDownStyle, 51 GUILayout.MinWidth(DROPDOWN_BUTTON_WIDTH), 52 GUILayout.MaxWidth(DROPDOWN_BUTTON_WIDTH)); 53 54 if (EditorGUI.DropdownButton( 55 dropDownRect, dropDownContent, FocusType.Passive, mDropDownStyle)) 56 { 57 actionMenu.DropDown(dropDownRect); 58 } 59 } 60 61 static readonly GUIStyle mButtonStyle = 62 new GUIStyle(EditorStyles.miniButtonLeft) 63 { 64 stretchWidth = false 65 }; 66 67 static readonly GUIStyle mDropDownStyle = 68 new GUIStyle(EditorStyles.miniButtonRight); 69 70 const int DROPDOWN_BUTTON_WIDTH = 16; 71 } 72}