diff options
| author | jacob1 <jfu614@gmail.com> | 2012-12-15 18:17:29 (GMT) |
|---|---|---|
| committer | jacob1 <jfu614@gmail.com> | 2012-12-15 18:17:29 (GMT) |
| commit | a172a9689783bed4d1fdfa8887f9f4be881b7076 (patch) | |
| tree | 24d71ba0f0affbd5b8e4f5990486170febd918f5 /src/interface/Label.cpp | |
| parent | e0f8456531bcd77d0d6a93ccd5815c43ca0d548c (diff) | |
| download | powder-a172a9689783bed4d1fdfa8887f9f4be881b7076.zip powder-a172a9689783bed4d1fdfa8887f9f4be881b7076.tar.gz | |
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
Diffstat (limited to 'src/interface/Label.cpp')
| -rw-r--r-- | src/interface/Label.cpp | 42 |
1 files changed, 22 insertions, 20 deletions
diff --git a/src/interface/Label.cpp b/src/interface/Label.cpp index 80387ce..5cd089c 100644 --- a/src/interface/Label.cpp +++ b/src/interface/Label.cpp @@ -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()); |
