protected internal override Vector2 DoMeasure(float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; Font font = base.style.font; Vector2 result; if (this.text == null || font == null) { result = new Vector2(num, num2); } else { IStylePainter stylePainter = base.elementPanel.stylePainter; if (widthMode == VisualElement.MeasureMode.Exactly) { num = width; } else { TextStylePainterParameters defaultTextParameters = stylePainter.GetDefaultTextParameters(this); defaultTextParameters.text = this.text; defaultTextParameters.font = font; defaultTextParameters.wordWrapWidth = 0f; defaultTextParameters.wordWrap = false; defaultTextParameters.richText = true; num = stylePainter.ComputeTextWidth(defaultTextParameters); if (widthMode == VisualElement.MeasureMode.AtMost) { num = Mathf.Min(num, width); } } if (heightMode == VisualElement.MeasureMode.Exactly) { num2 = height; } else { TextStylePainterParameters defaultTextParameters2 = stylePainter.GetDefaultTextParameters(this); defaultTextParameters2.text = this.text; defaultTextParameters2.font = font; defaultTextParameters2.wordWrapWidth = num; defaultTextParameters2.richText = true; num2 = stylePainter.ComputeTextHeight(defaultTextParameters2); if (heightMode == VisualElement.MeasureMode.AtMost) { num2 = Mathf.Min(num2, height); } } result = new Vector2(num, num2); } return(result); }
protected internal override Vector2 DoMeasure(float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; bool flag = widthMode != VisualElement.MeasureMode.Exactly || heightMode != VisualElement.MeasureMode.Exactly; if (flag) { Event evt = new Event { type = EventType.Layout }; Rect layout = base.layout; if (widthMode == VisualElement.MeasureMode.Exactly) { layout.width = desiredWidth; } if (heightMode == VisualElement.MeasureMode.Exactly) { layout.height = desiredHeight; } this.DoOnGUI(evt, this.m_CachedTransform, this.m_CachedClippingRect, true, layout, this.onGUIHandler, true); num = this.layoutMeasuredWidth; num2 = this.layoutMeasuredHeight; } if (widthMode != VisualElement.MeasureMode.Exactly) { if (widthMode == VisualElement.MeasureMode.AtMost) { num = Mathf.Min(num, desiredWidth); } } else { num = desiredWidth; } if (heightMode != VisualElement.MeasureMode.Exactly) { if (heightMode == VisualElement.MeasureMode.AtMost) { num2 = Mathf.Min(num2, desiredHeight); } } else { num2 = desiredHeight; } return(new Vector2(num, num2)); }
protected internal override Vector2 DoMeasure(float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; bool flag = this.image == null && this.vectorImage == null; Vector2 result; if (flag) { result = new Vector2(num, num2); } else { Vector2 vector = Vector2.zero; bool flag2 = this.image != null; if (flag2) { vector = this.GetTextureDisplaySize(this.image); } else { vector = this.vectorImage.size; } Rect sourceRect = this.sourceRect; bool flag3 = sourceRect != Rect.zero; num = (flag3 ? sourceRect.width : vector.x); num2 = (flag3 ? sourceRect.height : vector.y); bool flag4 = widthMode == VisualElement.MeasureMode.AtMost; if (flag4) { num = Mathf.Min(num, desiredWidth); } bool flag5 = heightMode == VisualElement.MeasureMode.AtMost; if (flag5) { num2 = Mathf.Min(num2, desiredHeight); } result = new Vector2(num, num2); } return(result); }
protected internal virtual Vector2 DoMeasure(float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; Vector2 result; if (string.IsNullOrEmpty(this.text) || this.font == null) { result = new Vector2(num, num2); } else { if (widthMode == VisualElement.MeasureMode.Exactly) { num = width; } else { num = this.elementPanel.stylePainter.ComputeTextWidth(this.text, this.font, this.fontSize, this.fontStyle, this.textAlignment, true); if (widthMode == VisualElement.MeasureMode.AtMost) { num = Mathf.Min(num, width); } } if (heightMode == VisualElement.MeasureMode.Exactly) { num2 = height; } else { num2 = this.elementPanel.stylePainter.ComputeTextHeight(this.text, num, this.wordWrap, this.font, this.fontSize, this.fontStyle, this.textAlignment, true); if (heightMode == VisualElement.MeasureMode.AtMost) { num2 = Mathf.Min(num2, height); } } result = new Vector2(num, num2); } return(result); }
protected internal override Vector2 DoMeasure(float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; if (widthMode != VisualElement.MeasureMode.Exactly || heightMode != VisualElement.MeasureMode.Exactly) { this.DoOnGUI(new Event { type = EventType.Layout }); num = this.m_Cache.topLevel.minWidth; num2 = this.m_Cache.topLevel.minHeight; } if (widthMode != VisualElement.MeasureMode.Exactly) { if (widthMode == VisualElement.MeasureMode.AtMost) { num = Mathf.Min(num, desiredWidth); } } else { num = desiredWidth; } if (heightMode != VisualElement.MeasureMode.Exactly) { if (heightMode == VisualElement.MeasureMode.AtMost) { num2 = Mathf.Min(num2, desiredHeight); } } else { num2 = desiredHeight; } return(new Vector2(num, num2)); }
protected internal override Vector2 DoMeasure(float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { return(this.MeasureTextSize(this.text, desiredWidth, widthMode, desiredHeight, heightMode)); }
internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode, TextHandle textHandle) { float num = float.NaN; float num2 = float.NaN; Font value = ve.computedStyle.unityFont.value; bool flag = textToMeasure == null || value == null; Vector2 result; if (flag) { result = new Vector2(num, num2); } else { Vector3 vector = ve.ComputeGlobalScale(); bool flag2 = vector.x + vector.y <= 0f || ve.scaledPixelsPerPoint <= 0f; if (flag2) { result = Vector2.zero; } else { float scaledPixelsPerPoint = ve.scaledPixelsPerPoint; float num3 = 0.02f; float num4 = num3 / scaledPixelsPerPoint; bool flag3 = widthMode == VisualElement.MeasureMode.Exactly; if (flag3) { num = width; } else { MeshGenerationContextUtils.TextParams textSettings = TextElement.GetTextSettings(ve, textToMeasure); textSettings.wordWrap = false; textSettings.richText = false; num = textHandle.ComputeTextWidth(textSettings, scaledPixelsPerPoint); num = ((num < num4) ? 0f : AlignmentUtils.CeilToPixelGrid(num, scaledPixelsPerPoint, num3)); bool flag4 = widthMode == VisualElement.MeasureMode.AtMost; if (flag4) { num = Mathf.Min(num, width); } } bool flag5 = heightMode == VisualElement.MeasureMode.Exactly; if (flag5) { num2 = height; } else { MeshGenerationContextUtils.TextParams textSettings2 = TextElement.GetTextSettings(ve, textToMeasure); textSettings2.wordWrapWidth = num; textSettings2.richText = false; num2 = textHandle.ComputeTextHeight(textSettings2, scaledPixelsPerPoint); num2 = ((num2 < num4) ? 0f : AlignmentUtils.CeilToPixelGrid(num2, scaledPixelsPerPoint, num3)); bool flag6 = heightMode == VisualElement.MeasureMode.AtMost; if (flag6) { num2 = Mathf.Min(num2, height); } } result = new Vector2(num, num2); } } return(result); }
public Vector2 MeasureTextSize(string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode) { return(TextElement.MeasureVisualElementTextSize(this, textToMeasure, width, widthMode, height, heightMode, this.m_TextHandle)); }
protected internal override Vector2 DoMeasure(float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; Vector2 result; if (this.image == null) { result = new Vector2(num, num2); } else { num = (float)this.image.width; num2 = (float)this.image.height; if (widthMode == VisualElement.MeasureMode.AtMost) { num = Mathf.Min(num, width); } if (heightMode == VisualElement.MeasureMode.AtMost) { num2 = Mathf.Min(num2, height); } result = new Vector2(num, num2); } return(result); }
protected internal override Vector2 DoMeasure(float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { string text = this.text; bool flag = string.IsNullOrEmpty(text); if (flag) { text = Button.NonEmptyString; } return(base.MeasureTextSize(text, desiredWidth, widthMode, desiredHeight, heightMode)); }
internal static Vector2 MeasureVisualElementTextSize(TextElement te, string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode) { float measuredWidth = float.NaN; float measuredHeight = float.NaN; if (textToMeasure == null || !IsFontAssigned(te)) { return(new Vector2(measuredWidth, measuredHeight)); } var elementScaling = te.ComputeGlobalScale(); if (elementScaling.x + elementScaling.y <= 0 || te.scaledPixelsPerPoint <= 0) { return(Vector2.zero); } float pixelsPerPoint = te.scaledPixelsPerPoint; if (widthMode == VisualElement.MeasureMode.Exactly) { measuredWidth = width; } else { measuredWidth = te.uitkTextHandle.ComputeTextWidth(textToMeasure, false, width, height); if (widthMode == VisualElement.MeasureMode.AtMost) { measuredWidth = Mathf.Min(measuredWidth, width); } } if (heightMode == VisualElement.MeasureMode.Exactly) { measuredHeight = height; } else { measuredHeight = te.uitkTextHandle.ComputeTextHeight(textToMeasure, width, height); if (heightMode == VisualElement.MeasureMode.AtMost) { measuredHeight = Mathf.Min(measuredHeight, height); } } // Case 1215962: round up as yoga could decide to round down and text would start wrapping float roundedWidth = AlignmentUtils.CeilToPixelGrid(measuredWidth, pixelsPerPoint); float roundedHeight = AlignmentUtils.CeilToPixelGrid(measuredHeight, pixelsPerPoint); var roundedValues = new Vector2(roundedWidth, roundedHeight); te.uitkTextHandle.MeasuredSizes = new Vector2(measuredWidth, measuredHeight); te.uitkTextHandle.RoundedSizes = roundedValues; return(roundedValues); }
public static Vector2 DoMeasure(this VisualElement ve, float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { return(ve.DoMeasure(desiredWidth, widthMode, desiredHeight, heightMode)); }
internal static Vector2 MeasureVisualElementTextSize(VisualElement ve, string textToMeasure, float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode, ITextHandle textHandle) { float measuredWidth = float.NaN; float measuredHeight = float.NaN; if (textToMeasure == null || (ve.computedStyle.unityFont == null && ve.computedStyle.unityFontDefinition.IsEmpty())) { return(new Vector2(measuredWidth, measuredHeight)); } var elementScaling = ve.ComputeGlobalScale(); if (elementScaling.x + elementScaling.y <= 0 || ve.scaledPixelsPerPoint <= 0) { return(Vector2.zero); } float pixelsPerPoint = ve.scaledPixelsPerPoint; float pixelOffset = 0.02f; float pointOffset = pixelOffset / pixelsPerPoint; if (widthMode == VisualElement.MeasureMode.Exactly) { measuredWidth = width; } else { var textParams = MeshGenerationContextUtils.TextParams.MakeStyleBased(ve, textToMeasure); textParams.wordWrap = false; // Case 1215962: round up as yoga could decide to round down and text would start wrapping measuredWidth = textHandle.ComputeTextWidth(textParams, pixelsPerPoint); measuredWidth = measuredWidth < pointOffset ? 0 : AlignmentUtils.CeilToPixelGrid(measuredWidth, pixelsPerPoint, pixelOffset); if (widthMode == VisualElement.MeasureMode.AtMost) { measuredWidth = Mathf.Min(measuredWidth, width); } } if (heightMode == VisualElement.MeasureMode.Exactly) { measuredHeight = height; } else { var textParams = MeshGenerationContextUtils.TextParams.MakeStyleBased(ve, textToMeasure); textParams.wordWrapWidth = measuredWidth; measuredHeight = textHandle.ComputeTextHeight(textParams, pixelsPerPoint); measuredHeight = measuredHeight < pointOffset ? 0 : AlignmentUtils.CeilToPixelGrid(measuredHeight, pixelsPerPoint, pixelOffset); if (heightMode == VisualElement.MeasureMode.AtMost) { measuredHeight = Mathf.Min(measuredHeight, height); } } return(new Vector2(measuredWidth, measuredHeight)); }
protected internal override Vector2 DoMeasure(float desiredWidth, VisualElement.MeasureMode widthMode, float desiredHeight, VisualElement.MeasureMode heightMode) { string text = this.m_Text; bool flag = string.IsNullOrEmpty(text); if (flag) { text = " "; } return(TextElement.MeasureVisualElementTextSize(this, text, desiredWidth, widthMode, desiredHeight, heightMode, this.m_TextHandle)); }
protected internal override Vector2 DoMeasure(float width, VisualElement.MeasureMode widthMode, float height, VisualElement.MeasureMode heightMode) { float num = float.NaN; float num2 = float.NaN; Texture specifiedValueOrDefault = this.image.GetSpecifiedValueOrDefault(null); Vector2 result; if (specifiedValueOrDefault == null) { result = new Vector2(num, num2); } else { Rect sourceRect = this.sourceRect; bool flag = sourceRect != Rect.zero; num = ((!flag) ? ((float)specifiedValueOrDefault.width) : sourceRect.width); num2 = ((!flag) ? ((float)specifiedValueOrDefault.height) : sourceRect.height); if (widthMode == VisualElement.MeasureMode.AtMost) { num = Mathf.Min(num, width); } if (heightMode == VisualElement.MeasureMode.AtMost) { num2 = Mathf.Min(num2, height); } result = new Vector2(num, num2); } return(result); }