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; CacheData cache = s_cache.getData(text, font_index); if (cache.line_count == 0 || cache.width == 0) { WordWrap_Unity.setupFont(style, font_index); cache.width = WordWrap.calcSize(style.richText, text, out int line_count); cache.line_count = line_count; cache.str = text; } __result.x = cache.width + style.padding.horizontal; __result.y = calcHeight(style, font_index, cache.line_count); return(false); }
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); }
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); }
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); }