Exemplo n.º 1
0
        /// <summary>
        /// 插入字符
        /// </summary>
        /// <param name="index">字符索引</param>
        /// <param name="emoji">字符数量</param>
        public void Insert(int index, EmojiString emoji)
        {
            if (index > m_str.Length)
            {
                index = m_str.Length;
            }
            var list = emoji.emojis;

            for (int i = 0; i < list.Count; i++)
            {
                list[i].pos += index;
            }
            string str = emoji.FilterString;

            builder.Insert(index, str);
            int l = str.Length;

            for (int i = 0; i < emojis.Count; i++)//将后面的表情符位置往后移
            {
                if (emojis[i].pos >= index)
                {
                    emojis[i].pos += l;
                }
            }
            emojis.AddRange(list);
            emojis.Sort((a, b) => { return(a.pos > b.pos ? 1 : -1); });
            m_str = builder.ToString();
            f_str = EmojiMap.EmojiToFullString(m_str, emojis);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 插入字符串
        /// </summary>
        /// <param name="con">表情符字符串</param>
        public static void InsertContent(EmojiString con)
        {
            Content.Insert(StartPress.Index, con);
            int index = StartPress.Index + con.Length;

            ChangeText(Target, Content);
            bool b = false;

            SetPressIndex(index, ref b);
        }
Exemplo n.º 3
0
        public static void ChangeText(HText text, EmojiString str)
        {
            verts.Clear();
            lines.Clear();
            chars.Clear();
            Target  = text;
            Content = str;
            text.GetGenerationSettings(ref text.m_sizeDelta, ref HText.settings);
            HText.settings.richText = false;
            var    g  = HText.Generator;
            string fs = Content.FilterString;

            if (contentType == ContentType.Password)
            {
                ContentHeight = g.GetPreferredHeight(new string('●', fs.Length), HText.settings);
            }
            else
            {
                ContentHeight = g.GetPreferredHeight(fs, HText.settings);
            }
            VisibleCount = g.characterCountVisible;
            if (g.lines.Count > 0)
            {
                float per = ContentHeight / g.lines.Count;
                ShowRow = (int)(text.m_sizeDelta.y / per);
            }
            else
            {
                ShowRow = (int)text.m_sizeDelta.y / text.FontSize;
            }
            StartY = ContentHeight * 0.5f - text.m_sizeDelta.y * 0.5f;
            verts.AddRange(g.verts);
            chars.AddRange(g.characters);
            LineInfo line = new LineInfo();

            if (g.lines.Count > 0)
            {
                var l = g.lines[0];
                for (int i = 1; i < g.lines.Count; i++)
                {
                    var n = g.lines[i];
                    line.startCharIdx = l.startCharIdx;
                    line.endIdx       = n.startCharIdx - 1;
                    line.topY         = l.topY;
                    line.endY         = n.topY;
                    l = n;
                    lines.Add(line);
                }
                l = g.lines[g.lines.Count - 1];
                line.startCharIdx = l.startCharIdx;
                line.endIdx       = chars.Count - 1;
                line.topY         = l.topY;
                line.endY         = g.lines[0].topY - ContentHeight - g.lines[g.lines.Count - 1].leading;
                lines.Add(line);
            }
            if (StartPress.Index > fs.Length)
            {
                SetPressIndex(fs.Length, ref StartPress);
                EndPress = StartPress;
            }
            SetShowStart(ShowStart);
        }