A game about forced loneliness, made by TACStudios
fork

Configure Feed

Select the types of activity you want to include in your feed.

at master 143 lines 6.0 kB view raw
1using System; 2using UnityEditor; 3using UnityEngine; 4 5namespace UnityEditor.U2D.Common 6{ 7 /// <summary> 8 /// Utilities to draw foldout headers in Inspector 9 /// </summary> 10 internal class InspectorUtils 11 { 12 /// <summary>Draw a splitter separator</summary> 13 /// <param name="isBoxed">[Optional] add margin if the splitter is boxed</param> 14 public static void DrawSplitter(bool isBoxed = false) 15 { 16 var rect = GUILayoutUtility.GetRect(1f, 1f); 17 float xMin = rect.xMin; 18 19 // Splitter rect should be full-width 20 rect.xMin = 0f; 21 rect.width += 4f; 22 23 if (isBoxed) 24 { 25 rect.xMin = xMin == 7.0 ? 4.0f : EditorGUIUtility.singleLineHeight; 26 rect.width -= 1; 27 } 28 29 if (Event.current.type != EventType.Repaint) 30 return; 31 32 EditorGUI.DrawRect(rect, !EditorGUIUtility.isProSkin 33 ? new Color(0.6f, 0.6f, 0.6f, 1.333f) 34 : new Color(0.12f, 0.12f, 0.12f, 1.333f)); 35 } 36 37 /// <summary>Draw a header</summary> 38 /// <param name="title">Title of the header</param> 39 public static void DrawHeader(string title) 40 => DrawHeader(EditorGUIUtility.TrTextContent(title)); 41 42 /// <summary>Draw a header</summary> 43 /// <param name="title">Title of the header</param> 44 public static void DrawHeader(GUIContent title) 45 { 46 var backgroundRect = GUILayoutUtility.GetRect(1f, 17f); 47 48 var labelRect = backgroundRect; 49 labelRect.xMax -= 20f; 50 51 var foldoutRect = backgroundRect; 52 foldoutRect.y += 1f; 53 foldoutRect.width = 13f; 54 foldoutRect.height = 13f; 55 56 // Background rect should be full-width 57 backgroundRect.xMin = 0f; 58 backgroundRect.width += 4f; 59 60 // Background 61 float backgroundTint = EditorGUIUtility.isProSkin ? 0.1f : 1f; 62 EditorGUI.DrawRect(backgroundRect, new Color(backgroundTint, backgroundTint, backgroundTint, 0.2f)); 63 64 // Title 65 EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); 66 } 67 68 /// <summary> Draw a foldout header </summary> 69 /// <param name="title"> The title of the header </param> 70 /// <param name="state"> The state of the header </param> 71 /// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param> 72 /// <param name="hasMoreOptions"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param> 73 /// <param name="toggleMoreOption"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param> 74 /// <returns>return the state of the foldout header</returns> 75 public static bool DrawHeaderFoldout(string title, bool state, bool isBoxed = false, Func<bool> hasMoreOptions = null, Action toggleMoreOption = null) 76 => DrawHeaderFoldout(EditorGUIUtility.TrTextContent(title), state, isBoxed, hasMoreOptions, toggleMoreOption); 77 78 /// <summary> Draw a foldout header </summary> 79 /// <param name="title"> The title of the header </param> 80 /// <param name="state"> The state of the header </param> 81 /// <param name="isBoxed"> [optional] is the eader contained in a box style ? </param> 82 /// <param name="hasMoreOptions"> [optional] Delegate used to draw the right state of the advanced button. If null, no button drawn. </param> 83 /// <param name="toggleMoreOptions"> [optional] Callback call when advanced button clicked. Should be used to toggle its state. </param> 84 /// <returns>return the state of the foldout header</returns> 85 public static bool DrawHeaderFoldout(GUIContent title, bool state, bool isBoxed = false, Func<bool> hasMoreOptions = null, Action toggleMoreOptions = null) 86 { 87 const float height = 17f; 88 var backgroundRect = GUILayoutUtility.GetRect(1f, height); 89 float xMin = backgroundRect.xMin; 90 91 var labelRect = backgroundRect; 92 labelRect.xMin += 16f; 93 labelRect.xMax -= 20f; 94 95 var foldoutRect = backgroundRect; 96 foldoutRect.y += 1f; 97 foldoutRect.width = 13f; 98 foldoutRect.height = 13f; 99 foldoutRect.x = labelRect.xMin + 15 * (EditorGUI.indentLevel - 1); //fix for presset 100 101 // More options 1/2 102 var moreOptionsRect = new Rect(); 103 if (hasMoreOptions != null) 104 { 105 moreOptionsRect = backgroundRect; 106 moreOptionsRect.x += moreOptionsRect.width - 16 - 1; 107 moreOptionsRect.height = 15; 108 moreOptionsRect.width = 16; 109 } 110 111 // Background rect should be full-width 112 backgroundRect.xMin = 0f; 113 backgroundRect.width += 4f; 114 115 if (isBoxed) 116 { 117 labelRect.xMin += 5; 118 foldoutRect.xMin += 5; 119 backgroundRect.xMin = xMin == 7.0 ? 4.0f : EditorGUIUtility.singleLineHeight; 120 backgroundRect.width -= 1; 121 } 122 123 // Background 124 float backgroundTint = EditorGUIUtility.isProSkin ? 0.1f : 1f; 125 EditorGUI.DrawRect(backgroundRect, new Color(backgroundTint, backgroundTint, backgroundTint, 0.2f)); 126 127 // Title 128 EditorGUI.LabelField(labelRect, title, EditorStyles.boldLabel); 129 130 // Active checkbox 131 state = GUI.Toggle(foldoutRect, state, GUIContent.none, EditorStyles.foldout); 132 133 var e = Event.current; 134 if (e.type == EventType.MouseDown && backgroundRect.Contains(e.mousePosition) && !moreOptionsRect.Contains(e.mousePosition) && e.button == 0) 135 { 136 state = !state; 137 e.Use(); 138 } 139 140 return state; 141 } 142 } 143}