mirror of https://github.com/axmolengine/axmol.git
refactor
This commit is contained in:
parent
e7da7b3e42
commit
f2b0528cc9
|
@ -109,7 +109,7 @@ Widget* Helper::seekActionWidgetByActionTag(Widget* root, int tag)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Helper::utf8_substr(const std::string& str, std::string::size_type start, std::string::size_type length)
|
std::string Helper::getSubStringOfUTF8String(const std::string& str, std::string::size_type start, std::string::size_type length)
|
||||||
{
|
{
|
||||||
if (length==0)
|
if (length==0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -68,13 +68,13 @@ public:
|
||||||
static Widget* seekActionWidgetByActionTag(Widget* root, int tag);
|
static Widget* seekActionWidgetByActionTag(Widget* root, int tag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get a utf8 substring from a std::string with a given start position and length
|
* @brief Get a UTF8 substring from a std::string with a given start position and length
|
||||||
* Sample: std::string str = "中国中国中国”; substr = utf8_substr(str,0,2) will = "中国"
|
* Sample: std::string str = "中国中国中国”; substr = getSubStringOfUTF8String(str,0,2) will = "中国"
|
||||||
* @param start The start position of the substring.
|
* @param start The start position of the substring.
|
||||||
* @param length The length of the substring in utf8 count
|
* @param length The length of the substring in UTF8 count
|
||||||
* @return a utf8 substring
|
* @return a UTF8 substring
|
||||||
*/
|
*/
|
||||||
static std::string utf8_substr(const std::string& str,
|
static std::string getSubStringOfUTF8String(const std::string& str,
|
||||||
std::string::size_type start,
|
std::string::size_type start,
|
||||||
std::string::size_type length);
|
std::string::size_type length);
|
||||||
|
|
||||||
|
|
|
@ -283,18 +283,18 @@ void RichText::handleTextRenderer(const std::string& text, const std::string& fo
|
||||||
std::string curText = text;
|
std::string curText = text;
|
||||||
size_t stringLength = StringUtils::getCharacterCountInUTF8String(text);
|
size_t stringLength = StringUtils::getCharacterCountInUTF8String(text);
|
||||||
int leftLength = stringLength * (1.0f - overstepPercent);
|
int leftLength = stringLength * (1.0f - overstepPercent);
|
||||||
std::string leftWords = Helper::utf8_substr(curText,0,leftLength);
|
std::string leftWords = Helper::getSubStringOfUTF8String(curText,0,leftLength);
|
||||||
std::string cutWords = Helper::utf8_substr(curText, leftLength, stringLength - leftLength);
|
std::string cutWords = Helper::getSubStringOfUTF8String(curText, leftLength, stringLength - leftLength);
|
||||||
if (leftLength > 0)
|
if (leftLength > 0)
|
||||||
{
|
{
|
||||||
Label* leftRenderer = nullptr;
|
Label* leftRenderer = nullptr;
|
||||||
if (fileExist)
|
if (fileExist)
|
||||||
{
|
{
|
||||||
leftRenderer = Label::createWithTTF(Helper::utf8_substr(leftWords, 0, leftLength), fontName, fontSize);
|
leftRenderer = Label::createWithTTF(Helper::getSubStringOfUTF8String(leftWords, 0, leftLength), fontName, fontSize);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
leftRenderer = Label::createWithSystemFont(Helper::utf8_substr(leftWords, 0, leftLength), fontName, fontSize);
|
leftRenderer = Label::createWithSystemFont(Helper::getSubStringOfUTF8String(leftWords, 0, leftLength), fontName, fontSize);
|
||||||
}
|
}
|
||||||
if (leftRenderer)
|
if (leftRenderer)
|
||||||
{
|
{
|
||||||
|
|
|
@ -133,7 +133,7 @@ void UICCTextField::insertText(const char* text, size_t len)
|
||||||
{
|
{
|
||||||
long length = _maxLength - text_count;
|
long length = _maxLength - text_count;
|
||||||
|
|
||||||
input_text = Helper::utf8_substr(input_text, 0, length);
|
input_text = Helper::getSubStringOfUTF8String(input_text, 0, length);
|
||||||
len = input_text.length();
|
len = input_text.length();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ void TextField::setText(const std::string& text)
|
||||||
long total = text_count + StringUtils::getCharacterCountInUTF8String(getStringValue());
|
long total = text_count + StringUtils::getCharacterCountInUTF8String(getStringValue());
|
||||||
if (total > max)
|
if (total > max)
|
||||||
{
|
{
|
||||||
strText = Helper::utf8_substr(strText, 0, max);
|
strText = Helper::getSubStringOfUTF8String(strText, 0, max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,12 +26,12 @@ bool UIRichTextTest::init()
|
||||||
str1.c_str(),
|
str1.c_str(),
|
||||||
str1.length(),
|
str1.length(),
|
||||||
StringUtils::getCharacterCountInUTF8String(str1),
|
StringUtils::getCharacterCountInUTF8String(str1),
|
||||||
Helper::utf8_substr(str1, 0, 5).c_str());
|
Helper::getSubStringOfUTF8String(str1, 0, 5).c_str());
|
||||||
CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s",
|
CCLOG("str2:%s ascii length = %ld, utf8 length = %ld, substr = %s",
|
||||||
str2.c_str(),
|
str2.c_str(),
|
||||||
str2.length(),
|
str2.length(),
|
||||||
StringUtils::getCharacterCountInUTF8String(str2),
|
StringUtils::getCharacterCountInUTF8String(str2),
|
||||||
Helper::utf8_substr(str2, 0, 2).c_str());
|
Helper::getSubStringOfUTF8String(str2, 0, 2).c_str());
|
||||||
|
|
||||||
// Add the alert
|
// Add the alert
|
||||||
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
|
Text *alert = Text::create("RichText", "fonts/Marker Felt.ttf", 30);
|
||||||
|
|
|
@ -277,7 +277,7 @@ bool UITextFieldTest_LineWrap::init()
|
||||||
textField->ignoreContentAdaptWithSize(false);
|
textField->ignoreContentAdaptWithSize(false);
|
||||||
((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true);
|
((Label*)(textField->getVirtualRenderer()))->setLineBreakWithoutSpace(true);
|
||||||
textField->setContentSize(Size(240, 170));
|
textField->setContentSize(Size(240, 170));
|
||||||
textField->setText("input words hereinput words hereinput words hereinput words hereinput words hereinput words here");
|
textField->setText("input words here");
|
||||||
textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
|
textField->setTextHorizontalAlignment(TextHAlignment::CENTER);
|
||||||
textField->setTextVerticalAlignment(TextVAlignment::CENTER);
|
textField->setTextVerticalAlignment(TextVAlignment::CENTER);
|
||||||
textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
textField->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
||||||
|
|
Loading…
Reference in New Issue