UnityEngine.GUIStyle.CalcHeight C# (CSharp) Method

CalcHeight() public method

How tall this element will be when rendered with content and a specific width.

public CalcHeight ( GUIContent content, float width ) : float
content GUIContent
width float
return float
        public float CalcHeight(GUIContent content, float width)
        {
            return Internal_CalcHeight(this.m_Ptr, content, width);
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Calculates text height by ignoring bold style of the font. This will not work with inline bold tags.
        /// NOTE: This will not fix occasional new line when text ends right before end.
        /// </summary>
        /// <param name="content">Text content.</param>
        /// <param name="style">Text style.</param>
        /// <param name="width">Fixed width of text container.</param>
        /// <returns>Returns calculated height of the text.</returns>
        public static float CalculateHeight(GUIContent content, GUIStyle style, float width)
        {
            float height;

            // Bold fonts have much higher chance of having one new line to many than normal font.
            // There were no issues with missing new lines even with couple of extreme cases. (but extra new lines can occur)
            if (style.fontStyle == FontStyle.Bold)
            {
                style.fontStyle = FontStyle.Normal;
                style.wordWrap = true;
                style.fixedWidth = width;
                style.fixedHeight = 0;

                Texture2D t = new Texture2D(1,1);
                content.image = t;
                style.imagePosition = ImagePosition.ImageLeft;

                float min, max;
                style.CalcMinMaxWidth(content, out min, out max);

                style.clipping = TextClipping.Overflow;
                height = style.CalcHeight(content, min);
                style.fontStyle = FontStyle.Bold;
            }
            else
            {
                height = style.CalcHeight(content, width);
            }

            return height;
        }
All Usage Examples Of UnityEngine.GUIStyle::CalcHeight