public new void SetText(string text) { if (text.ToString().Length > MaxLength) { text = text.ToString().Substring(0, MaxLength); } if (AllowTextEntered != null) { if (AllowTextEntered.Invoke(text)) { base.SetText(text); OnTextChanged?.Invoke(); } } else { base.SetText(text); OnTextChanged?.Invoke(); } if (text != HintText) { TextColor = new Color(252, 180, 151); } }
void variableControl_TextChanged(object sender, EventArgs e) { if (OnTextChanged != null) { OnTextChanged.Invoke(sender, e); } }
public void SetText(string text) { if (currentString != text) { currentString = text; OnTextChanged?.Invoke(); } }
public void Write(string text) { base.SetText(base.Text.Insert(this._cursor, text)); this._cursor += text.Length; _cursor = Math.Min(Text.Length, _cursor); Recalculate(); OnTextChanged?.Invoke(); }
private void RaiseEvent() { var handler = OnTextChanged; if (handler != null) { OnTextChanged?.Invoke(); } }
void localize(Language language) { if (text != null && !string.IsNullOrEmpty(key)) { string localiaztion = LanguageManager.Instance.GetLocalization(key, language); text.text = localiaztion; OnTextChanged?.Invoke(); } }
/// <summary> /// Triggered when editing of the text ends (field loses focus). /// </summary> /// <param name="text">The text entered.</param> private void OnEndEdit(string text) { var obj = gameObject; if (obj != null) { OnTextChanged?.Invoke(obj, text); } StartCoroutine(DelayEndEdit()); }
public override void Draw() { string newText; if (Text != (newText = GUILayout.TextField(Text, Options)) && OnTextChanged != null) { var args = new TextChangedEventArgs(Text, newText); Text = newText; OnTextChanged.Invoke(this, args); } }
public void SetText(string text) { if (text.ToString().Length > _maxLength) { text = text.ToString().Substring(0, _maxLength); } if (currentString != text) { currentString = text; OnTextChanged?.Invoke(); } }
public void ReceiveTextInput(string input) { if (selectedCharacters > 0) { RemoveSelectedText(); } if (SetText(Text.Insert(CaretIndex, input))) { CaretIndex = Math.Min(Text.Length, CaretIndex + input.Length); OnTextChanged?.Invoke(this, Text); } }
public override void SetText(string text, float textScale, bool large) { if (text.ToString().Length > this._maxLength) { text = text.ToString().Substring(0, this._maxLength); } base.SetText(text, textScale, large); this._cursor = Math.Min(base.Text.Length, this._cursor); OnTextChanged?.Invoke(); }
public void WriteAll(string text) { bool changed = text != Text; base.SetText(text); this._cursor = text.Length; Recalculate(); if (changed) { OnTextChanged?.Invoke(); } }
public void Write(string text) { base.SetText(base.Text.Insert(this._cursor, text)); this._cursor += text.Length; _cursor = Math.Min(Text.Length, _cursor); int lines = text.Split('\n').Length; Recalculate(); this.MinHeight.Set(-4 + lines * 28 + this.PaddingTop + this.PaddingBottom, 0f); OnTextChanged?.Invoke(); }
public void WriteAll(string text) { bool changed = text != Text; SetText(text); _cursor = text.Length; //_cursor = Math.Min(Text.Length, _cursor); Recalculate(); if (changed) { OnTextChanged?.Invoke(); } }
public override void SetText(string text, float textScale, bool large) { if (text.ToString().Length > _maxLength) { text = text.ToString().Substring(0, _maxLength); } base.SetText(text, textScale, large); //this.MinWidth.Set(120, 0f); _cursor = Math.Min(Text.Length, _cursor); OnTextChanged?.Invoke(); }
public void ReceiveCommandInput(char command) { if (Text == null) { Text = ""; } switch (command) { case '\b': //backspace if (selectedCharacters > 0) { RemoveSelectedText(); } else if (Text.Length > 0 && CaretIndex > 0) { CaretIndex--; SetText(Text.Remove(CaretIndex, 1)); CalculateCaretPos(); ClearSelection(); } OnTextChanged?.Invoke(this, Text); break; case (char)0x3: // ctrl-c CopySelectedText(); break; case (char)0x16: // ctrl-v string text = GetCopiedText(); RemoveSelectedText(); if (SetText(Text.Insert(CaretIndex, text))) { CaretIndex = Math.Min(Text.Length, CaretIndex + text.Length); OnTextChanged?.Invoke(this, Text); } break; case (char)0x18: // ctrl-x CopySelectedText(); RemoveSelectedText(); break; case (char)0x1: // ctrl-a SelectAll(); break; } }
private void RemoveSelectedText() { if (selectedText.Length == 0) { return; } selectionStartIndex = Math.Max(0, Math.Min(selectionEndIndex, Math.Min(selectionStartIndex, Text.Length - 1))); int selectionLength = Math.Min(Text.Length - selectionStartIndex, selectedText.Length); SetText(Text.Remove(selectionStartIndex, selectionLength)); CaretIndex = Math.Min(Text.Length, selectionStartIndex); ClearSelection(); OnTextChanged?.Invoke(this, Text); }
//public void Write(string text) //{ // base.SetText(base.Text.Insert(this._cursor, text)); // this._cursor += text.Length; // _cursor = Math.Min(Text.Length, _cursor); // Recalculate(); // OnTextChanged?.Invoke(); //} //public void WriteAll(string text) //{ // bool changed = text != Text; // if (!changed) return; // base.SetText(text); // this._cursor = text.Length; // //_cursor = Math.Min(Text.Length, _cursor); // Recalculate(); // if (changed) // { // OnTextChanged?.Invoke(); // } //} public void SetText(string text) { if (text.ToString().Length > this._maxLength) { text = text.ToString().Substring(0, this._maxLength); } if (currentString != text) { currentString = text; //OnTextChanged?.Invoke(); //### if (OnTextChanged != null) { OnTextChanged.Invoke(); } } }
private void RemoveSelectedText() { if (selectedText.Length == 0) { return; } if (IsLeftToRight) { SetText(Text.Remove(selectionStartIndex, selectedText.Length)); CaretIndex = Math.Min(Text.Length, selectionStartIndex); } else { SetText(Text.Remove(selectionEndIndex, selectedText.Length)); CaretIndex = Math.Min(Text.Length, selectionEndIndex); } ClearSelection(); OnTextChanged?.Invoke(this, Text); }
public void ReceiveTextInput(string input) { if (selectedCharacters > 0) { RemoveSelectedText(); } Vector2 textPos = textBlock.TextPos; bool wasOverflowClipActive = textBlock.OverflowClipActive; if (SetText(Text.Insert(CaretIndex, input))) { CaretIndex = Math.Min(Text.Length, CaretIndex + input.Length); OnTextChanged?.Invoke(this, Text); if (textBlock.OverflowClipActive && wasOverflowClipActive && !MathUtils.NearlyEqual(textBlock.TextPos, textPos)) { textBlock.TextPos = textPos + Vector2.UnitX * Font.MeasureString(input).X; } } }
void Fire_OnTextChanged(object editor, object changeObj) { if (isFiring_OnTextChanged) { return; } isFiring_OnTextChanged = true; if (_editor != null) { var editorValue = Script.Write <string>("this._editor.getValue()"); Text = editorValue; } OnTextChanged?.Invoke(); isFiring_OnTextChanged = false; }
public object AddTextfield(string text, string defaultContent, OnTextChanged eventChangedCallback, OnTextSubmitted eventSubmittedCallback) { if ((eventChangedCallback != null || eventSubmittedCallback != null) && !string.IsNullOrEmpty(text)) { UIPanel uIPanel = this.m_Root.AttachUIComponent(UITemplateManager.GetAsGameObject(kTextfieldTemplate)) as UIPanel; uIPanel.Find <UILabel>("Label").text = text; UITextField uITextField = uIPanel.Find <UITextField>("Text Field"); uITextField.text = defaultContent; uITextField.eventTextChanged += delegate(UIComponent c, string sel) { eventChangedCallback?.Invoke(sel); }; uITextField.eventTextSubmitted += delegate(UIComponent c, string sel) { eventSubmittedCallback?.Invoke(sel); }; return(uITextField); } DebugOutputPanel.AddMessage(PluginManager.MessageType.Warning, "Cannot create dropdown with no name or no event"); return(null); }
public override void SetText(string text, float textScale, bool large) { string lastLine = text.Split('\n').Last(); if (lastLine.Length > this._maxLineLength) { //text = text + "\n"; } //if (text.ToString().Length > this._maxLength) //{ // text = text.ToString().Substring(0, this._maxLength); //} base.SetText(text, textScale, large); int lines = text.Split('\n').Length; this.MinHeight.Set(-4 + lines * 28 + this.PaddingTop + this.PaddingBottom, 0f); //this.MinWidth.Set(120, 0f); this._cursor = Math.Min(base.Text.Length, this._cursor); OnTextChanged?.Invoke(); }
public void ReceiveSpecialInput(Keys key) { switch (key) { case Keys.Left: if (isSelecting) { InitSelectionStart(); } CaretIndex = Math.Max(CaretIndex - 1, 0); caretTimer = 0; HandleSelection(); break; case Keys.Right: if (isSelecting) { InitSelectionStart(); } CaretIndex = Math.Min(CaretIndex + 1, Text.Length); caretTimer = 0; HandleSelection(); break; case Keys.Up: if (isSelecting) { InitSelectionStart(); } float lineHeight = Font.MeasureString("T").Y *TextBlock.TextScale; int newIndex = textBlock.GetCaretIndexFromLocalPos(new Vector2(caretPos.X, caretPos.Y - lineHeight)); CaretIndex = newIndex; caretTimer = 0; HandleSelection(); break; case Keys.Down: if (isSelecting) { InitSelectionStart(); } lineHeight = Font.MeasureString("T").Y *TextBlock.TextScale; newIndex = textBlock.GetCaretIndexFromLocalPos(new Vector2(caretPos.X, caretPos.Y + lineHeight)); CaretIndex = newIndex; caretTimer = 0; HandleSelection(); break; case Keys.Delete when !Readonly: if (selectedCharacters > 0) { RemoveSelectedText(); } else if (Text.Length > 0 && CaretIndex < Text.Length) { SetText(Text.Remove(CaretIndex, 1)); OnTextChanged?.Invoke(this, Text); caretPosDirty = true; } break; case Keys.Tab: // Select the next text box. var editor = RectTransform.GetParents().Select(p => p.GUIComponent as SerializableEntityEditor).FirstOrDefault(e => e != null); if (editor == null) { break; } var allTextBoxes = GetAndSortTextBoxes(editor).ToList(); if (allTextBoxes.Any()) { int currentIndex = allTextBoxes.IndexOf(this); int nextIndex = Math.Min(allTextBoxes.Count - 1, currentIndex + 1); var next = allTextBoxes[nextIndex]; if (next != this) { next.Select(); next.Flash(Color.White * 0.5f, 0.5f); } else { // Select the first text box in the next editor that has text boxes. var listBox = RectTransform.GetParents().Select(p => p.GUIComponent as GUIListBox).FirstOrDefault(lb => lb != null); if (listBox == null) { break; } // TODO: The get's out of focus if the selection is out of view. // Not sure how's that possible, but it seems to work when the auto scroll is disabled and you handle the scrolling manually. listBox.SelectNext(); while (SelectNextTextBox(listBox) == null) { var previous = listBox.SelectedComponent; listBox.SelectNext(); if (listBox.SelectedComponent == previous) { break; } } } } IEnumerable <GUITextBox> GetAndSortTextBoxes(GUIComponent parent) => parent.GetAllChildren <GUITextBox>().OrderBy(t => t.Rect.Y).ThenBy(t => t.Rect.X); GUITextBox SelectNextTextBox(GUIListBox listBox) { var textBoxes = GetAndSortTextBoxes(listBox.SelectedComponent); if (textBoxes.Any()) { var next = textBoxes.First(); next.Select(); next.Flash(Color.White * 0.5f, 0.5f); return(next); } return(null); } break; } OnKeyHit?.Invoke(this, key); void HandleSelection() { if (isSelecting) { InitSelectionStart(); CalculateSelection(); } else { ClearSelection(); } } }
public void ReceiveCommandInput(char command) { if (Text == null) { Text = ""; } switch (command) { case '\b' when !Readonly: //backspace if (PlayerInput.KeyDown(Keys.LeftControl) || PlayerInput.KeyDown(Keys.RightControl)) { SetText(string.Empty, false); CaretIndex = Text.Length; } else if (selectedCharacters > 0) { RemoveSelectedText(); } else if (Text.Length > 0 && CaretIndex > 0) { CaretIndex--; SetText(Text.Remove(CaretIndex, 1)); CalculateCaretPos(); ClearSelection(); } OnTextChanged?.Invoke(this, Text); break; case (char)0x3: // ctrl-c CopySelectedText(); break; case (char)0x16 when !Readonly: // ctrl-v string text = GetCopiedText(); RemoveSelectedText(); if (SetText(Text.Insert(CaretIndex, text))) { CaretIndex = Math.Min(Text.Length, CaretIndex + text.Length); OnTextChanged?.Invoke(this, Text); } break; case (char)0x18: // ctrl-x CopySelectedText(); if (!Readonly) { RemoveSelectedText(); } break; case (char)0x1: // ctrl-a SelectAll(); break; case (char)0x1A when !Readonly: // ctrl-z text = memento.Undo(); if (text != Text) { ClearSelection(); SetText(text, false); CaretIndex = Text.Length; OnTextChanged?.Invoke(this, Text); } break; case (char)0x12 when !Readonly: // ctrl-r text = memento.Redo(); if (text != Text) { ClearSelection(); SetText(text, false); CaretIndex = Text.Length; OnTextChanged?.Invoke(this, Text); } break; } }
protected override void DrawSelf(SpriteBatch spriteBatch) { Rectangle hitbox = GetInnerDimensions().ToRectangle(); // Draw panel base.DrawSelf(spriteBatch); // Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Yellow); if (focused) { Terraria.GameInput.PlayerInput.WritingText = true; Main.instance.HandleIME(); string newString = Main.GetInputText(currentString); if (!newString.Equals(currentString)) { currentString = newString; OnTextChanged?.Invoke(); } else { currentString = newString; } if (JustPressed(Keys.Tab)) { if (unfocusOnTab) { Unfocus(); } OnTabPressed?.Invoke(); } if (JustPressed(Keys.Enter)) { Main.drawingPlayerChat = false; if (unfocusOnEnter) { Unfocus(); } OnEnterPressed?.Invoke(); } if (++textBlinkerCount >= 20) { textBlinkerState = (textBlinkerState + 1) % 2; textBlinkerCount = 0; } Main.instance.DrawWindowsIMEPanel(new Vector2(98f, Main.screenHeight - 36), 0f); } string displayString = currentString; if (textBlinkerState == 1 && focused) { displayString = displayString + "|"; } CalculatedStyle space = base.GetDimensions(); Color color = Color.Black; if (currentString.Length == 0) { } Vector2 drawPos = space.Position() + new Vector2(4, 2); if (currentString.Length == 0 && !focused) { color *= 0.5f; //Utils.DrawBorderString(spriteBatch, hintText, new Vector2(space.X, space.Y), Color.Gray, 1f); spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color); } else { //Utils.DrawBorderString(spriteBatch, displayString, drawPos, Color.White, 1f); spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color); } }
protected override void DrawSelf(SpriteBatch spriteBatch) { Rectangle hitbox = GetInnerDimensions().ToRectangle(); // Draw panel base.DrawSelf(spriteBatch); // Main.spriteBatch.Draw(Main.magicPixel, hitbox, Color.Yellow); if (focused) { Terraria.GameInput.PlayerInput.WritingText = true; Main.instance.HandleIME(); string newString = Main.GetInputText(""); if (newString != null && newString != "") { history.Push(currentString); currentString = currentString.Insert(cursorPos, newString); cursorPos += newString.Length; OnTextChanged?.Invoke(); } if (JustPressed(Keys.Tab)) { if (unfocusOnTab) { Unfocus(); } OnTabPressed?.Invoke(); } else if (JustPressed(Keys.Enter)) { Main.drawingPlayerChat = false; if (unfocusOnEnter) { Unfocus(); } OnEnterPressed?.Invoke(); } else if (JustPressed(Keys.Left)) { cursorPos -= 1; if (cursorPos < 0) { cursorPos = 0; } } else if (JustPressed(Keys.Right)) { cursorPos += 1; if (cursorPos > currentString.Length) { cursorPos = currentString.Length; } } else if (JustPressed(Keys.End)) { cursorPos = currentString.Length; } else if (JustPressed(Keys.Home)) { cursorPos = 0; } else if (JustPressed(Keys.Back) && cursorPos != 0) { history.Push(currentString); currentString = currentString.Remove(cursorPos - 1, 1); OnTextChanged?.Invoke(); cursorPos -= 1; } else if (JustPressed(Keys.Delete) && cursorPos != currentString.Length) { history.Push(currentString); currentString = currentString.Remove(cursorPos, 1); OnTextChanged?.Invoke(); } else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.C)) { ReLogic.OS.Platform.Current.Clipboard = currentString; } else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.X)) { history.Push(currentString); ReLogic.OS.Platform.Current.Clipboard = currentString; OnTextChanged?.Invoke(); currentString = ""; cursorPos = 0; } else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.V)) { history.Push(currentString); currentString = currentString.Insert(cursorPos, ReLogic.OS.Platform.Current.Clipboard); cursorPos += ReLogic.OS.Platform.Current.Clipboard.Length; OnTextChanged?.Invoke(); } else if (IsPressed(Keys.LeftControl) && JustPressed(Keys.Z) && history.Count > 0) { currentString = history.Pop(); cursorPos = currentString.Length; } if (++textBlinkerCount >= 20) { textBlinkerState = (textBlinkerState + 1) % 2; textBlinkerCount = 0; } Main.instance.DrawWindowsIMEPanel(new Vector2(98f, (float)(Main.screenHeight - 36)), 0f); } string displayString = currentString; string cursorChar = " "; if (textBlinkerState == 1) { cursorChar = "|"; } if (focused) { displayString = displayString.Insert(cursorPos, cursorChar); } CalculatedStyle space = base.GetDimensions(); Color color = textColor; if (currentString.Length == 0) { } Vector2 drawPos = space.Position() + new Vector2(4, 2); if (currentString.Length == 0 && !focused) { color *= 0.5f; //Utils.DrawBorderString(spriteBatch, hintText, new Vector2(space.X, space.Y), Color.Gray, 1f); spriteBatch.DrawString(Main.fontMouseText, hintText, drawPos, color); } else { //Utils.DrawBorderString(spriteBatch, displayString, drawPos, Color.White, 1f); spriteBatch.DrawString(Main.fontMouseText, displayString, drawPos, color); } if (IsMouseHovering) { Main.hoverItemName = hoverText; } }
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { OnTextChanged?.Invoke(sender, e); }
public override void OnTextInput(string text) { base.OnTextInput(text); if (Focused) { char c = text[0]; string tmpText = _realText; if (c == 8) { if (_realText.Length > 0) { if (_text.IsAnyTextSelected) { RemoveSelectedText(); } else if (_currentIndex > 0) { _realText = _realText.Remove(_currentIndex - 1, 1); _currentIndex--; } } } else if (c == 13 && _text.Lines < MaxLines) { _realText = _realText.Insert(_currentIndex, "\n"); _currentIndex++; } else if (!char.IsControl(c)) { RemoveSelectedText(); if ((char.IsDigit(c) && AllowNumbers == true) || (c == '-' && _currentIndex == 0 && _realText.Contains("-") == false)) { _realText = _realText.Insert(_currentIndex, text); _currentIndex++; } if (char.IsLetter(c) && AllowLetters == true) { _realText = _realText.Insert(_currentIndex, text); _currentIndex++; } if ((char.IsSymbol(c) || char.IsPunctuation(c) || char.IsSeparator(c)) && char.IsWhiteSpace(c) == false && AllowSpecialCharacters == true) { _realText = _realText.Insert(_currentIndex, text); _currentIndex++; } if (char.IsWhiteSpace(c)) { _realText = _realText.Insert(_currentIndex, text); _currentIndex++; } } UpdateValue(); if (_realText != tmpText) { OnTextChanged?.Invoke(this, _realText); } } }
public void NoticeChanged(string value) { OnTextChanged?.Invoke(value); }