Skip to content

Commit

Permalink
Shell|libdeng2: More robust management of maximum line width
Browse files Browse the repository at this point in the history
MonospaceLogSinkFormatter, TextRootWidget, and LogWidget now disallow
resizing to a very small / negative width.
  • Loading branch information
skyjake committed Jan 27, 2013
1 parent e82bb87 commit 2ff7a31
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
3 changes: 2 additions & 1 deletion doomsday/libdeng2/src/core/monospacelogsinkformatter.cpp
Expand Up @@ -18,6 +18,7 @@
*/

#include "de/MonospaceLogSinkFormatter"
#include <de/math.h>

namespace de {

Expand Down Expand Up @@ -180,7 +181,7 @@ QList<String> MonospaceLogSinkFormatter::logEntryToTextLines(LogEntry const &ent

void MonospaceLogSinkFormatter::setMaxLength(duint maxLength)
{
_maxLength = maxLength;
_maxLength = de::max(duint(_minimumIndent + 10), maxLength);
}

duint MonospaceLogSinkFormatter::maxLength() const
Expand Down
6 changes: 4 additions & 2 deletions doomsday/tools/shell/libshell/src/textrootwidget.cpp
Expand Up @@ -40,8 +40,10 @@ TextCanvas &TextRootWidget::rootCanvas()

void TextRootWidget::setViewSize(Vector2i const &viewSize)
{
_canvas->resize(viewSize);
RootWidget::setViewSize(viewSize);
// Shouldn't go below 1 x 1.
Vector2i vs = viewSize.max(Vector2i(1, 1));
_canvas->resize(vs);
RootWidget::setViewSize(vs);
}

TextWidget *TextRootWidget::focus() const
Expand Down
13 changes: 7 additions & 6 deletions doomsday/tools/shell/shell-text/src/logwidget.cpp
Expand Up @@ -77,11 +77,11 @@ struct LogWidget::Instance
{
Sink sink;
MonospaceLogSinkFormatter formatter;
QList<TextCanvas *> cache;
int cacheWidth;
QList<TextCanvas *> cache; ///< Indices match entry indices in sink.

Instance(LogWidget &inst) : sink(inst)
{
}
Instance(LogWidget &inst) : sink(inst), cacheWidth(0)
{}

~Instance()
{
Expand Down Expand Up @@ -116,9 +116,10 @@ void LogWidget::draw()
Rectanglei pos = rule().recti();
TextCanvas buf(pos.size());

if(d->formatter.maxLength() != duint(pos.width()))
if(d->cacheWidth != pos.width())
{
d->formatter.setMaxLength(pos.width());
d->cacheWidth = pos.width();
d->formatter.setMaxLength(d->cacheWidth);

// Width has changed, zap the cache.
d->clearCache();
Expand Down

0 comments on commit 2ff7a31

Please sign in to comment.