improve textfield code

This commit is contained in:
zilongshanren 2016-04-01 09:31:18 +08:00
parent dcb7c58216
commit 90087ae5a7
4 changed files with 11 additions and 17 deletions

View File

@ -63,6 +63,7 @@ TextFieldTTF::TextFieldTTF()
, _placeHolder("") // prevent Label initWithString assertion
, _colorText(Color4B::WHITE)
, _secureTextEntry(false)
,_passwordStyleText("\u25CF")
, _cursorEnabled(false)
, _cursorPosition(0)
, _cursorChar(CURSOR_DEFAULT_CHAR)
@ -71,7 +72,6 @@ TextFieldTTF::TextFieldTTF()
{
_colorSpaceHolder.r = _colorSpaceHolder.g = _colorSpaceHolder.b = 127;
_colorSpaceHolder.a = 255;
_passwordStyleText = {(char)0xe2, (char)0x80, (char)0xa2, (char)0x00};
}
TextFieldTTF::~TextFieldTTF()
@ -422,7 +422,7 @@ void TextFieldTTF::update(float delta)
_cursorShowingTime = CURSOR_TIME_SHOW_HIDE;
}
// before cursor inserted '\b', need next letter
auto sprite = getLetter(_cursorPosition + 1);
auto sprite = getLetter((int)_cursorPosition + 1);
if (sprite)
{
@ -687,6 +687,11 @@ void TextFieldTTF::setSecureTextEntry(bool value)
void TextFieldTTF::setPasswordTextStyle(const std::string &text)
{
if (text.length() < 1)
{
return;
}
if (text != _passwordStyleText) {
_passwordStyleText = text;
setString(_inputText);

View File

@ -162,7 +162,7 @@ public:
* Query the currently inputed character count.
*@return The total input character count.
*/
inline int getCharCount() const { return _charCount; };
inline std::size_t getCharCount() const { return _charCount; };
/**
* Query the color of place holder.
@ -279,7 +279,7 @@ protected:
virtual void controlKey(EventKeyboard::KeyCode keyCode) override;
TextFieldDelegate * _delegate;
int _charCount;
std::size_t _charCount;
std::string _inputText;

View File

@ -194,7 +194,7 @@ int UICCTextField::getMaxLength()const
return _maxLength;
}
int UICCTextField::getCharCount()const
std::size_t UICCTextField::getCharCount()const
{
return TextFieldTTF::getCharCount();
}
@ -211,15 +211,6 @@ bool UICCTextField::isPasswordEnabled()const
void UICCTextField::setPasswordStyleText(const std::string& styleText)
{
if (styleText.length() > 1)
{
return;
}
char value = styleText[0];
if (value < 33 || value > 126)
{
return;
}
this->setPasswordTextStyle(styleText);
}
@ -573,8 +564,6 @@ int TextField::getMaxLength()const
void TextField::setPasswordEnabled(bool enable)
{
_textFieldRenderer->setPasswordEnabled(enable);
if (enable)
setPasswordStyleText(getPasswordStyleText());
}
bool TextField::isPasswordEnabled()const

View File

@ -119,7 +119,7 @@ public:
* Return the total inputed characters.
*@return Total inputed character count.
*/
int getCharCount()const;
std::size_t getCharCount()const;
/**