void AdjustCaret(TextField.CharPosition cp) { _caretPosition = cp.caretIndex; Vector2 pos = GetCharLocation(cp); TextField.LineInfo line = textField.lines[cp.lineIndex]; pos.y = line.y + textField.y; Vector2 newPos = pos; if (newPos.x < textField.textFormat.size) { newPos.x += Math.Min(50, (int)(_contentRect.width / 2)); } else if (newPos.x > _contentRect.width - GUTTER_X - textField.textFormat.size) { newPos.x -= Math.Min(50, (int)(_contentRect.width / 2)); } if (newPos.x < GUTTER_X) { newPos.x = GUTTER_X; } else if (newPos.x > _contentRect.width - GUTTER_X) { newPos.x = Math.Max(GUTTER_X, _contentRect.width - GUTTER_X); } if (newPos.y < GUTTER_Y) { newPos.y = GUTTER_Y; } else if (newPos.y + line.height >= _contentRect.height - GUTTER_Y) { newPos.y = Math.Max(GUTTER_Y, _contentRect.height - line.height - GUTTER_Y); } pos += MoveContent(newPos - pos); if (_editing) { if (line.height > 0) //将光标居中 { pos.y += (int)(line.height - textField.textFormat.size) / 2; } _caret.SetPosition(pos.x, pos.y, 0); Vector2 cursorPos = _caret.LocalToGlobal(new Vector2(0, _caret.height)); Input.compositionCursorPos = cursorPos; _nextBlink = Time.time + 0.5f; _caret.graphics.enabled = true; if (_selectionStart != null) { UpdateSelection(cp); } } }
void UpdateCaret(bool forceUpdate = false) { TextField.CharPosition cp; if (_editing) { cp = GetCharPosition(_caretPosition + IMEAdapter.compositionString.Length); } else { cp = GetCharPosition(_caretPosition); } Vector2 pos = GetCharLocation(cp); TextField.LineInfo line = textField.lines[cp.lineIndex]; pos.Y = line.y + textField.y; Vector2 newPos = pos; if (newPos.X < textField.textFormat.size) { newPos.X += Math.Min(50, (int)(_contentRect.Width / 2)); } else if (newPos.X > _contentRect.Width - GUTTER_X - textField.textFormat.size) { newPos.X -= Math.Min(50, (int)(_contentRect.Width / 2)); } if (newPos.X < GUTTER_X) { newPos.X = GUTTER_X; } else if (newPos.X > _contentRect.Width - GUTTER_X) { newPos.X = Math.Max(GUTTER_X, _contentRect.Width - GUTTER_X); } if (newPos.Y < GUTTER_Y) { newPos.Y = GUTTER_Y; } else if (newPos.Y + line.height >= _contentRect.Height - GUTTER_Y) { newPos.Y = Math.Max(GUTTER_Y, _contentRect.Height - line.height - GUTTER_Y); } pos += MoveContent(newPos - pos, forceUpdate); if (_editing) { if (line.height > 0) //将光标居中 { pos.Y += (int)(line.height - textField.textFormat.size) / 2; } _caret.SetPosition(pos.X, pos.Y, 0); Vector2 cursorPos = _caret.LocalToGlobal(new Vector2(0, _caret.height)); IMEAdapter.compositionCursorPos = cursorPos; _nextBlink = Timers.time + 0.5f; _caret.graphics.enabled = true; UpdateSelection(cp); } }
void UpdateCaret(bool forceUpdate = false) { TextField.CharPosition cp; if (_editing) { cp = GetCharPosition(_caretPosition + Input.compositionString.Length); } else { cp = GetCharPosition(_caretPosition); } Vector2 pos = GetCharLocation(cp); TextField.LineInfo line = textField.lines[cp.lineIndex]; pos.y = line.y + textField.y; Vector2 newPos = pos; if (newPos.x < textField.textFormat.size) { newPos.x += Math.Min(50, (int)(_contentRect.width / 2)); } else if (newPos.x > _contentRect.width - GUTTER_X - textField.textFormat.size) { newPos.x -= Math.Min(50, (int)(_contentRect.width / 2)); } if (newPos.x < GUTTER_X) { newPos.x = GUTTER_X; } else if (newPos.x > _contentRect.width - GUTTER_X) { newPos.x = Math.Max(GUTTER_X, _contentRect.width - GUTTER_X); } if (newPos.y < GUTTER_Y) { newPos.y = GUTTER_Y; } else if (newPos.y + line.height >= _contentRect.height - GUTTER_Y) { newPos.y = Math.Max(GUTTER_Y, _contentRect.height - line.height - GUTTER_Y); } pos += MoveContent(newPos - pos, forceUpdate); if (_editing) { if (line.height > 0) //将光标居中 { pos.y += (int)(line.height - textField.textFormat.size) / 2; } _caret.SetPosition(pos.x, pos.y, 0); Vector2 cursorPos = _caret.LocalToGlobal(new Vector2(0, _caret.height)); Input.compositionCursorPos = UIScreen.UIScreenPosToScreenPos(cursorPos); _nextBlink = Time.time + 0.5f; _caret.graphics.enabled = true; UpdateSelection(cp); } }