Skip to content

Instantly share code, notes, and snippets.

@Furkanzmc
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Furkanzmc/84e8bd6c86bb2a92ee6d to your computer and use it in GitHub Desktop.
Save Furkanzmc/84e8bd6c86bb2a92ee6d to your computer and use it in GitHub Desktop.
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