private static Vector2 DoGetCursorPosition(TextNativeSettings settings, Rect rect, int cursorPosition) { Vector2 result; TextNative.DoGetCursorPosition_Injected(ref settings, ref rect, cursorPosition, out result); return(result); }
private static Vector2 DoGetOffset(TextNativeSettings settings, Rect rect) { Vector2 result; TextNative.DoGetOffset_Injected(ref settings, ref rect, out result); return(result); }
public Vector2 GetCursorPosition(CursorPositionStylePainterParameters parms, float scaling) { if (useLegacy) { return(TextNative.GetCursorPosition(parms.GetTextNativeSettings(scaling), parms.rect, parms.cursorIndex)); } return(TextCore.TextGenerator.GetCursorPosition(m_TextInfo, parms.rect, parms.cursorIndex)); }
public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling) { if (useLegacy) { return(TextNative.ComputeTextHeight( MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling))); } UpdatePreferredValues(parms); return(m_PreferredSize.y); }
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)); }
public NativeArray <TextVertex> GetVertices(MeshGenerationContextUtils.TextParams parms, float scaling) { int paramsHash = parms.GetHashCode(); if (m_PreviousTextParamsHash == paramsHash) { return(textVertices); } m_PreviousTextParamsHash = paramsHash; TextNativeSettings textSettings = MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling); textVertices = TextNative.GetVertices(textSettings); return(textVertices); }
public static NativeArray <TextVertex> GetVertices(TextNativeSettings settings) { int num = 0; TextNative.GetVertices(settings, IntPtr.Zero, UnsafeUtility.SizeOf <TextVertex>(), ref num); NativeArray <TextVertex> nativeArray = new NativeArray <TextVertex>(num, Allocator.Temp, NativeArrayOptions.UninitializedMemory); bool flag = num > 0; if (flag) { TextNative.GetVertices(settings, (IntPtr)nativeArray.GetUnsafePtr <TextVertex>(), UnsafeUtility.SizeOf <TextVertex>(), ref num); Debug.Assert(num == nativeArray.Length); } return(nativeArray); }
public Vector2 GetCursorPosition(CursorPositionStylePainterParameters parms, float scaling) { bool flag = this.useLegacy; Vector2 cursorPosition; if (flag) { cursorPosition = TextNative.GetCursorPosition(parms.GetTextNativeSettings(scaling), parms.rect, parms.cursorIndex); } else { cursorPosition = UnityEngine.TextCore.TextGenerator.GetCursorPosition(this.textInfo, parms.rect, parms.cursorIndex); } return(cursorPosition); }
public static Vector2 GetCursorPosition(TextNativeSettings settings, Rect rect, int cursorIndex) { bool flag = settings.font == null; Vector2 result; if (flag) { Debug.LogError("Cannot process a null font."); result = Vector2.zero; } else { result = TextNative.DoGetCursorPosition(settings, rect, cursorIndex); } return(result); }
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 static Vector2 GetOffset(TextNativeSettings settings, Rect screenRect) { bool flag = settings.font == null; Vector2 result; if (flag) { Debug.LogError("Cannot process a null font."); result = new Vector2(0f, 0f); } else { settings.text = (settings.text ?? ""); result = TextNative.DoGetOffset(settings, screenRect); } return(result); }
public static float ComputeTextHeight(TextNativeSettings settings) { bool flag = settings.font == null; float result; if (flag) { Debug.LogError("Cannot process a null font."); result = 0f; } else { bool flag2 = string.IsNullOrEmpty(settings.text); if (flag2) { result = 0f; } else { result = TextNative.DoComputeTextHeight(settings); } } return(result); }
private static float DoComputeTextHeight(TextNativeSettings settings) { return(TextNative.DoComputeTextHeight_Injected(ref settings)); }
internal void DrawWithTextSelectionAndCursor(MeshGenerationContext mgc, string newText) { var keyboardTextEditor = editorEventHandler as KeyboardTextEditorEventHandler; if (keyboardTextEditor == null) { return; } keyboardTextEditor.PreDrawCursor(newText); int cursorIndex = editorEngine.cursorIndex; int selectIndex = editorEngine.selectIndex; Rect localPosition = editorEngine.localPosition; var scrollOffset = editorEngine.scrollOffset; float textScaling = TextNative.ComputeTextScaling(worldTransform, GUIUtility.pixelsPerPoint); var textParams = MeshGenerationContextUtils.TextParams.MakeStyleBased(this, text); textParams.text = " "; textParams.wordWrapWidth = 0.0f; textParams.wordWrap = false; var textNativeSettings = MeshGenerationContextUtils.TextParams.GetTextNativeSettings(textParams, textScaling); float lineHeight = TextNative.ComputeTextHeight(textNativeSettings); float wordWrapWidth = 0.0f; // Make sure to take into account the word wrap style... if (editorEngine.multiline && (resolvedStyle.whiteSpace == WhiteSpace.Normal)) { wordWrapWidth = contentRect.width; // Since the wrapping is enabled, there is no need to offset the text... It will always fit the space on screen ! scrollOffset = Vector2.zero; } GUIUtility.compositionCursorPos = editorEngine.graphicalCursorPos - scrollOffset + new Vector2(localPosition.x, localPosition.y + lineHeight); Color drawCursorColor = cursorColor; int selectionEndIndex = string.IsNullOrEmpty(GUIUtility.compositionString) ? selectIndex : cursorIndex + GUIUtility.compositionString.Length; CursorPositionStylePainterParameters cursorParams; // Draw highlighted section, if any if ((cursorIndex != selectionEndIndex) && !isDragging) { int min = cursorIndex < selectionEndIndex ? cursorIndex : selectionEndIndex; int max = cursorIndex > selectionEndIndex ? cursorIndex : selectionEndIndex; cursorParams = CursorPositionStylePainterParameters.GetDefault(this, text); cursorParams.text = editorEngine.text; cursorParams.wordWrapWidth = wordWrapWidth; cursorParams.cursorIndex = min; textNativeSettings = cursorParams.GetTextNativeSettings(textScaling); Vector2 minPos = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, min); Vector2 maxPos = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, max); minPos -= scrollOffset; maxPos -= scrollOffset; if (Mathf.Approximately(minPos.y, maxPos.y)) { mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams() { rect = new Rect(minPos.x, minPos.y, maxPos.x - minPos.x, lineHeight), color = selectionColor }); } else { // Draw first line mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams() { rect = new Rect(minPos.x, minPos.y, contentRect.xMax - minPos.x, lineHeight), color = selectionColor }); var inbetweenHeight = (maxPos.y - minPos.y) - lineHeight; if (inbetweenHeight > 0f) { // Draw all lines in-between mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams() { rect = new Rect(contentRect.xMin, minPos.y + lineHeight, contentRect.width, inbetweenHeight), color = selectionColor }); } // Draw last line if not empty if (maxPos.x != contentRect.x) { mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams() { rect = new Rect(contentRect.xMin, maxPos.y, maxPos.x, lineHeight), color = selectionColor }); } } } // Draw the text with the scroll offset if (!string.IsNullOrEmpty(editorEngine.text) && contentRect.width > 0.0f && contentRect.height > 0.0f) { textParams = MeshGenerationContextUtils.TextParams.MakeStyleBased(this, text); textParams.rect = new Rect(contentRect.x - scrollOffset.x, contentRect.y - scrollOffset.y, contentRect.width + scrollOffset.x, contentRect.height + scrollOffset.y); textParams.text = editorEngine.text; mgc.Text(textParams); } // Draw the cursor if (!isReadOnly && !isDragging) { if (cursorIndex == selectionEndIndex && computedStyle.unityFont.value != null) { cursorParams = CursorPositionStylePainterParameters.GetDefault(this, text); cursorParams.text = editorEngine.text; cursorParams.wordWrapWidth = wordWrapWidth; cursorParams.cursorIndex = cursorIndex; textNativeSettings = cursorParams.GetTextNativeSettings(textScaling); Vector2 cursorPosition = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, cursorParams.cursorIndex); cursorPosition -= scrollOffset; mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams { rect = new Rect(cursorPosition.x, cursorPosition.y, 1f, lineHeight), color = drawCursorColor }); } // Draw alternate cursor, if any if (editorEngine.altCursorPosition != -1) { cursorParams = CursorPositionStylePainterParameters.GetDefault(this, text); cursorParams.text = editorEngine.text.Substring(0, editorEngine.altCursorPosition); cursorParams.wordWrapWidth = wordWrapWidth; cursorParams.cursorIndex = editorEngine.altCursorPosition; textNativeSettings = cursorParams.GetTextNativeSettings(textScaling); Vector2 altCursorPosition = TextNative.GetCursorPosition(textNativeSettings, cursorParams.rect, cursorParams.cursorIndex); altCursorPosition -= scrollOffset; mgc.Rectangle(new MeshGenerationContextUtils.RectangleParams { rect = new Rect(altCursorPosition.x, altCursorPosition.y, 1f, lineHeight), color = drawCursorColor }); } } keyboardTextEditor.PostDrawCursor(); }
private static void GetVertices(TextNativeSettings settings, IntPtr buffer, int vertexSize, ref int vertexCount) { TextNative.GetVertices_Injected(ref settings, buffer, vertexSize, ref vertexCount); }
public float ComputeTextHeight(MeshGenerationContextUtils.TextParams parms, float scaling) { return(TextNative.ComputeTextHeight( MeshGenerationContextUtils.TextParams.GetTextNativeSettings(parms, scaling))); }
public Vector2 GetCursorPosition(CursorPositionStylePainterParameters parms, float scaling) { return(TextNative.GetCursorPosition(parms.GetTextNativeSettings(scaling), parms.rect, parms.cursorIndex)); }
private static float DoComputeTextWidth(TextNativeSettings settings) { return(TextNative.DoComputeTextWidth_Injected(ref settings)); }