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

Method makeStringSupportCursor

core/2d/TextFieldTTF.cpp:593–623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

591}
592
593void TextFieldTTF::makeStringSupportCursor(std::string& displayText)
594{
595 if (_cursorEnabled && _isAttachWithIME)
596 {
597 if (displayText.empty())
598 {
599 // \b - Next char not change x position
600 if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT)
601 displayText.push_back(StringUtils::AsciiCharacters::NextCharNoChangeX);
602 displayText.push_back(_cursorChar);
603 }
604 else
605 {
606 auto numChars = StringUtils::countUTF8Chars(displayText);
607 if (_cursorPosition > numChars)
608 _cursorPosition = numChars;
609
610 std::string cursorChar;
611 // \b - Next char not change x position
612 if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT)
613 cursorChar.push_back(StringUtils::AsciiCharacters::NextCharNoChangeX);
614 cursorChar.push_back(_cursorChar);
615
616 auto offset = StringUtils::getUTF8ByteOffset(displayText, _cursorPosition);
617 if (offset != std::string::npos)
618 displayText.insert(offset, cursorChar);
619 else
620 displayText += cursorChar;
621 }
622 }
623}
624
625void TextFieldTTF::updateCursorDisplayText()
626{

Callers

nothing calls this directly

Calls 5

countUTF8CharsFunction · 0.85
getUTF8ByteOffsetFunction · 0.85
emptyMethod · 0.45
push_backMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected