51 std::stringstream wrappedStream;
52 std::string::size_type spacePos, newlinePos, lastNewlinePos = 0;
56 spacePos = text.rfind(
" ", text.size());
58 if (spacePos != std::string::npos)
60 const std::string word = text.substr(spacePos + 1);
61 const int length = getFont()->getWidth(word);
70 newlinePos = text.find(
"\n", lastNewlinePos);
72 if (newlinePos == std::string::npos)
73 newlinePos = text.size();
76 text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
77 std::string::size_type lastSpacePos = 0;
82 spacePos = line.find(
" ", lastSpacePos);
84 if (spacePos == std::string::npos)
85 spacePos = line.size();
88 line.substr(lastSpacePos, spacePos - lastSpacePos);
90 int width = getFont()->getWidth(word);
96 wrappedStream << word;
98 else if (xpos != 0 && xpos + getFont()->getWidth(
" ") + width <=
101 xpos += getFont()->getWidth(
" ") + width;
102 wrappedStream <<
" " << word;
104 else if (lastSpacePos == 0)
107 wrappedStream << word;
118 wrappedStream.clear();
119 wrappedStream.str(std::string());
122 newlinePos = text.find(
"\n", lastNewlinePos);
123 if (newlinePos == std::string::npos)
124 newlinePos = text.size();
125 line = text.substr(lastNewlinePos, newlinePos -
132 wrappedStream <<
"\n" << word;
136 lastSpacePos = spacePos + 1;
138 while (spacePos != line.size());
140 if (text.find(
"\n", lastNewlinePos) != std::string::npos)
141 wrappedStream <<
"\n";
143 lastNewlinePos = newlinePos + 1;
145 while (newlinePos != text.size());
152 gcn::TextBox::setText(wrappedStream.str());
165 graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
168 if (isFocused() && isEditable())
171 getFont()->getWidth(mTextRows[mCaretRow].substr(0, mCaretColumn)),
172 mCaretRow * getFont()->getHeight());
180 for (i = 0; i < mTextRows.size(); i++)
185 i * getFont()->getHeight(),
void drawText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, const gcn::Color &color, gcn::Font *font, bool outline=false, bool shadow=false, const std::optional< gcn::Color > &outlineColor={}, const std::optional< gcn::Color > &shadowColor={})
std::optional< gcn::Color > mOutlineColor
void draw(gcn::Graphics *graphics) override
Draws the text.
void setTextWrapped(const std::string &text, int minDimension)
Sets the text after wrapping it to the current width of the widget.
const gcn::Color * mTextColor