Exemple #1
0
        public void TestHighlight(
            string searchIn
            )
        {
            Assume.That(searchIn, Has.Length.GreaterThan(1));

            var textMesh  = InstantiateTextMeshPro(searchIn);
            var highlight = InstantiateHighlight();

            var word = new TMP_Word(textMesh, textMesh.textInfo.characterInfo.Take(searchIn.Length / 2).ToList());

            Assert.That(
                word.ToString(),
                Is.EqualTo(searchIn.Substring(0, searchIn.Length / 2))
                );

            word.HighlightWord(highlight);

            foreach (var e in (RectTransform.Edge[])Enum.GetValues(typeof(RectTransform.Edge)))
            {
                float actual = word.GetEdgePosition_AsFloat(e);
                float expect = highlight.GetEdgePosition_AsFloat(e);
                Assert.That(
                    actual,
                    new ApproximationConstraint(expect, TestUtils.ApproximationThreshold)
                    );
            }
        }
Exemple #2
0
    private TMP_Word RandomWord()
    {
        var ln    = Random.Range(1, TextMesh.text.Length);
        var start = Random.Range(0, TextMesh.text.Length - ln);

        LogUtils.Log(
            new Dictionary <object, object>()
        {
            { nameof(TextMesh.text), TextMesh.text },
            { nameof(TextMesh.text.Length), TextMesh.text.Length },
            { nameof(ln), ln },
            { nameof(start), start }
        }
            );
        // new TMP_Word(TextMesh, TextMesh.textInfo.characterInfo.Take(TextMesh.text.Length / 2));
        var chars = TextMesh.textInfo.characterInfo.ToList().GetRange(start, ln);
        var word  = new TMP_Word(TextMesh, chars);

        LogUtils.Log(Color.green, word);
        return(word);
    }