MCPcopy Create free account
hub / github.com/axmolengine/axmol / __moveCursor

Method __moveCursor

core/ui/UITextFieldEx.cpp:937–983  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

935}
936
937void 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
985void TextFieldEx::__moveCursorTo(float x)
986{ // test

Callers 1

enableIMEMethod · 0.95

Calls 10

getStringMethod · 0.95
internalUTF8MoveLeftFunction · 0.85
internalCalcStringWidthFunction · 0.85
internalUTF8MoveRightFunction · 0.85
PointClass · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
setPositionMethod · 0.45
getContentSizeMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected