Skip to content

Commit f0a28d2

Browse files
sbrednikhinminggo
authored andcommitted
Partial cursor support for text field with system font (#18555)
* Partial cursor support for text field with system font Enables cursor support without cursor blinking an zero with of cursor symbol. In case of system font usage magical "/b" symbol won't be used, also update won't be scheduled. * Update CCTextFieldTTF.cpp
1 parent 4c0361e commit f0a28d2

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

cocos/2d/CCTextFieldTTF.cpp

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,8 @@ void TextFieldTTF::makeStringSupportCursor(std::string& displayText)
566566
if (displayText.empty())
567567
{
568568
// \b - Next char not change x position
569-
displayText.push_back((char)TextFormatter::NextCharNoChangeX);
569+
if (_currentLabelType == LabelType::TTF)
570+
displayText.push_back((char) TextFormatter::NextCharNoChangeX);
570571
displayText.push_back(_cursorChar);
571572
}
572573
else
@@ -581,7 +582,8 @@ void TextFieldTTF::makeStringSupportCursor(std::string& displayText)
581582
}
582583
std::string cursorChar;
583584
// \b - Next char not change x position
584-
cursorChar.push_back((char)TextFormatter::NextCharNoChangeX);
585+
if (_currentLabelType == LabelType::TTF)
586+
cursorChar.push_back((char)TextFormatter::NextCharNoChangeX);
585587
cursorChar.push_back(_cursorChar);
586588
stringUTF8.insert(_cursorPosition, cursorChar);
587589

@@ -679,29 +681,22 @@ const std::string& TextFieldTTF::getPlaceHolder() const
679681

680682
void TextFieldTTF::setCursorEnabled(bool enabled)
681683
{
682-
if (_currentLabelType == LabelType::TTF)
684+
if (_cursorEnabled != enabled)
683685
{
684-
if (_cursorEnabled != enabled)
686+
_cursorEnabled = enabled;
687+
if (_cursorEnabled)
685688
{
686-
_cursorEnabled = enabled;
687-
if (_cursorEnabled)
688-
{
689-
_cursorPosition = _charCount;
690-
689+
_cursorPosition = _charCount;
690+
if (_currentLabelType == LabelType::TTF)
691691
scheduleUpdate();
692-
}
693-
else
694-
{
695-
_cursorPosition = 0;
696-
692+
}
693+
else
694+
{
695+
_cursorPosition = 0;
696+
if (_currentLabelType == LabelType::TTF)
697697
unscheduleUpdate();
698-
}
699698
}
700699
}
701-
else
702-
{
703-
CCLOG("TextFieldTTF cursor worked only LabelType::TTF");
704-
}
705700
}
706701

707702
// secureTextEntry

0 commit comments

Comments
 (0)