This commit is contained in:
bMorgan01 2022-03-08 10:18:34 -07:00
parent 54f5313273
commit b49080f675
83 changed files with 2083 additions and 0 deletions

31
TextBox.cpp Normal file
View file

@ -0,0 +1,31 @@
//
// Created by Benjamin on 2/27/2022.
//
#include <sstream>
#include "TextBox.h"
std::string wordWrap(const std::string &text, float length, const sf::Font &font, unsigned int charSize) {
std::istringstream iss(text);
std::vector<std::string> results((std::istream_iterator<std::string>(iss)), std::istream_iterator<std::string>());
sf::Text temp;
temp.setFont(font);
temp.setCharacterSize(charSize);
std::string tempStr;
std::string returnStr;
for (const std::string &s : results) {
tempStr += s + " ";
temp.setString(tempStr);
if (temp.getGlobalBounds().width < length) returnStr += s + " ";
else {
returnStr += "\n" + s + " ";
tempStr = s;
}
}
return returnStr;
}
TextBox::TextBox(const std::string &text, const sf::Font &font, unsigned int size, float x, float y, float w, int origin) : Label(wordWrap(text, w, font, size), font, size, x, y, origin) {}