From 84954cd78d6e0fa8eff24e7a0558f48748e4ba47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Wed, 12 Apr 2017 22:29:17 +0200 Subject: Fit text of TextEdit to widget size of resize. --- plugingui/textedit.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'plugingui/textedit.cc') 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); -- cgit v1.2.3