Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
## [3.2.0-pre.7] - 2023-12-17
### Changes
- Fixed TMP_InputField line limit behavior to mean unlimited when the value is set to zero or negative (UUM-57192)
- Fixed custom validator ignores the returned character from the validate function (UUM-42147)
- Fixed editing a textfield on mobile and then submitting throws an exception (UUM-37282)
- Addressed issue surrounding dropdown not closing correctly in certain situations(UUM-33691)
- Ensure Sprites can be reordered within a SpriteAsset. (UUM-49349)
- Added missing grey and lightblue tags (UUM-54820)
- Fix underline when use at end of text. (UUM-55135)
- Add support for Visions OS keyboard.
  • Loading branch information
Unity Technologies committed Dec 17, 2023
1 parent 83ba776 commit aee719b
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 45 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog
These are the release notes for the TextMesh Pro UPM package which was first introduced with Unity 2018.1. Please see the following link for the Release Notes for prior versions of TextMesh Pro. http://digitalnativestudios.com/forum/index.php?topic=1363.0


## [3.2.0-pre.7] - 2023-12-17
### Changes
- Fixed TMP_InputField line limit behavior to mean unlimited when the value is set to zero or negative (UUM-57192)
- Fixed custom validator ignores the returned character from the validate function (UUM-42147)
- Fixed editing a textfield on mobile and then submitting throws an exception (UUM-37282)
- Addressed issue surrounding dropdown not closing correctly in certain situations(UUM-33691)
- Ensure Sprites can be reordered within a SpriteAsset. (UUM-49349)
- Added missing grey and lightblue tags (UUM-54820)
- Fix underline when use at end of text. (UUM-55135)
- Add support for Visions OS keyboard.

## [3.2.0-pre.6] - 2023-09-25
### Changes
- Fix TextMeshPro component does not perform linear color conversion when the VertexColorAlwaysGammaSpace option is enabled. Case #UUM-36113
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Editor/TMP_BaseEditorPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,13 +1132,13 @@ protected void DrawMargins()
{
// Value range check on margins to make sure they are not excessive.
Vector4 margins = m_MarginProp.vector4Value;
Vector2 textContainerSize = m_RectTransform.sizeDelta;
Rect textContainerSize = m_RectTransform.rect;

margins.x = Mathf.Clamp(margins.x, -textContainerSize.x, textContainerSize.x);
margins.z = Mathf.Clamp(margins.z, -textContainerSize.x, textContainerSize.x);
margins.x = Mathf.Clamp(margins.x, -textContainerSize.width, textContainerSize.width);
margins.z = Mathf.Clamp(margins.z, -textContainerSize.width, textContainerSize.width);

margins.y = Mathf.Clamp(margins.y, -textContainerSize.y, textContainerSize.y);
margins.w = Mathf.Clamp(margins.w, -textContainerSize.y, textContainerSize.y);
margins.y = Mathf.Clamp(margins.y, -textContainerSize.height, textContainerSize.height);
margins.w = Mathf.Clamp(margins.w, -textContainerSize.height, textContainerSize.height);

m_MarginProp.vector4Value = margins;

Expand Down
9 changes: 3 additions & 6 deletions Scripts/Editor/TMP_EditorResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,13 @@ void OnPreRenderCanvases()
}

#if UNITY_2023_3_OR_NEWER
void OnEndOfFrame(ScriptableRenderContext renderContext, List<Camera> cameras)
{
DoPostRenderUpdates();
}
void OnEndOfFrame(ScriptableRenderContext renderContext, List<Camera> cameras)
#else
void OnEndOfFrame(ScriptableRenderContext renderContext, Camera[] cameras)
void OnEndOfFrame(ScriptableRenderContext renderContext, Camera[] cameras)
#endif
{
DoPostRenderUpdates();
}
#endif

/// <summary>
/// Register resource for re-import.
Expand Down
11 changes: 5 additions & 6 deletions Scripts/Editor/TMP_FontAssetEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,11 @@ public void OnEnable()
// Create serialized object to allow us to use a serialized property of an empty kerning pair.
m_SerializedPropertyHolder = CreateInstance<TMP_SerializedPropertyHolder>();
m_SerializedPropertyHolder.fontAsset = m_fontAsset;
using (SerializedObject internalSerializedObject = new SerializedObject(m_SerializedPropertyHolder))
{
m_FirstCharacterUnicode_prop = internalSerializedObject.FindProperty("firstCharacter");
m_SecondCharacterUnicode_prop = internalSerializedObject.FindProperty("secondCharacter");
m_EmptyGlyphPairAdjustmentRecord_prop = internalSerializedObject.FindProperty("glyphPairAdjustmentRecord");
}
SerializedObject internalSerializedObject = new SerializedObject(m_SerializedPropertyHolder);
m_FirstCharacterUnicode_prop = internalSerializedObject.FindProperty("firstCharacter");
m_SecondCharacterUnicode_prop = internalSerializedObject.FindProperty("secondCharacter");
m_EmptyGlyphPairAdjustmentRecord_prop = internalSerializedObject.FindProperty("glyphPairAdjustmentRecord");

m_materialPresets = TMP_EditorUtility.FindMaterialReferences(m_fontAsset);

m_GlyphSearchList = new List<int>();
Expand Down
8 changes: 4 additions & 4 deletions Scripts/Editor/TMP_FontAsset_CreationMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace TMPro
{
static class TMP_FontAsset_CreationMenu
{
[MenuItem("Assets/Create/TextMeshPro/FontAsset/Font Asset Variant", false, 200)]
[MenuItem("Assets/Create/TextMeshPro/Font Asset/Font Asset Variant", false, 200)]
static void CreateFontAssetVariant()
{
Object target = Selection.activeObject;
Expand Down Expand Up @@ -56,21 +56,21 @@ static void CreateFontAssetVariant()
AssetDatabase.SaveAssets();
}

[MenuItem("Assets/Create/TextMeshPro/FontAsset/SDF #%F12", false, 100)]
[MenuItem("Assets/Create/TextMeshPro/Font Asset/SDF #%F12", false, 100)]
//[MenuItem("Assets/Create/TextMeshPro/Font Asset", false, 100)]
static void CreateFontAssetSDF()
{
CreateFontAsset(GlyphRenderMode.SDFAA);
}

[MenuItem("Assets/Create/TextMeshPro/FontAsset/Bitmap", false, 105)]
[MenuItem("Assets/Create/TextMeshPro/Font Asset/Bitmap", false, 105)]
static void CreateFontAssetBitmap()
{
CreateFontAsset(GlyphRenderMode.SMOOTH);
}

#if TEXTCORE_FONT_ENGINE_1_5_OR_NEWER
[MenuItem("Assets/Create/TextMeshPro/FontAsset/Color", false, 110)]
[MenuItem("Assets/Create/TextMeshPro/Font Asset/Color", false, 110)]
static void CreateFontAssetColor()
{
CreateFontAsset(GlyphRenderMode.COLOR);
Expand Down
9 changes: 7 additions & 2 deletions Scripts/Editor/TMP_PackageUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEditor;
using System;
Expand All @@ -10,6 +10,11 @@
using System.Threading;
using TMPro.EditorUtilities;

#if UNITY_2023_3_OR_NEWER
using PhysicsMaterialAsset = UnityEngine.PhysicsMaterial;
#else
using PhysicsMaterialAsset = UnityEngine.PhysicMaterial;
#endif

namespace TMPro
{
Expand Down Expand Up @@ -618,7 +623,7 @@ static void ShowConverterWindow()
typeof(LightingDataAsset),
typeof(Mesh),
typeof(MonoScript),
typeof(PhysicMaterial),
typeof(PhysicsMaterialAsset),
typeof(PhysicsMaterial2D),
typeof(RenderTexture),
typeof(Shader),
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Runtime/TMP_FontAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ void SetupNewAtlasTexture()
#if UNITY_EDITOR
// Add new texture as sub asset to font asset
Texture2D tex = m_AtlasTextures[m_AtlasTextureIndex];
tex.name = m_AtlasTextures[0].name + " " + m_AtlasTextureIndex;
tex.name = atlasTexture.name + " " + m_AtlasTextureIndex;

OnFontAssetTextureChanged?.Invoke(tex, this);
#endif
Expand Down
21 changes: 18 additions & 3 deletions Scripts/Runtime/TMP_InputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,9 @@ public bool shouldHideSoftKeyboard
case RuntimePlatform.Android:
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.tvOS:
#if UNITY_2022_3_OR_NEWER
case RuntimePlatform.VisionOS:
#endif
case RuntimePlatform.WSAPlayerX86:
case RuntimePlatform.WSAPlayerX64:
case RuntimePlatform.WSAPlayerARM:
Expand Down Expand Up @@ -482,6 +485,9 @@ public bool shouldHideSoftKeyboard
case RuntimePlatform.Android:
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.tvOS:
#if UNITY_2022_3_OR_NEWER
case RuntimePlatform.VisionOS:
#endif
case RuntimePlatform.WSAPlayerX86:
case RuntimePlatform.WSAPlayerX64:
case RuntimePlatform.WSAPlayerARM:
Expand Down Expand Up @@ -522,6 +528,9 @@ private bool isKeyboardUsingEvents()
return InPlaceEditing() && m_HideSoftKeyboard;
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.tvOS:
#if UNITY_2022_3_OR_NEWER
case RuntimePlatform.VisionOS:
#endif
return m_HideSoftKeyboard;
#if UNITY_2020_2_OR_NEWER
case RuntimePlatform.PS4:
Expand Down Expand Up @@ -1768,14 +1777,19 @@ protected virtual void LateUpdate()
for (int i = 0; i < val.Length; ++i)
{
char c = val[i];
bool hasValidateUpdatedText = false;

if (c == '\r' || c == 3)
c = '\n';

if (onValidateInput != null)
c = onValidateInput(m_Text, m_Text.Length, c);
else if (characterValidation != CharacterValidation.None)
{
string textBeforeValidate = m_Text;
c = Validate(m_Text, m_Text.Length, c);
hasValidateUpdatedText = textBeforeValidate != m_Text;
}

if (lineType == LineType.MultiLineSubmit && c == '\n')
{
Expand All @@ -1787,7 +1801,8 @@ protected virtual void LateUpdate()
}

// In the case of a Custom Validator, the user is expected to modify the m_Text where as such we do not append c.
if (c != 0 && characterValidation != CharacterValidation.CustomValidator)
// However we will append c if the user did not modify the m_Text (UUM-42147)
if (c != 0 && (characterValidation != CharacterValidation.CustomValidator || !hasValidateUpdatedText))
m_Text += c;
}

Expand Down Expand Up @@ -2236,7 +2251,7 @@ protected EditState KeyPressed(Event evt)
{
TMP_TextInfo textInfo = m_TextComponent.textInfo;

if (textInfo != null && textInfo.lineCount >= m_LineLimit)
if (m_LineLimit > 0 && textInfo != null && textInfo.lineCount >= m_LineLimit)
{
m_ReleaseSelection = true;
return EditState.Finish;
Expand Down Expand Up @@ -4445,7 +4460,7 @@ public virtual void OnSubmit(BaseEventData eventData)

SendOnSubmit();
DeactivateInputField();
eventData.Use();
eventData?.Use();
}

public virtual void OnCancel(BaseEventData eventData)
Expand Down
2 changes: 2 additions & 0 deletions Scripts/Runtime/TMP_RichTextTagsCommon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ internal enum MarkupTag
BLACK = 81074727,
WHITE = 105680263,
PURPLE = -1250222130,
GREY = 2638345,
LIGHTBLUE= 341063360,

// Unicode Characters
BR = 2256, // <br> Line Feed (LF) \u000A
Expand Down
10 changes: 5 additions & 5 deletions Scripts/Runtime/TMP_Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4077,10 +4077,10 @@ protected virtual Vector2 CalculatePreferredValues(ref float fontSize, Vector2 m
if (m_textElementType == TMP_TextElementType.Sprite)
{
// If a sprite is used as a fallback then get a reference to it and set the color to white.
m_currentSpriteAsset = m_textInfo.characterInfo[m_characterCount].textElement.textAsset as TMP_SpriteAsset;
m_spriteIndex = (int)m_textInfo.characterInfo[m_characterCount].textElement.glyphIndex;
TMP_SpriteCharacter sprite = (TMP_SpriteCharacter)m_textInfo.characterInfo[m_characterCount].textElement;
m_currentSpriteAsset = sprite.textAsset as TMP_SpriteAsset;
m_spriteIndex = (int)sprite.glyphIndex;

TMP_SpriteCharacter sprite = m_currentSpriteAsset.spriteCharacterTable[m_spriteIndex];
if (sprite == null) continue;

// Sprites are assigned in the E000 Private Area + sprite Index
Expand Down Expand Up @@ -7669,15 +7669,15 @@ internal bool ValidateHtmlTag(TextProcessingElement[] chars, int startIndex, out
m_htmlColor = Color.red;
m_colorStack.Add(m_htmlColor);
return true;
case -992792864: // <color=lightblue>
case (int)MarkupTag.LIGHTBLUE: // <color=lightblue>
m_htmlColor = new Color32(173, 216, 230, 255);
m_colorStack.Add(m_htmlColor);
return true;
case (int)MarkupTag.BLUE: // <color=blue>
m_htmlColor = Color.blue;
m_colorStack.Add(m_htmlColor);
return true;
case 3680713: // <color=grey>
case (int)MarkupTag.GREY: // <color=grey>
m_htmlColor = new Color32(128, 128, 128, 255);
m_colorStack.Add(m_htmlColor);
return true;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Runtime/TextMeshPro.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4905,7 +4905,7 @@ protected virtual void GenerateTextMesh()
#endregion

// Set vertex count for Underline geometry
//m_textInfo.meshInfo[m_Underline.materialIndex].vertexCount = last_vert_index;
m_textInfo.meshInfo[m_Underline.materialIndex].vertexCount = last_vert_index;

// METRICS ABOUT THE TEXT OBJECT
m_textInfo.characterCount = m_characterCount;
Expand Down
2 changes: 1 addition & 1 deletion Scripts/Runtime/TextMeshProUGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5271,7 +5271,7 @@ protected virtual void GenerateTextMesh()
#endregion

// Set vertex count for Underline geometry
//m_textInfo.meshInfo[m_Underline.materialIndex].vertexCount = last_vert_index;
m_textInfo.meshInfo[m_Underline.materialIndex].vertexCount = last_vert_index;

// METRICS ABOUT THE TEXT OBJECT
m_textInfo.characterCount = m_characterCount;
Expand Down
21 changes: 21 additions & 0 deletions Tests/Editor/TMP_EditorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,27 @@ public void MarkupTag_Indent(string sourceText, float origin1, float advance1, f
Assert.AreEqual(advance3, m_TextComponent.textInfo.characterInfo[2].xAdvance);
}

#if TMP_TEST_RESOURCES
const string k_SpriteAssetPath = "Assets/TextMesh Pro/Resources/Sprite Assets/MixedIndexTest.asset";
[Test]
public void SpriteAssetIndexAreValidAfterReordering()
{
var spriteAsset = AssetDatabase.LoadAssetAtPath<TMP_SpriteAsset>(k_SpriteAssetPath);
if (spriteAsset == null)
{
Debug.LogError("Failed to load Sprite Asset at path: " + k_SpriteAssetPath);
return;
}

string text = $"<sprite name=\"cta_obsidianjade\">";
m_TextComponent.spriteAsset = spriteAsset;
m_TextComponent.text = text;
m_TextComponent.ForceMeshUpdate();

Assert.AreEqual(203, m_TextComponent.textInfo.characterInfo[0].textElement.glyphIndex, $"Mismatch between sprite index. Expected 203 but was {m_TextComponent.textInfo.characterInfo[0].textElement.glyphIndex}");
}
#endif


// Add tests that check position of individual characters in a complex block of text.
// These test also use the data contained inside the TMP_TextInfo class.
Expand Down
35 changes: 28 additions & 7 deletions Tests/Runtime/TMP_RuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,16 @@ public static IEnumerable<object[]> TestCases_MultiLineNewline_OnLastLine_WhenPr
yield return new object[] { 6, 6 };
}

[Test, TestCaseSource("TestCases_MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine")]
public void MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine(int lineLimit, int expectedLineCount)
[Test, TestCaseSource(nameof(TestCases_MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine))]
public void MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_NextLine(int lineLimit,
int expectedLineCount)
{
MultiLineNewline_LineLimit_ExpectedLineCount_Logic(lineLimit, lineLimit, 3);
Assert.AreEqual(m_TextComponent.textInfo.lineCount, expectedLineCount);
}

private void MultiLineNewline_LineLimit_ExpectedLineCount_Logic(int lineLimitValue, int lineLimitApplied,
int extraKeyDownEventCount)
{
GameObject cameraObject = new GameObject("Camera Object", typeof(Camera));
GameObject canvasObject = new GameObject("Canvas Object", typeof(Canvas), typeof(GraphicRaycaster));
Expand All @@ -207,20 +215,20 @@ public void MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_Nex
m_InputField.targetGraphic = inputObject.GetComponent<Image>();
m_InputField.textComponent = m_TextComponent;
m_InputField.lineType = TMP_InputField.LineType.MultiLineNewline;
m_InputField.lineLimit = lineLimit;
m_InputField.lineLimit = lineLimitValue;

GameObject eventGameObject = new GameObject("Event Object", typeof(EventSystem), typeof(StandaloneInputModule));
Event enterKeyDownEvent = new Event { type = EventType.KeyDown, keyCode = KeyCode.KeypadEnter, modifiers = EventModifiers.None, character = '\n' };

m_InputField.text = "POTUS";
EventSystem.current.SetSelectedGameObject(inputObject);
m_InputField.ActivateInputField();
int count = 0;
while (count < lineLimit + 3)
int count = lineLimitApplied + extraKeyDownEventCount;
while (count > 0)
{
m_InputField.ProcessEvent(enterKeyDownEvent);
m_InputField.ForceLabelUpdate();
count++;
count--;
}

m_InputField.textComponent.ForceMeshUpdate();
Expand All @@ -231,8 +239,21 @@ public void MultiLineNewline_OnLastLine_WhenPressedEnter_Caret_ShouldNotGoto_Nex
GameObject.Destroy(inputObject);
GameObject.Destroy(canvasObject);
GameObject.Destroy(cameraObject);
}

Assert.AreEqual(m_TextComponent.textInfo.lineCount, expectedLineCount);
public static IEnumerable<object[]> TestCases_MultiLineNewLine_NegativeOrZeroLineLimit_AddsNewLine()
{
yield return new object[] { 0, 0, 1 };
yield return new object[] { 0, 0, 4 };
yield return new object[] { -1, 0, 2 };
}

[Test, TestCaseSource(nameof(TestCases_MultiLineNewLine_NegativeOrZeroLineLimit_AddsNewLine))]
public void MultiLineNewLine_NegativeOrZeroLineLimit_AddsNewLine(int lineLimitValue, int lineLimitApplied,
int extraKeyDownEventCount)
{
MultiLineNewline_LineLimit_ExpectedLineCount_Logic(lineLimitValue, lineLimitApplied, extraKeyDownEventCount);
Assert.AreEqual(m_TextComponent.textInfo.lineCount, extraKeyDownEventCount + 1);
}

//[OneTimeTearDown]
Expand Down
Loading

0 comments on commit aee719b

Please sign in to comment.