Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void adjustFontSize(Label *label, const float &desiredSize)
{
std::string str = label->getString();
const float estimatedCharSize = label->getBoundingBox().size.width / label->getStringLength();
const float columnNumberToWrap = desiredSize / estimatedCharSize;
const float numberOfTimesToWrap = label->getBoundingBox().size.width / desiredSize;
for (int i = 1; i < numberOfTimesToWrap; i++) {
const int index = columnNumberToWrap * i;
std::string splitter = std::isspace(str.at(index)) ? "\n" : "-\n";
str.insert(index, splitter);
}
label->setString(str);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment