73 #include "render/graphics.h"
86 mMinWidth(getWidth()),
119 const size_t textSize = text.size();
120 size_t spacePos = text.rfind(
' ', textSize);
122 if (spacePos != std::string::npos)
124 const std::string word = text.substr(spacePos + 1);
131 std::stringstream wrappedStream;
133 size_t lastNewlinePos = 0;
140 newlinePos = text.find(
'\n', lastNewlinePos);
142 if (newlinePos == std::string::npos)
143 newlinePos = textSize;
146 text.substr(lastNewlinePos, newlinePos - lastNewlinePos);
147 size_t lastSpacePos = 0;
150 const int spaceWidth = font->
getWidth(
" ");
151 size_t sz = line.size();
155 spacePos = line.find(
' ', lastSpacePos);
157 if (spacePos == std::string::npos)
160 const std::string word =
161 line.substr(lastSpacePos, spacePos - lastSpacePos);
163 const int width = font->
getWidth(word);
169 wrappedStream << word;
171 else if (xpos != 0 && xpos + spaceWidth + width <=
174 xpos += spaceWidth + width;
175 wrappedStream <<
" " << word;
177 else if (lastSpacePos == 0)
180 wrappedStream << word;
191 wrappedStream.clear();
192 wrappedStream.str(
"");
194 newlinePos = text.find(
'\n', lastNewlinePos);
195 if (newlinePos == std::string::npos)
196 newlinePos = textSize;
197 line = text.substr(lastNewlinePos, newlinePos -
204 wrappedStream <<
"\n" << word;
208 lastSpacePos = spacePos + 1;
210 while (spacePos != sz);
212 if (text.find(
'\n', lastNewlinePos) != std::string::npos)
213 wrappedStream <<
"\n";
215 lastNewlinePos = newlinePos + 1;
217 while (newlinePos != textSize);
244 pos = text.find(
'\n', lastPos);
246 if (pos != std::string::npos)
249 length =
CAST_S32(text.size() - lastPos);
250 std::string sub = text.substr(lastPos, length);
253 }
while (pos != std::string::npos);
260 const Key &key =
event.getKey();
264 PRAGMA45(GCC diagnostic ignored
"-Wswitch-enum")
463 const int fontHeight = font->
getHeight();
465 for (
size_t i = 0, sz =
mTextRows.size(); i < sz; i++)
498 return std::string();
504 for (i = 0; i < sz - 1; ++ i)
560 for (
int row = 0; row <
mCaretRow; row++)
639 for (
size_t i = 0, sz =
mTextRows.size(); i < sz; ++i)
int getStringIndexAt(const std::string &text, const int x) const
int getWidth(const std::string &text) const
void drawString(Graphics *const graphics, Color col, const Color &col2, const std::string &text, const int x, const int y)
virtual void fillRectangle(const Rect &rectangle)=0
virtual void setColor(const Color &color)
virtual void drawLine(int x1, int y1, int x2, int y2)=0
void removeDragged(const Widget *const widget)
MouseButtonT getButton() const
void safeDraw(Graphics *const graphics)
void mouseDragged(MouseEvent &event)
std::vector< std::string > mTextRows
void setCaretPosition(unsigned int position)
void setEditable(const bool editable)
std::string getText() const
void setCaretColumn(const int column)
void setCaretRowColumn(const int row, const int column)
void setOpaque(const Opaque opaque)
void setTextRow(const int row, const std::string &text)
void addRow(const std::string &row)
void setCaretRow(const int row)
void keyPressed(KeyEvent &event)
void setForegroundColor(const Color &color)
void mousePressed(MouseEvent &event)
void drawCaret(Graphics *const graphics, const int x, const int y) const
void setForegroundColorAll(const Color &color1, const Color &color2)
void draw(Graphics *const graphics)
unsigned int getCaretPosition() const
void setText(const std::string &text)
void setTextWrapped(const std::string &text, const int minDimension)
TextBox(const Widget2 *const widget)
PRAGMA45(GCC diagnostic push) PRAGMA45(GCC diagnostic ignored "-Wredundant-decls") PRAGMA45(GCC diagnostic pop) class TestMain
#define BLOCK_START(name)