Exemplo n.º 1
0
        public void Rebuild()
        {
            if (input.textComponent.enabled && checker.NeedRebuild())
            {
                //================================
                // fix bug for tmp
                // TMPの不具合で、正しく座標を設定されてなかったため、試しに対応する
                var rt   = input.textComponent.GetComponent <RectTransform>();
                var size = input.textComponent.GetPreferredValues();
                if (size.x < rt.rect.xMax)
                {
                    // textComponent の座標を更新
                    var pos = rt.anchoredPosition;
                    pos.x = 0;
                    rt.anchoredPosition = pos;

                    // caret の座標更新
                    var caret     = input.GetComponentInChildren <TMP_SelectionCaret>();
                    var caretRect = caret.GetComponent <RectTransform>();
                    caretRect.anchoredPosition = rt.anchoredPosition;
                }
                //==============================

                // HACK : 1フレーム無効にする
                // MEMO : 他にいい方法Rebuildがあれば対応する
                // LayoutRebuilder.ForceRebuildLayoutImmediate(); で試してダメでした
                input.textComponent.enabled = false;
                input.Rebuild(CanvasUpdate.LatePreRender);
                input.textComponent.SetAllDirty();
            }
            else
            {
                input.textComponent.enabled = true;
            }
        }
Exemplo n.º 2
0
 public void Rebuild(CanvasUpdate update)
 {
     input.Rebuild(update);
 }
Exemplo n.º 3
0
        private void AutoIndentCaret(bool isClosingToken = false)
        {
            // Check for new line
            if (Input.GetKeyDown(KeyCode.Return) == true)
            {
                // Update line column and indent positions
                UpdateCurrentLineColumnIndent();

                // Build indent string
                string indent = string.Empty;

                // Make sure we have some text
                if (inputField.caretPosition < inputField.text.Length)
                {
                    // Check for tabs before caret
                    int beforeIndentCount = 0;
                    int caretIndentCount  = 0;
                    for (int i = inputField.caretPosition; i >= 0; i--)
                    {
                        // Check for tab characters
                        if (inputField.text[i] == '\t')
                        {
                            beforeIndentCount++;
                        }

                        // Check for previous line or spaces
                        if (inputField.text[i] == '\n' || (languageTheme.autoIndent.autoIndentMode == AutoIndent.IndentMode.AutoTabContextual && inputField.text[i] != ' '))
                        {
                            if (i != inputField.caretPosition)
                            {
                                break;
                            }
                        }
                    }

                    if (languageTheme.autoIndent.autoIndentMode == AutoIndent.IndentMode.AutoTabContextual)
                    {
                        // Take into account any previous tab characters
                        caretIndentCount = currentIndent - caretIndentCount;
                    }
                    else
                    {
                        caretIndentCount = beforeIndentCount;
                    }

                    indent = GetAutoIndentTab(caretIndentCount);

                    //int length = 0;

                    //for(int i = inputField.caretPosition + 1; i < inputField.text.Length; i++, length++)
                    //{
                    //    if (inputField.text[i] == '\n')
                    //        break;
                    //}

                    //int caret = 0;
                    //string formatted = languageTheme.autoIndent.GetAutoIndentedFormattedString(inputField.text.Substring(inputField.caretPosition + 1, length), currentIndent, out caret);

                    //inputField.text = inputField.text.Remove(inputField.caretPosition + 1, length);
                    //inputField.text = inputField.text.Insert(inputField.caretPosition + 1, formatted);

                    //inputField.stringPosition = inputField.stringPosition + caret;
                    //return;
                }


                if (indent.Length > 0)
                {
                    // Get caret position
                    inputField.text = inputField.text.Insert(inputField.caretPosition + 1, indent);

                    // Move to the end of the new line
                    inputField.stringPosition = inputField.stringPosition + indent.Length;
                }

                //if (languageTheme.autoIndent.autoIndentMode == AutoIndent.IndentMode.AutoTabContextual)
                //{
                // Check for closing bracket
                bool immediateClosing = false;
                int  closingOffset    = -1;

                for (int i = inputField.caretPosition + 1; i < inputField.text.Length; i++)
                {
                    if (inputField.text[i] == languageTheme.autoIndent.indentDecreaseCharacter)
                    {
                        // Set the closing flag
                        immediateClosing = true;
                        closingOffset    = i - (inputField.caretPosition + 1);
                        break;
                    }

                    // Check for any other character
                    if (char.IsWhiteSpace(inputField.text[i]) == false || inputField.text[i] == '\n')
                    {
                        break;
                    }
                }

                if (immediateClosing == true)
                {
                    // Remove unnecessary white space
                    inputField.text = inputField.text.Remove(inputField.caretPosition + 1, closingOffset);

                    string localIndent = (string.IsNullOrEmpty(indent) == true) ? string.Empty : indent.Remove(0, 1);


                    // Insert new line
                    inputField.text = inputField.text.Insert(inputField.caretPosition + 1, GetAutoIndentTab(currentIndent) + "\n" + localIndent);

                    //inputField.stringPosition -= 1;

                    if (string.IsNullOrEmpty(localIndent) == false)
                    {
                        //inputField.stringPosition -= localIndent.Length;
                    }


                    // Update line column and indent positions
                    UpdateCurrentLineColumnIndent();
                }
            }
            //}

            // Check for closing token
            if (isClosingToken == true)
            {
                if (inputField.caretPosition > 0)
                {
                    // Check for tab before caret
                    if (inputField.text[inputField.caretPosition - 1] == '\t')
                    {
                        // Remove 1 tab because we have received a closing token
                        inputField.text = inputField.text.Remove(inputField.caretPosition - 1, 1);

                        inputField.stringPosition = inputField.stringPosition - 1;
                    }
                }
            }

            inputText.text = inputField.text;
            inputText.SetText(inputField.text, true);
            inputText.Rebuild(CanvasUpdate.Prelayout);
            inputField.ForceLabelUpdate();
            inputField.Rebuild(CanvasUpdate.Prelayout);
            Refresh(true);
            delayedRefresh = true;
        }