Skip to content

Commit

Permalink
Client|LogWidget|FontLineWrapping: Fixed wrapping bug, adjusted log s…
Browse files Browse the repository at this point in the history
…tyle

When checking if the remainder fits on a line, newlines were not taken
into account. Also, reduced the size of the log section font.
  • Loading branch information
skyjake committed May 24, 2013
1 parent 41ecd01 commit b346e78
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
73 changes: 42 additions & 31 deletions doomsday/client/src/ui/widgets/fontlinewrapping.cpp
Expand Up @@ -21,6 +21,8 @@
using namespace de;
using namespace de::shell;

static QChar const NEWLINE('\n');

DENG2_PIMPL_NOREF(FontLineWrapping)
{
Font const *font;
Expand Down Expand Up @@ -85,22 +87,32 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
{
for(int i = range.start; i < range.end; ++i)
{
if(!text.at(i).isSpace()) return false;
if(!text.at(i).isSpace())
return false;
}
return true;
}

bool containsNewline(Rangei const &range) const
{
for(int i = range.start; i < range.end; ++i)
{
if(text.at(i) == NEWLINE)
return true;
}
return false;
}

int findMaxWrapWithStep(int const stepSize, int const begin, int end,
int const availableWidth,
int *wrapPosMax)
{
QChar const newline('\n');
int bestEnd = end;
int stepCounter = stepSize;

if(wrapPosMax) *wrapPosMax = begin + 1;

while(end < text.size() && text.at(end) != newline)
while(end < text.size() && text.at(end) != NEWLINE)
{
++end;

Expand All @@ -114,12 +126,10 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
if(wrapPosMax) *wrapPosMax = --end;
break;
}

// We have verified this fits in the available width.
bestEnd = end;
}
}

return bestEnd;
}

Expand Down Expand Up @@ -164,8 +174,6 @@ void FontLineWrapping::wrapTextToWidth(String const &text, int maxWidth)

void FontLineWrapping::wrapTextToWidth(String const &text, Font::RichFormat const &format, int maxWidth)
{
QChar const newline('\n');

clear();

int const MIN_LINE_WIDTH = 120;
Expand All @@ -189,12 +197,15 @@ void FontLineWrapping::wrapTextToWidth(String const &text, Font::RichFormat cons

// Quick check: does the remainder fit?
Rangei range(begin, text.size());
int visWidth = d->rangeAdvanceWidth(range);
if(visWidth <= availWidth)
if(!d->containsNewline(range))
{
d->lines.append(Instance::Line(WrappedLine(Rangei(begin, text.size())),
visWidth, d->indent));
break;
int visWidth = d->rangeAdvanceWidth(range);
if(visWidth <= availWidth)
{
d->lines.append(Instance::Line(WrappedLine(Rangei(begin, text.size())),
visWidth, d->indent));
break;
}
}

// Newlines always cause a wrap.
Expand All @@ -203,32 +214,32 @@ void FontLineWrapping::wrapTextToWidth(String const &text, Font::RichFormat cons

DENG2_ASSERT(end != text.size());

// Rewind to find a good (whitespace) break point.
while(!text.at(end).isSpace())
{
if(--end == begin)
{
// Ran out of non-space chars, force a break.
end = wrapPosMax;
break;
}
}

// If there is only whitespace remaining on the line,
// just use the max wrap -- blank lines are not pretty.
if(d->isAllSpace(Rangei(begin, end)))
{
end = wrapPosMax;
}

if(text.at(end) == newline)
if(text.at(end) == NEWLINE)
{
// The newline will be omitted from the wrapped lines.
d->appendLine(Rangei(begin, end));
begin = end + 1;
}
else
{
// Rewind to find a good (whitespace) break point.
while(!text.at(end).isSpace())
{
if(--end == begin)
{
// Ran out of non-space chars, force a break.
end = wrapPosMax;
break;
}
}

// If there is only whitespace remaining on the line,
// just use the max wrap -- blank lines are not pretty.
if(d->isAllSpace(Rangei(begin, end)))
{
end = wrapPosMax;
}

while(end < text.size() && text.at(end).isSpace()) ++end;
d->appendLine(Rangei(begin, end));
begin = end;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/client/src/ui/widgets/logwidget.cpp
Expand Up @@ -472,7 +472,8 @@ DENG2_PIMPL(LogWidget), public Font::RichFormat::IStyle
{
// Update the background quad.
bgBuf->setVertices(gl::TriangleStrip,
VertexBuf::Builder().makeQuad(pos, Vector4f(0, 0, 0, .666f),
VertexBuf::Builder().makeQuad(pos,
self.style().colors().colorf("background"),
self.root().atlas().imageRectf(bgTex).middle()),
gl::Static);
}
Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/src/font.cpp
Expand Up @@ -191,7 +191,7 @@ String Font::RichFormat::initFromStyledText(String const &styledText)
break;

case '5': // Log section style
format->sizeFactor = 1.f;
format->sizeFactor = .9f;
format->weight = Light;
format->style = Italic;
format->colorIndex = AccentColor;
Expand Down

0 comments on commit b346e78

Please sign in to comment.