Beispiel #1
0
 public float ComputeTextWidth(MeshGenerationContextUtils.TextParams parms, float scaling)
 {
     if (useLegacy)
     {
         return(TextNative.ComputeTextWidth(
                    MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling)));
     }
     UpdatePreferredValues(parms);
     return(m_PreferredSize.x);
 }
        internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string textToMeasure, float width, MeasureMode widthMode, float height, MeasureMode heightMode)
        {
            float measuredWidth  = float.NaN;
            float measuredHeight = float.NaN;

            Font usedFont = ve.computedStyle.unityFont.value;

            if (textToMeasure == null || usedFont == null)
            {
                return(new Vector2(measuredWidth, measuredHeight));
            }

            var elementScaling = ve.ComputeGlobalScale();

            float pixelsPerPoint = (ve.elementPanel != null) ? ve.elementPanel.currentPixelsPerPoint : GUIUtility.pixelsPerPoint;
            float scaling        = (elementScaling.x + elementScaling.y) * 0.5f * pixelsPerPoint;

            if (widthMode == MeasureMode.Exactly)
            {
                measuredWidth = width;
            }
            else
            {
                var textSettings = GetTextNativeSettings(ve, textToMeasure, scaling);
                textSettings.wordWrapWidth = 0.0f;
                textSettings.wordWrap      = false;

                //we make sure to round up as yoga could decide to round down and text would start wrapping
                measuredWidth = Mathf.Ceil(TextNative.ComputeTextWidth(textSettings));

                if (widthMode == MeasureMode.AtMost)
                {
                    measuredWidth = Mathf.Min(measuredWidth, width);
                }
            }

            if (heightMode == MeasureMode.Exactly)
            {
                measuredHeight = height;
            }
            else
            {
                var textSettings = GetTextNativeSettings(ve, textToMeasure, scaling);
                textSettings.wordWrapWidth = measuredWidth;
                measuredHeight             = Mathf.Ceil(TextNative.ComputeTextHeight(textSettings));

                if (heightMode == MeasureMode.AtMost)
                {
                    measuredHeight = Mathf.Min(measuredHeight, height);
                }
            }

            return(new Vector2(measuredWidth, measuredHeight));
        }
Beispiel #3
0
        public float ComputeTextWidth(MeshGenerationContextUtils.TextParams parms, float scaling)
        {
            bool  flag = this.useLegacy;
            float result;

            if (flag)
            {
                result = TextNative.ComputeTextWidth(MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling));
            }
            else
            {
                this.UpdatePreferredValues(parms);
                result = this.m_PreferredSize.x;
            }
            return(result);
        }
 public float ComputeTextWidth(MeshGenerationContextUtils.TextParams parms, float scaling)
 {
     return(TextNative.ComputeTextWidth(
                MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling)));
 }