Skip to content

Commit

Permalink
Fixed|libappfw|DocumentWidget: Document contents not updated for drawing
Browse files Browse the repository at this point in the history
Fixes the issue where the autocompletion popup would sometimes refuse
to show anything (zero content size). The problem was that
DocumentWidget gave up on the TextDrawable before it had finished
wrapping the text.

Also applied some general cleanup in DocumentWidget.
  • Loading branch information
skyjake committed Dec 6, 2014
1 parent 487a3fc commit 83a030d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 34 deletions.
2 changes: 0 additions & 2 deletions doomsday/libappfw/include/de/widgets/documentwidget.h
Expand Up @@ -74,9 +74,7 @@ class LIBAPPFW_PUBLIC DocumentWidget : public ScrollAreaWidget

// Events.
void viewResized();
void update();
void drawContent();
bool handleEvent(Event const &event);

protected:
void glInit();
Expand Down
50 changes: 18 additions & 32 deletions doomsday/libappfw/src/widgets/documentwidget.cpp
Expand Up @@ -32,7 +32,7 @@ public Font::RichFormat::IStyle
{
typedef DefaultVertexBuf VertexBuf;

ProgressWidget *progress;
ProgressWidget *progress = nullptr;

// Style.
ColorBank::Color normalColor;
Expand All @@ -42,30 +42,22 @@ public Font::RichFormat::IStyle
ColorBank::Color dimAccentColor;

// State.
ui::SizePolicy widthPolicy;
int maxLineWidth;
int oldScrollY;
ui::SizePolicy widthPolicy = ui::Expand;
int maxLineWidth = 1000;
int oldScrollY = 0;
String styledText;
String text;

// GL objects.
TextDrawable glText;
Drawable drawable;
Matrix4f modelMatrix;
GLUniform uMvpMatrix;
GLUniform uScrollMvpMatrix;
GLUniform uColor;
GLState clippedTextState;
GLUniform uMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };
GLUniform uScrollMvpMatrix { "uMvpMatrix", GLUniform::Mat4 };
GLUniform uColor { "uColor", GLUniform::Vec4 };

Instance(Public *i)
: Base(i)
, progress(0)
, widthPolicy(ui::Expand)
, maxLineWidth(1000)
, oldScrollY(0)
, uMvpMatrix ("uMvpMatrix", GLUniform::Mat4)
, uScrollMvpMatrix("uMvpMatrix", GLUniform::Mat4)
, uColor ("uColor", GLUniform::Vec4)
Instance(Public *i) : Base(i)
{
updateStyle();

Expand Down Expand Up @@ -190,8 +182,8 @@ public Font::RichFormat::IStyle
glText.setLineWrapWidth(wrapWidth);
if(glText.update())
{
// Text is ready for drawing.
if(progress->isVisible())
// Text is ready for drawing?
if(!glText.isBeingWrapped() && progress->isVisible())
{
self.setContentSize(glText.wrappedSize());
progress->hide();
Expand All @@ -215,11 +207,11 @@ public Font::RichFormat::IStyle
DENG2_ASSERT(glText.isReady());

// Determine visible range of lines.
Font const &font = self.font();
int contentHeight = self.contentHeight();
Font const &font = self.font();
int contentHeight = self.contentHeight();
int const extraLines = 1;
int numVisLines = contentHeight / font.lineSpacing().valuei() + 2 * extraLines;
int firstVisLine = scrollY / font.lineSpacing().valuei() - extraLines + 1;
int numVisLines = contentHeight / font.lineSpacing().valuei() + 2 * extraLines;
int firstVisLine = scrollY / font.lineSpacing().valuei() - extraLines + 1;

// Update visible range and release/alloc lines accordingly.
Rangei visRange(firstVisLine, firstVisLine + numVisLines);
Expand Down Expand Up @@ -276,6 +268,7 @@ void DocumentWidget::setText(String const &styledText)
}

d->progress->show();

int indSize = style().rules().rule("document.progress").valuei();
setContentSize(Vector2i(indSize, indSize));

Expand Down Expand Up @@ -319,28 +312,20 @@ void DocumentWidget::viewResized()
requestGeometry();
}

void DocumentWidget::update()
{
ScrollAreaWidget::update();
}

void DocumentWidget::drawContent()
{
d->draw();
}

bool DocumentWidget::handleEvent(Event const &event)
{
return ScrollAreaWidget::handleEvent(event);
}

void DocumentWidget::glInit()
{
ScrollAreaWidget::glInit();
d->glInit();
}

void DocumentWidget::glDeinit()
{
ScrollAreaWidget::glDeinit();
d->glDeinit();
}

Expand All @@ -354,6 +339,7 @@ void DocumentWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)

void DocumentWidget::updateStyle()
{
ScrollAreaWidget::updateStyle();
d->updateStyle();
}

Expand Down

0 comments on commit 83a030d

Please sign in to comment.