Fix password style text in UTF-16 (#15620)

* Fix password style text in UTF-16

Label used UTF-16 in internal.
Need string in UTF-8.

* Set correct char for Max and iOS

* Add test for TextFiledTTF Secure Text Entry
This commit is contained in:
Vladimir Perminov 2016-05-23 04:48:15 +03:00 committed by minggo
parent 2c9716d714
commit b6d72e33d8
3 changed files with 51 additions and 3 deletions

View File

@ -34,7 +34,7 @@ NS_CC_BEGIN
#define CURSOR_TIME_SHOW_HIDE 0.5f #define CURSOR_TIME_SHOW_HIDE 0.5f
#define CURSOR_DEFAULT_CHAR '|' #define CURSOR_DEFAULT_CHAR '|'
#define PASSWORD_STYLE_TEXT_DEFAULT "\xe2\x80\xa2"
static int _calcCharCount(const char * text) static int _calcCharCount(const char * text)
{ {
int n = 0; int n = 0;
@ -63,7 +63,7 @@ TextFieldTTF::TextFieldTTF()
, _placeHolder("") // prevent Label initWithString assertion , _placeHolder("") // prevent Label initWithString assertion
, _colorText(Color4B::WHITE) , _colorText(Color4B::WHITE)
, _secureTextEntry(false) , _secureTextEntry(false)
,_passwordStyleText("\u25CF") , _passwordStyleText(PASSWORD_STYLE_TEXT_DEFAULT)
, _cursorEnabled(false) , _cursorEnabled(false)
, _cursorPosition(0) , _cursorPosition(0)
, _cursorChar(CURSOR_DEFAULT_CHAR) , _cursorChar(CURSOR_DEFAULT_CHAR)

View File

@ -9,6 +9,7 @@ TextInputTests::TextInputTests()
{ {
ADD_TEST_CASE(TextFieldTTFDefaultTest); ADD_TEST_CASE(TextFieldTTFDefaultTest);
ADD_TEST_CASE(TextFieldTTFActionTest); ADD_TEST_CASE(TextFieldTTFActionTest);
ADD_TEST_CASE(TextFieldTTFSecureTextEntryTest);
} }
static Rect getRect(Node * node) static Rect getRect(Node * node)
@ -340,3 +341,37 @@ void TextFieldTTFActionTest::callbackRemoveNodeWhenDidAction(Node * node)
{ {
this->removeChild(node, true); this->removeChild(node, true);
} }
//////////////////////////////////////////////////////////////////////////
// implement TextFieldTTFSecureTextEntryTest
//////////////////////////////////////////////////////////////////////////
std::string TextFieldTTFSecureTextEntryTest::subtitle() const
{
return "TextFieldTTF with SecureTextEntry test";
}
void TextFieldTTFSecureTextEntryTest::onEnter()
{
KeyboardNotificationLayer::onEnter();
// add TextFieldTTF
auto s = Director::getInstance()->getWinSize();
auto pTextField = TextFieldTTF::textFieldWithPlaceHolder("<click here for input>",
FONT_NAME,
FONT_SIZE);
addChild(pTextField);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
// on android, TextFieldTTF cannot auto adjust its position when soft-keyboard pop up
// so we had to set a higher position to make it visable
pTextField->setPosition(Vec2(s.width / 2, s.height/2 + 50));
#else
pTextField->setPosition(Vec2(s.width / 2, s.height / 2));
#endif
pTextField->setSecureTextEntry(true);
_trackNode = pTextField;
}

View File

@ -75,4 +75,17 @@ public:
virtual bool onDraw(cocos2d::TextFieldTTF* sender); virtual bool onDraw(cocos2d::TextFieldTTF* sender);
}; };
//////////////////////////////////////////////////////////////////////////
// TextFieldTTFSecureTextEntryTest for test TextFieldTTF SecureTextEntry.
//////////////////////////////////////////////////////////////////////////
class TextFieldTTFSecureTextEntryTest : public TextFieldTTFDefaultTest
{
public:
CREATE_FUNC(TextFieldTTFSecureTextEntryTest);
virtual std::string subtitle() const override;
// Layer
virtual void onEnter() override;
};
#endif // __TEXT_INPUT_TEST_H__ #endif // __TEXT_INPUT_TEST_H__