diff options
author | André Nusser <andre.nusser@googlemail.com> | 2017-04-12 22:29:17 +0200 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2017-04-15 20:36:12 +0200 |
commit | 84954cd78d6e0fa8eff24e7a0558f48748e4ba47 (patch) | |
tree | e8d23ab9d21826bbf6ff412638eb08b433554f45 /plugingui/textedit.cc | |
parent | 16c39e953ef0b3df06a7aee6b510de37a2bcc15c (diff) |
Fit text of TextEdit to widget size of resize.
Diffstat (limited to 'plugingui/textedit.cc')
-rw-r--r-- | plugingui/textedit.cc | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/plugingui/textedit.cc b/plugingui/textedit.cc index 9ef21ec..c91b300 100644 --- a/plugingui/textedit.cc +++ b/plugingui/textedit.cc @@ -56,6 +56,12 @@ void TextEdit::resize(std::size_t width, std::size_t height) Widget::resize(width, height); scroll.resize(scroll.width(), height - 14); scroll.move(width - 30, 7); + + // TODO: This might be bad for performance. Improve at some point. + if (adapt_text_on_resize) + { + preprocessText(); + } } void TextEdit::setReadOnly(bool readonly) @@ -92,6 +98,11 @@ std::string TextEdit::text() return _text; } +void TextEdit::adaptTextOnResize(bool adapt) +{ + adapt_text_on_resize = adapt; +} + void TextEdit::preprocessText() { preprocessedtext.clear(); @@ -129,7 +140,7 @@ void TextEdit::preprocessText() for(size_t i = 0; i < line.length(); ++i) { size_t linewidth = font.textWidth(line.substr(0, i)); - if(linewidth >= width() - BORDER - 4 + 3 - 10 - scroll.width()) + if(linewidth >= width() - BORDER - 20 - scroll.width()) { preprocessedtext.push_back(line.substr(0, i)); line = line.substr(i); |