Example #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;
            string   str = text;

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

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

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

                WordWrap_Unity.setupFont(style, font_index);
                string new_label = WordWrap.modify(str, (int)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;
            }
            else
            {
                if (cache.width == 0)
                {
                    s_calcSize(style, font_index, str, cache);
                }

                line_count = cache.line_count;
            }
end:
            __result = calcHeight(style, font_index, line_count);

            return(false);
        }
Example #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);
            }

            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);
        }