Exemple #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);
        }
        static void s_calcSize(GUIStyle style, int font_index, string str, CacheData cache)
        {
            int line_count = 1;

            s_content.text = str;
            Vector2 size = style.CalcSize(s_content);

            // bug fix
            int index = str.IndexOfAny(s_CRLF);

            while (index >= 0)
            {
                line_count++;

                if (str[index] == '\r')
                {
                    index++;
                    if (index < str.Length && str[index] == '\n')
                    {
                        index++;
                    }
                }
                else
                {
                    index++;
                }
                if (index >= str.Length)
                {
                    break;
                }

                index = str.IndexOfAny(s_CRLF, index);
            }

            cache.width      = (int)size.x;
            cache.line_count = line_count;
        }
        public static bool Text_CalcSize_prefix(string text, ref Vector2 __result)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(false);
            }

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

            string str = text;

            CacheData cache = s_cache.getData(str, font_index);

            if (cache.width == 0)
            {
                s_calcSize(style, font_index, str, cache);
            }

            __result.x = cache.width;
            __result.y = calcHeight(style, font_index, cache.line_count);

            return(false);
        }
Exemple #4
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);
        }
        public static bool Widgets_Label_prefix(Rect rect, string label)
        {
            if (Event.current.type != EventType.Repaint)
            {
                return(false);
            }

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

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

            string str   = label;
            int    width = (int)rect.width;

            int line_count;

            CacheData cache = s_cache.getData(str, font_index);

            if (style.wordWrap)
            {
                if (cache.width != 0 && cache.width <= width)
                {
                    line_count = cache.line_count;
                    goto end;
                }

                if (
                    (cache.wrap_width == width) ||
                    (cache.wrap_width != 0 && cache.wrap_str == null && cache.wrap_width <= width)
                    )
                {
                    line_count = cache.wrap_line_count;
                    if (cache.wrap_str != null)
                    {
                        str = cache.wrap_str;
                    }
                    goto end;
                }

                WordWrap_Unity.setupFont(style, font_index);
                string new_label = WordWrap.modify(str, width, out line_count);

                cache.wrap_width      = (int)width;
                cache.wrap_line_count = line_count;
                cache.wrap_str        = new_label;

                line_count = cache.wrap_line_count;
                if (cache.wrap_str != null)
                {
                    str = cache.wrap_str;
                }
            }
            else
            {
                if (cache.width == 0)
                {
                    s_calcSize(style, font_index, str, cache);
                }
                line_count = cache.line_count;
            }
end:
            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, str, style);
            style.wordWrap  = ww;
            style.alignment = alignment;

            return(false);
        }