public static float HeightWithLabel(Metadata metadata, float width, float height, GUIContent label = null, GUIStyle labelStyle = null) { label = ProcessLabel(metadata, label); if (label == GUIContent.none) { return(height); } var labelWidth = LabelWidth(metadata, width); labelStyle = ProcessLabelStyle(metadata, labelStyle); var wide = metadata.HasAttribute <InspectorWideAttribute>(); var labelHeight = labelStyle.CalcHeight(label, labelWidth); if (expandTooltip.value || metadata.HasAttribute <InspectorExpandTooltipAttribute>()) { var tooltipHeight = StringUtility.IsNullOrWhiteSpace(label.tooltip) ? 0 : LudiqStyles.expandedTooltip.CalcHeight(new GUIContent(label.tooltip), labelWidth); if (wide) { height += labelHeight + tooltipHeight; } else { height = Mathf.Max(height, labelHeight + tooltipHeight); } } else { if (wide) { height += labelHeight; } else { height = Mathf.Max(height, labelHeight); } } return(height); }
public void Draw(Rect position, GUIContent label = null) { if (SkipEvent(Event.current, position)) { return; } if (failure == null) { try { var oldIndent = EditorGUI.indentLevel; if (!indent) { EditorGUI.indentLevel = 0; } EditorGUI.BeginDisabledGroup(EditorApplication.isCompiling && !EditorApplicationUtility.isAssemblyReloadLocked); var drawerPosition = position; if (profile) { var drawerHeight = position.height - GetProfilingHeight(); drawerPosition = new Rect ( position.x, position.y, position.width, drawerHeight ); } if (editLocked) { if (GUI.Button(drawerPosition, GUIContent.none, GUIStyle.none)) { if (EditorUtility.DisplayDialog(warnBeforeEditingAttribute.warningTitle, warnBeforeEditingAttribute.warningMessage, "Edit", "Cancel")) { editLocked = false; } } } EditorGUI.BeginDisabledGroup(editLocked); y = drawerPosition.y; if (metadata.HasAttribute <EditorPrefAttribute>()) { BeginProfiling("OnEditorPrefGUI"); OnEditorPrefGUI(drawerPosition, ProcessLabel(metadata, label)); EndProfiling("OnEditorPrefGUI"); } else { BeginProfiling("OnGUI"); OnGUI(drawerPosition, ProcessLabel(metadata, label)); EndProfiling("OnGUI"); } EditorGUI.EndDisabledGroup(); if (profile) { var profilingPosition = new Rect ( position.x, drawerPosition.yMax, position.width, position.height - drawerPosition.height ); OnProfilingGUI(profilingPosition); } EditorGUI.EndDisabledGroup(); if (!indent) { EditorGUI.indentLevel = oldIndent; } } catch (ExitGUIException) { // http://answers.unity3d.com/questions/385235 throw; } catch (Exception ex) { if (safe) { failure = ex; } else { throw; } } } if (safe && failure != null) { EditorGUI.HelpBox(position, $"Error drawing {GetType().Name}.", MessageType.Warning); if (GUI.Button(position, GUIContent.none, GUIStyle.none)) { Debug.LogException(failure); } } }
public static Rect PrefixLabel(Metadata metadata, Rect position, GUIContent label = null, GUIStyle style = null) { label = ProcessLabel(metadata, label); if (label == GUIContent.none) { return(position); } var width = LabelWidth(metadata, position.width); style = ProcessLabelStyle(metadata, style); var wide = metadata.HasAttribute <InspectorWideAttribute>(); var y = position.y; var labelPosition = new Rect ( position.x, position.y, width, style.CalcHeight(label, width) ); y = labelPosition.yMax + 2; var expandTooltip = Inspector.expandTooltip || metadata.HasAttribute <InspectorExpandTooltipAttribute>(); EditorGUI.LabelField(labelPosition, expandTooltip ? new GUIContent(label.text, label.image) : label, style); if (BoltCore.Configuration.developerMode && BoltCore.Configuration.debugInspectorGUI && e.type == EventType.Repaint) { labelDebugBox.Draw(labelPosition, false, false, false, false); } if (expandTooltip) { var tooltip = new GUIContent(label.tooltip); var tooltipPosition = new Rect ( position.x, y - 2, width, LudiqStyles.expandedTooltip.CalcHeight(tooltip, width) ); EditorGUI.LabelField(tooltipPosition, tooltip, LudiqStyles.expandedTooltip); if (BoltCore.Configuration.developerMode && BoltCore.Configuration.debugInspectorGUI && e.type == EventType.Repaint) { labelDebugBox.Draw(tooltipPosition, false, false, false, false); } y = tooltipPosition.yMax - 4; } Rect remainingPosition; if (wide) { remainingPosition = new Rect ( position.x, y, position.width, position.height - labelPosition.height ); } else { remainingPosition = new Rect ( labelPosition.xMax, position.y, position.width - labelPosition.width, position.height ); } return(remainingPosition); }