Skip to content

Commit

Permalink
libgui|Client: Improved handling of indents in text drawing
Browse files Browse the repository at this point in the history
Indents can be marked and reseted individually.
  • Loading branch information
skyjake committed Jan 28, 2014
1 parent f55148a commit 9dcb32d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions doomsday/libappfw/src/fontlinewrapping.cpp
Expand Up @@ -67,6 +67,7 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
String text; ///< Plain text.
Font::RichFormat format;
int indent; ///< Current left indentation (in pixels).
QList<int> prevIndents;
int tabStop;

Instance() : font(0), maxWidth(0), indent(0), tabStop(0) {}
Expand Down Expand Up @@ -105,24 +106,32 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
return 0;
}

int rangeIndentMarkWidth(Rangei const &range) const
void updateIndentMarkWidth(Rangei const &range)
{
Font::RichFormatRef rich = format.subRange(range);
Font::RichFormat::Iterator iter(rich);
int markWidth = 0;
int const origIndent = indent;
while(iter.hasNext())
{
iter.next();
if(iter.markIndent())
{
markWidth = rangeAdvanceWidth(Rangei(0, iter.range().start) + range.start);
prevIndents.append(indent);
indent = origIndent + rangeAdvanceWidth(Rangei(0, iter.range().start) + range.start);
}

if(iter.resetIndent())
{
markWidth = -indent;
if(!prevIndents.isEmpty())
{
indent = prevIndents.takeLast();
}
else
{
indent = 0;
}
}
}
return markWidth;
}

/**
Expand Down Expand Up @@ -186,7 +195,7 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
}

// Check for possible indent for following lines.
indent += rangeIndentMarkWidth(range);
updateIndentMarkWidth(range);

return line;
}
Expand Down Expand Up @@ -288,7 +297,7 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
Lines wrapRange(Rangei const &rangeToWrap, int maxWidth, int subsequentMaxWidth = 0,
int initialIndent = 0)
{
int const MIN_LINE_WIDTH = 120;
int const MIN_LINE_WIDTH = 150;
bool const isTabbed = (subsequentMaxWidth > 0);

indent = initialIndent;
Expand All @@ -307,8 +316,15 @@ DENG2_PIMPL_NOREF(FontLineWrapping)
if(!isTabbed)
{
// Regular non-tabbed line -- there is no room for this indent,
// so reduce it.
indent = de::max(0, mw - MIN_LINE_WIDTH);
// fall back to the previous one.
if(prevIndents.isEmpty())
{
indent = 0;
}
else
{
indent = prevIndents.last();
}
}
else
{
Expand Down Expand Up @@ -520,6 +536,7 @@ void FontLineWrapping::reset()

d->clearLines();
d->indent = 0;
d->prevIndents.clear();
d->tabStop = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion doomsday/libgui/src/font_richformat.cpp
Expand Up @@ -114,12 +114,12 @@ DENG2_OBSERVES(EscapeParser, EscapeSequence)
Format form = stack.takeLast();
stack.last().tabStop = form.tabStop; // Retain tab stop.
stack.last().markIndent = form.markIndent;
//stack.last().resetIndent = form.resetIndent;
}
break;

case '>':
stack.last().markIndent = true;
handlePlainText(Rangei(0, 0));
break;

case '<':
Expand Down

0 comments on commit 9dcb32d

Please sign in to comment.