| 935 | } |
| 936 | |
| 937 | void TextFieldEx::__moveCursor(int direction) |
| 938 | { |
| 939 | auto newOffset = _insertPosUtf8 + direction; |
| 940 | |
| 941 | if (newOffset > 0 && newOffset <= _charCount) |
| 942 | { |
| 943 | |
| 944 | std::string_view displayText; |
| 945 | if (!_secureTextEntry) |
| 946 | displayText = this->getString(); |
| 947 | else if (!_inputText.empty()) |
| 948 | displayText = _renderLabel->getString(); |
| 949 | |
| 950 | if (direction < 0) |
| 951 | { |
| 952 | _insertPos = static_cast<int>(internalUTF8MoveLeft(_inputText, _insertPos).size()); |
| 953 | |
| 954 | auto s = internalUTF8MoveLeft(displayText, _cursorPos); |
| 955 | |
| 956 | auto width = internalCalcStringWidth(s, _fontName, _fontSize); |
| 957 | _cursor->setPosition(Point(width, this->getContentSize().height / 2)); |
| 958 | _cursorPos = static_cast<int>(s.length()); |
| 959 | } |
| 960 | else |
| 961 | { |
| 962 | _insertPos = static_cast<int>(internalUTF8MoveRight(_inputText, _insertPos).size()); |
| 963 | |
| 964 | auto s = internalUTF8MoveRight(displayText, _cursorPos); |
| 965 | auto width = internalCalcStringWidth(s, _fontName, _fontSize); |
| 966 | _cursor->setPosition(Point(width, this->getContentSize().height / 2)); |
| 967 | _cursorPos = static_cast<int>(s.length()); |
| 968 | } |
| 969 | |
| 970 | _insertPosUtf8 = newOffset; |
| 971 | } |
| 972 | else if (newOffset == 0) |
| 973 | { |
| 974 | _cursor->setPosition(Point(0, this->getContentSize().height / 2)); |
| 975 | _insertPosUtf8 = newOffset; |
| 976 | _insertPos = 0; |
| 977 | _cursorPos = 0; |
| 978 | } |
| 979 | else |
| 980 | { |
| 981 | // MessageBeep(0); |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | void TextFieldEx::__moveCursorTo(float x) |
| 986 | { // test |
no test coverage detected