make sure long amounts of text without spaces doesn't run over out of bounds

A character may be deleted to insert a new line, but when copying something like a url, the missing one is copied back in. I couldn't get inserting a newline between letters to work right
This commit is contained in:
jacob1 2012-12-15 13:17:29 -05:00
parent e0f8456531
commit a172a96897
2 changed files with 23 additions and 21 deletions

View File

@ -96,23 +96,30 @@ void Label::updateMultiline()
lines++;
break;
default:
if(pc == ' ')
{
wordStart = &rawText[charIndex-2];
}
wordWidth += Graphics::CharWidth(c);
if(lineWidth + wordWidth >= Size.X-(Appearance.Margin.Left+Appearance.Margin.Right))
{
if(wordStart && *wordStart)
*wordStart = '\n';
else if(!wordStart)
rawText[charIndex-1] = '\n';
lineWidth = wordWidth;
wordWidth = 0;
lines++;
}
break;
}
if(pc == ' ')
{
wordStart = &rawText[charIndex-2];
}
if ((c != ' ' || pc == ' ') && lineWidth + wordWidth >= Size.X-(Appearance.Margin.Left+Appearance.Margin.Right))
{
if(wordStart && *wordStart)
{
*wordStart = '\n';
if (lineWidth != 0)
lineWidth = wordWidth;
}
else if(!wordStart)
{
rawText[charIndex-1] = '\n';
lineWidth = 0;
}
wordWidth = 0;
wordStart = 0;
lines++;
}
pc = c;
}
if(autoHeight)
@ -201,12 +208,7 @@ void Label::OnMouseClick(int x, int y, unsigned button)
void Label::copySelection()
{
std::string currentText;
if(multiline)
currentText = textLines;
else
currentText = text;
std::string currentText = text;
if(selectionIndex1 > selectionIndex0) {
clipboard_push_text((char*)currentText.substr(selectionIndex0, selectionIndex1-selectionIndex0).c_str());

View File

@ -447,7 +447,7 @@ void Textbox::OnVKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
backingText.erase(backingText.begin());
}
if(cursor > backingText.length())
cursor = backingText.length();
cursor = backingText.length();
if(changed)
{
if(masked)