Пример #1
0
        public static bool Text_CalcHeight_prefix(string text, float width, ref float __result)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

            int      font_index = (int)Text.Font;
            GUIStyle style      = Text.CurFontStyle;
            int      line_count;

            {
                CacheData cache = s_cache.getData(text, font_index);

                if (style.wordWrap)
                {
                    if (cache.wrap_line_count == 0 || cache.wrap_width != (int)width)
                    {
                        WordWrap_Unity.setupFont(style, font_index);
                        cache.wrap_str   = WordWrap.wrap(style.richText, text, (int)width, out cache.wrap_line_count);
                        cache.wrap_width = (int)width;
                    }
                    line_count = cache.wrap_line_count;
                }
                else
                {
                    if (cache.line_count == 0)
                    {
                        cache.line_count = lineCount(text);
                        cache.str        = text;
                    }
                    line_count = cache.line_count;
                }
            }

            __result = calcHeight(style, font_index, line_count);

            return(false);
        }
Пример #2
0
        public static bool Widgets_Label_prefix(Rect rect, string label)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return(false);
            }

            if (string.IsNullOrEmpty(label))
            {
                return(false);
            }

            float scale = Prefs.UIScale;

            if (scale > 1f)
            {
                float num = scale / 2f;
                if (Math.Abs(num - Mathf.Floor(num)) > Single.Epsilon)
                {
                    rect.xMin = Widgets.AdjustCoordToUIScalingFloor(rect.xMin);
                    rect.yMin = Widgets.AdjustCoordToUIScalingFloor(rect.yMin);
                    rect.xMax = Widgets.AdjustCoordToUIScalingCeil(rect.xMax + 1E-05f);                    // + 0.00001f
                    rect.yMax = Widgets.AdjustCoordToUIScalingCeil(rect.yMax + 1E-05f);
                }
            }

            int      font_index = (int)Text.Font;
            GUIStyle style      = Text.CurFontStyle;
            int      line_count;

            {
                CacheData cache = s_cache.getData(label, font_index);
                if (style.wordWrap)
                {
                    if (cache.wrap_line_count == 0 || cache.wrap_width != (int)rect.width)
                    {
                        WordWrap_Unity.setupFont(style, font_index);
                        cache.wrap_str   = WordWrap.wrap(style.richText, label, (int)rect.width, out cache.wrap_line_count);
                        cache.wrap_width = (int)rect.width;
                    }
                    label      = cache.wrap_str;
                    line_count = cache.wrap_line_count;
                }
                else
                {
                    if (cache.line_count == 0)
                    {
                        cache.line_count = lineCount(label);
                        cache.str        = label;
                    }
                    label      = cache.str;
                    line_count = cache.line_count;
                }
            }


            int text_height = calcHeight(style, font_index, line_count);

            TextAnchor alignment = style.alignment;
            float      offset_y;

            switch (alignment)
            {
            case TextAnchor.MiddleLeft:
                offset_y        = rect.height / 2 - text_height / 2;
                style.alignment = TextAnchor.UpperLeft;
                break;

            case TextAnchor.MiddleCenter:
                offset_y        = rect.height / 2 - text_height / 2;
                style.alignment = TextAnchor.UpperCenter;
                break;

            case TextAnchor.MiddleRight:
                offset_y        = rect.height / 2 - text_height / 2;
                style.alignment = TextAnchor.UpperRight;
                break;

            case TextAnchor.LowerLeft:
                offset_y        = rect.height - text_height;
                style.alignment = TextAnchor.UpperLeft;
                break;

            case TextAnchor.LowerCenter:
                offset_y        = rect.height - text_height;
                style.alignment = TextAnchor.UpperCenter;
                break;

            case TextAnchor.LowerRight:
                offset_y        = rect.height - text_height;
                style.alignment = TextAnchor.UpperRight;
                break;

            default:
                offset_y = 0;
                break;
            }
            rect.y += offset_y;

            bool ww = style.wordWrap;

            style.wordWrap = false;
            GUI.Label(rect, label, style);
            style.wordWrap  = ww;
            style.alignment = alignment;

            return(false);
        }