CalcScreenSize() public method

Calculate the size of an element formatted with this style, and a given space to content.

public CalcScreenSize ( Vector2 contentSize ) : Vector2
contentSize Vector2
return Vector2
 static public int CalcScreenSize(IntPtr l)
 {
     try {
         UnityEngine.GUIStyle self = (UnityEngine.GUIStyle)checkSelf(l);
         UnityEngine.Vector2  a1;
         checkType(l, 2, out a1);
         var ret = self.CalcScreenSize(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int CalcScreenSize(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.GUIStyle obj  = (UnityEngine.GUIStyle)ToLua.CheckObject(L, 1, typeof(UnityEngine.GUIStyle));
         UnityEngine.Vector2  arg0 = ToLua.ToVector2(L, 2);
         UnityEngine.Vector2  o    = obj.CalcScreenSize(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
        public static string Truncate(string source, GUIStyle guiStyle, float width, string truncateString)
        {
            if(source == null) return "";

            int tuncateStringNum = 2;

            GUIContent content = new GUIContent(source);

            while (guiStyle.CalcScreenSize(guiStyle.CalcSize(content)).x > width)
            {
                if (source.Length - tuncateStringNum < 2) break;

                content = new GUIContent(source.Substring(0, source.Length - tuncateStringNum) + truncateString);

                tuncateStringNum++;
            }

            return content.text;
        }