input text property
| 778 | |
| 779 | // input text property |
| 780 | void TextFieldEx::setString(std::string_view text) |
| 781 | { |
| 782 | static char bulletString[] = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00}; |
| 783 | |
| 784 | _inputText = text; |
| 785 | |
| 786 | std::string secureText; |
| 787 | |
| 788 | std::string* displayText = &_inputText; |
| 789 | |
| 790 | if (!_inputText.empty()) |
| 791 | { |
| 792 | if (_secureTextEntry) |
| 793 | { |
| 794 | size_t length = _inputText.length(); |
| 795 | displayText = &secureText; |
| 796 | |
| 797 | while (length > 0) |
| 798 | { |
| 799 | displayText->append(bulletString); |
| 800 | --length; |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | // if there is no input text, display placeholder instead |
| 806 | if (_inputText.empty()) |
| 807 | { |
| 808 | _renderLabel->setTextColor(_colorSpaceHolder); |
| 809 | _renderLabel->setString(_placeHolder); |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | _renderLabel->setTextColor(_colorText); |
| 814 | _renderLabel->setString(*displayText); |
| 815 | } |
| 816 | |
| 817 | bool bInsertAtEnd = (_insertPosUtf8 == _charCount); |
| 818 | |
| 819 | _charCount = StringUtils::countUTF8Chars(_inputText); |
| 820 | |
| 821 | if (bInsertAtEnd) |
| 822 | { |
| 823 | _insertPosUtf8 = static_cast<int>(_charCount); |
| 824 | _insertPos = static_cast<int>(_inputText.length()); |
| 825 | _cursorPos = static_cast<int>(displayText->length()); |
| 826 | } |
| 827 | } |
| 828 | |
| 829 | void TextFieldEx::updateContentSize(void) |
| 830 | { |
no test coverage detected