This commit is contained in:
halx99 2021-12-01 12:02:42 +08:00 committed by GitHub
parent 629b882230
commit 00d8a4ef5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 8 deletions

View File

@ -176,9 +176,9 @@ namespace ui {
} }
} }
static float internalCalcStringWidth(const std::string& s, const std::string& fontName, float fontSize) static float internalCalcStringWidth(std::string_view s, const std::string& fontName, float fontSize)
{ {
auto label = createLabel(s, fontName, fontSize); auto label = createLabel(std::string{s}, fontName, fontSize);
return label->getContentSize().width; return label->getContentSize().width;
} }
@ -197,7 +197,7 @@ namespace ui {
return std::string{utf8Text.data(), static_cast<size_t>(length - deleteLen)}; return std::string{utf8Text.data(), static_cast<size_t>(length - deleteLen)};
} }
else { else {
return utf8Text; return std::string{utf8Text};
} }
} }
@ -216,7 +216,7 @@ namespace ui {
return std::string{utf8Text.data(), static_cast<size_t>(length + addLen)}; return std::string{utf8Text.data(), static_cast<size_t>(length + addLen)};
} }
else { else {
return utf8Text; return std::string{utf8Text};
} }
} }
@ -333,7 +333,8 @@ namespace ui {
} }
this->fontName = fontName; this->fontName = fontName;
this->asteriskWidth = internalCalcStringWidth("*", this->fontName, this->fontSize); using namespace std::string_view_literals;
this->asteriskWidth = internalCalcStringWidth("*"sv, this->fontName, this->fontSize);
} }
void TextFieldEx::setTextFontSize(float size) void TextFieldEx::setTextFontSize(float size)
@ -351,7 +352,8 @@ namespace ui {
this->fontSize = size; this->fontSize = size;
this->asteriskWidth = internalCalcStringWidth("*", this->fontName, this->fontSize); using namespace std::string_view_literals;
this->asteriskWidth = internalCalcStringWidth("*"sv, this->fontName, this->fontSize);
} }
float TextFieldEx::getTextFontSize() const float TextFieldEx::getTextFontSize() const
@ -982,7 +984,7 @@ namespace ui {
// normalized x // normalized x
float normalizedX = 0; float normalizedX = 0;
std::string displayText; std::string_view displayText;
if (!secureTextEntry) if (!secureTextEntry)
{ {
displayText = this->inputText; displayText = this->inputText;
@ -1018,7 +1020,7 @@ namespace ui {
} }
--n; --n;
displayText.resize(displayText.length() - backwardLen); displayText.remove_suffix(backwardLen);
length -= backwardLen; length -= backwardLen;
} }