Exemplo n.º 1
0
        public static void GetLabelAndControlRects(this Rect fullRect, out Rect labelRect, out Rect controlRect)
        {
                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(fullRect.width.Equals(DrawGUI.GetCurrentDrawAreaWidth()), "GetLabelAndControlRects : fullRect.width (" + fullRect.width + ") != DrawGUI.GetCurrentDrawAreaWidth() (" + DrawGUI.GetCurrentDrawAreaWidth() + ")");
                        #endif

            labelRect = fullRect;

            float indent = DrawGUI.IndentLevel * DrawGUI.IndentWidth;

            labelRect.x      = fullRect.x + DrawGUI.LeftPadding + indent;
            labelRect.height = DrawGUI.SingleLineHeight;
            float prefixWidth = DrawGUI.PrefixLabelWidth;
            labelRect.width = prefixWidth - DrawGUI.LeftPadding - indent - DrawGUI.MiddlePadding;

            controlRect       = fullRect;
            controlRect.x     = fullRect.x + prefixWidth + DrawGUI.MiddlePadding;
            controlRect.width = fullRect.width - prefixWidth - DrawGUI.MiddlePadding - DrawGUI.RightPadding;

                        #if DEV_MODE && PI_ASSERTATIONS
            Debug.Assert(labelRect.width > 0f || DrawGUI.PrefixLabelWidth <= DrawGUI.LeftPadding + indent + DrawGUI.MiddlePadding, "labelRect " + labelRect + " from fullRect " + fullRect + " with PrefixLabelWidth=" + DrawGUI.PrefixLabelWidth + ", Indent=" + indent + ", LeftPadding = " + DrawGUI.LeftPadding + " and MiddlePadding=" + DrawGUI.MiddlePadding);
            Debug.Assert(controlRect.width > 0f, "controlRect " + controlRect + " from fullRect " + fullRect);
                        #endif
        }
Exemplo n.º 2
0
        /// <summary>
        /// Split the Rect into prefix label and control components.
        /// If fullRect is the full width of the inspector, then labelRect width will be set to DrawGUI.PrefixLabelWidth,
        /// and controlRect width will basically be the remainder of the full width.
        /// If fullRect width is less than the width of the inspector, then labelRect width will be just enough to display a single letter
        /// and the controlRect will get all the rest of the fullRect's width.
        /// </summary>
        /// <param name="fullRect">
        /// The fullRect to act on. </param>
        /// <param name="label">
        /// The label which will be displayed inside the labelRect.
        /// If the label has no text, then the control will take the whole width of the fullRect.
        /// If the label has a tooltip, and placeTooltipsBehindIcons setting is true, then the
        /// controlRect x position and width will be adjusted to leave room for the tooltip icon. </param>
        /// <param name="labelRect">
        /// [out] The rectangle where the label should be drawn. </param>
        /// <param name="controlRect">
        /// [out] The rectangle where the control should be drawn. </param>
        public static void GetLabelAndControlRects(this Rect fullRect, GUIContent label, out Rect labelRect, out Rect controlRect)
        {
                        #if SAFE_MODE
            if (label == null)
            {
                                #if DEV_MODE
                Debug.LogWarning("GetLabelAndControlRects - label was null!");
                                #endif
                label = GUIContent.none;
            }

            if (label.text == null)
            {
                                #if DEV_MODE
                Debug.LogWarning("GetLabelAndControlRects - label.text was null!");
                                #endif
                if (label.image == null)
                {
                    label = GUIContent.none;
                }
                else
                {
                    label = new GUIContent("", label.image, label.tooltip);
                }
            }
                        #endif

            var fullDrawAreaWidth = DrawGUI.GetCurrentDrawAreaWidth();

            if (label.text.Length == 0 && label.image == null)
            {
                //added this fix for stuff like Button not respecting edge paddings
                //when drawn in full width with no label
                if (fullRect.width + DrawGUI.LeftPadding >= fullDrawAreaWidth)
                {
                    float leftOffset = DrawGUI.LeftPadding + DrawGUI.IndentLevel * DrawGUI.IndentWidth;
                    fullRect.x     = fullRect.x + leftOffset;
                    fullRect.width = fullRect.width - leftOffset - DrawGUI.RightPadding;
                }

                labelRect       = fullRect;
                labelRect.width = 0f;
                controlRect     = fullRect;
            }
            //indent width reduction was needed after adding fix for property drawers being drawn
            //too close to left edge of inspector
            else
            {
                if (fullDrawAreaWidth - fullRect.width > DrawGUI.ScrollBarWidth)
                {
                    labelRect   = fullRect;
                    controlRect = fullRect;
                    if (fullRect.width >= DrawGUI.MinWidthWithSingleLetterPrefix)
                    {
                        labelRect.width    = InspectorPreferences.Styles.Label.CalcSize(label).x;
                        controlRect.x     += labelRect.width;
                        controlRect.width -= labelRect.width;

                                                #if DEV_MODE && DEBUG_SINGLE_LETTER_WIDTH
                        DebugUtility.LogChanges(label.text + "_SingleLetterWidth" + fullRect, "Changing " + label.text + " labelRect.width to SingleLetterPrefixWidth because InspectorWidth (" + DrawGUI.InspectorWidth + ") - fullRect.width (" + fullRect.width + ") > " + DrawGUI.ScrollBarWidth);
                                                #endif
                    }
                    //dynamically hide the prefix label if there's not enough space
                    else
                    {
                                                #if DEV_MODE && DEBUG_HIDE_LABELS
                        Debug.LogWarning("Hiding " + label.text + " labelRect because not enough space...");
                                                #endif

                        labelRect.width = 0f;
                    }
                }
                else
                {
                    GetLabelAndControlRects(fullRect, out labelRect, out controlRect);
                }
            }

            //Add room for the tooltip icon
            if (InspectorUtility.Preferences.enableTooltipIcons && label.tooltip.Length > 0)
            {
                controlRect.x     += DrawGUI.SingleLineHeight;
                controlRect.width -= DrawGUI.SingleLineHeight;
            }
        }