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

Method __moveCursorTo

core/ui/UITextFieldEx.cpp:985–1036  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

983}
984
985void TextFieldEx::__moveCursorTo(float x)
986{ // test
987 // normalized x
988 float normalizedX = 0;
989
990 std::string_view displayText;
991 if (!_secureTextEntry)
992 {
993 displayText = _inputText;
994 }
995 else
996 {
997 if (!_inputText.empty())
998 {
999 displayText = _renderLabel->getString();
1000 }
1001 }
1002
1003 int length = static_cast<int>(displayText.length());
1004 int n = static_cast<int>(_charCount); // UTF8 char counter
1005
1006 int insertWhere = 0;
1007 int insertWhereUtf8 = 0;
1008 while (length > 0)
1009 {
1010 auto checkX = internalCalcStringWidth(displayText, _fontName, _fontSize);
1011 if (x >= checkX)
1012 {
1013 insertWhere = length;
1014 insertWhereUtf8 = n;
1015 normalizedX = checkX;
1016 break;
1017 }
1018
1019 // clamp backward
1020 size_t backwardLen = 1; // default, erase 1 byte
1021 while (0x80 == (0xC0 & displayText.at(displayText.length() - backwardLen)))
1022 {
1023 ++backwardLen;
1024 }
1025
1026 --n;
1027 displayText.remove_suffix(backwardLen);
1028
1029 length -= backwardLen;
1030 }
1031
1032 _insertPos = !_secureTextEntry ? insertWhere : insertWhereUtf8;
1033 _cursorPos = insertWhere;
1034 _insertPosUtf8 = insertWhereUtf8;
1035 _cursor->setPosition(Point(normalizedX, this->getContentSize().height / 2));
1036}
1037}; // namespace ui
1038
1039}

Callers

nothing calls this directly

Calls 9

internalCalcStringWidthFunction · 0.85
remove_suffixMethod · 0.80
PointClass · 0.50
emptyMethod · 0.45
getStringMethod · 0.45
lengthMethod · 0.45
atMethod · 0.45
setPositionMethod · 0.45
getContentSizeMethod · 0.45

Tested by

no test coverage detected