コード例 #1
0
        /// <summary>Positions the cursor immediately.</summary>
        private void LocateCursorNow()
        {
            LocateCursor = false;
            // Position the cursor - we need to locate the letter's exact position first:
            // ..Which will be in the text element:
            float position = 0f;

            if (Element.childNodes.Count > 1)
            {
                // Note: If it's equal to 1, ele[0] is the cursor.
                TextElement text  = (TextElement)(Element.childNodes[0]);
                int         index = CursorIndex;

                if (text != null)
                {
                    Vector2 fullPosition = text.GetPosition(ref index);
                    position = fullPosition.x;
                }
            }

            // Scroll it if the cursor is beyond the end of the box:
            int boxSize = Element.Style.Computed.InnerWidth;

            if (position > boxSize)
            {
                Element.Style.Computed.ScrollLeft = (int)position - Element.Style.Computed.InnerWidth;
            }
            else
            {
                Element.Style.Computed.ScrollLeft = 0;
            }

            // Set it in:
            Element.Style.Computed.SetSize();

            if (position > boxSize)
            {
                Cursor.Style.Computed.PositionLeft = boxSize - 1;
            }
            else
            {
                Cursor.Style.Computed.PositionLeft = ((int)position);
            }
        }
コード例 #2
0
        /// <summary>Positions the cursor immediately.</summary>
        private void LocateCursorNow()
        {
            LocateCursor = false;
            // Position the cursor - we need to locate the letter's exact position first:
            // ..Which will be in the text element:
            Vector2 position = Vector2.zero;

            int count = Element.childNodes.Count;

            if (count > 1)
            {
                // Note: If it's equal to 1, ele[0] is the cursor.
                int index = CursorIndex;

                for (int i = 0; i < count; i++)
                {
                    if (index >= 0)
                    {
                        TextElement text = Element.childNodes[0] as TextElement;

                        if (text != null)
                        {
                            position = text.GetPosition(ref index);
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }

            // Set it in:
            Cursor.Style.Computed.PositionLeft = ((int)position.x);
            Cursor.Style.Computed.PositionTop  = ((int)position.y) - Element.Style.Computed.ScrollTop;
        }