summaryrefslogtreecommitdiff
path: root/src/interface/Label.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-07-20 16:43:38 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-07-20 16:43:38 (GMT)
commit22990b680c003c37f531dd9d48619e0c812ee485 (patch)
tree0bd61f7c4c23fd5e645f265533ea8dacbf796215 /src/interface/Label.cpp
parent332fbfe590d29f2bdd375229142bae6f845be6a5 (diff)
downloadpowder-22990b680c003c37f531dd9d48619e0c812ee485.zip
powder-22990b680c003c37f531dd9d48619e0c812ee485.tar.gz
Prevent the multiline update for labels from going out of bounds
Diffstat (limited to 'src/interface/Label.cpp')
-rw-r--r--src/interface/Label.cpp65
1 files changed, 38 insertions, 27 deletions
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp
index 35b2000..76ea45f 100644
--- a/src/interface/Label.cpp
+++ b/src/interface/Label.cpp
@@ -48,40 +48,51 @@ void Label::SetText(std::string text)
void Label::updateMultiline()
{
- char * rawText = new char[text.length()+1];
- std::copy(text.begin(), text.end(), rawText);
- rawText[text.length()] = 0;
-
int lines = 1;
- int currentWidth = 0;
- char * lastSpace = NULL;
- char * currentWord = rawText;
- char * nextSpace;
- while(true)
+ if(text.length()>0)
{
- nextSpace = strchr(currentWord+1, ' ');
- if(nextSpace)
- nextSpace[0] = 0;
- int width = Graphics::textwidth(currentWord);
- if(width+currentWidth > Size.X-6)
+ char * rawText = new char[text.length()+1];
+ std::copy(text.begin(), text.end(), rawText);
+ rawText[text.length()] = 0;
+
+ int currentWidth = 0;
+ char * lastSpace = NULL;
+ char * currentWord = rawText;
+ char * nextSpace;
+ while(true)
{
- currentWidth = width;
- currentWord[0] = '\n';
- lines++;
+ nextSpace = strchr(currentWord+1, ' ');
+ if(nextSpace)
+ nextSpace[0] = 0;
+ int width = Graphics::textwidth(currentWord);
+ if(width+currentWidth > Size.X-6)
+ {
+ currentWidth = width;
+ currentWord[0] = '\n';
+ lines++;
+ }
+ else
+ currentWidth += width;
+ if(nextSpace)
+ nextSpace[0] = ' ';
+ if(!currentWord[0] || !currentWord[1] || !(currentWord = strchr(currentWord+1, ' ')))
+ break;
}
- else
- currentWidth += width;
- if(nextSpace)
- nextSpace[0] = ' ';
- if(!(currentWord = strchr(currentWord+1, ' ')))
- break;
+ if(autoHeight)
+ {
+ Size.Y = lines*12;
+ }
+ textLines = std::string(rawText);
+ delete[] rawText;
}
- if(autoHeight)
+ else
{
- Size.Y = lines*12;
+ if(autoHeight)
+ {
+ Size.Y = 12;
+ }
+ textLines = std::string("");
}
- textLines = std::string(rawText);
- delete[] rawText;
}
std::string Label::GetText()