Skip to content

Commit

Permalink
Refactor|UI|Client: Use SequentialLayout in NotificationWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Aug 18, 2013
1 parent 9189fd6 commit 3cb4e99
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
1 change: 1 addition & 0 deletions doomsday/client/include/ui/widgets/scrollareawidget.h
Expand Up @@ -47,6 +47,7 @@ class ScrollAreaWidget : public GuiWidget
void setContentWidth(de::Rule const &width);
void setContentHeight(int height);
void setContentHeight(de::Rule const &height);
void setContentSize(de::Rule const &width, de::Rule const &height);
void setContentSize(de::Vector2i const &size);

void modifyContentWidth(int delta);
Expand Down
3 changes: 1 addition & 2 deletions doomsday/client/src/ui/widgets/aboutdialog.cpp
Expand Up @@ -85,8 +85,7 @@ AboutDialog::AboutDialog() : DialogWidget("about")
.setAnchorPoint(Vector2f(.5f, 0));

// Total size of the dialog's content.
area().setContentWidth(layout.width());
area().setContentHeight(layout.height() + homepage->rule().height());
area().setContentSize(layout.width(), layout.height() + homepage->rule().height());

buttons().items()
<< new DialogButtonItem(DialogWidget::Accept | DialogWidget::Default, tr("Close"));
Expand Down
39 changes: 11 additions & 28 deletions doomsday/client/src/ui/widgets/notificationwidget.cpp
Expand Up @@ -18,6 +18,7 @@

#include "ui/widgets/notificationwidget.h"
#include "ui/widgets/guirootwidget.h"
#include "ui/widgets/sequentiallayout.h"

#include <de/Drawable>
#include <de/Matrix>
Expand Down Expand Up @@ -98,44 +99,26 @@ DENG2_PIMPL(NotificationWidget)
{
Rule const &gap = self.style().rules().rule("unit");

Rule const *totalWidth = 0;
Rule const *totalHeight = 0;
// The children are laid out simply in a row from right to left.
SequentialLayout layout(self.rule().right(), self.rule().top(), ui::Left);

WidgetList const children = self.Widget::children();
for(int i = 0; i < children.size(); ++i)
bool first = true;
foreach(Widget *child, self.childWidgets())
{
GuiWidget &w = children[i]->as<GuiWidget>();

// The children are laid out simply in a row from right to left.
w.rule().setInput(Rule::Top, self.rule().top());
if(i > 0)
{
w.rule().setInput(Rule::Right, children[i - 1]->as<GuiWidget>().rule().left() - gap);
changeRef(totalWidth, *totalWidth + gap + w.rule().width());
}
else
GuiWidget &w = child->as<GuiWidget>();
if(first)
{
w.rule().setInput(Rule::Right, self.rule().right());
totalWidth = holdRef(w.rule().width());
}

if(!totalHeight)
{
totalHeight = holdRef(w.rule().height());
layout << w;
first = false;
}
else
{
changeRef(totalHeight, OperatorRule::maximum(*totalHeight, w.rule().height()));
layout.append(w, gap);
}
}

// Update the total size of the notification area.
self.rule()
.setInput(Rule::Width, *totalWidth)
.setInput(Rule::Height, *totalHeight);

releaseRef(totalWidth);
releaseRef(totalHeight);
self.rule().setSize(layout.width(), layout.height());
}

void show()
Expand Down
7 changes: 7 additions & 0 deletions doomsday/client/src/ui/widgets/scrollareawidget.cpp
Expand Up @@ -185,6 +185,13 @@ void ScrollAreaWidget::setContentHeight(Rule const &height)
d->contentRule.setInput(Rule::Height, height);
}

void ScrollAreaWidget::setContentSize(Rule const &width, Rule const &height)
{
DENG2_GUARD(d);
setContentWidth(width);
setContentHeight(height);
}

void ScrollAreaWidget::setContentSize(Vector2i const &size)
{
DENG2_GUARD(d);
Expand Down
12 changes: 7 additions & 5 deletions doomsday/client/src/ui/widgets/sequentiallayout.cpp
Expand Up @@ -83,17 +83,19 @@ DENG2_PIMPL(SequentialLayout)

void append(GuiWidget *widget, Rule const *spaceBefore)
{
if(spaceBefore)
{
advancePos(*spaceBefore);
}

if(!widget) return;

widgets << widget;

// Override the widget's size as requested.
if(fixedWidth) widget->rule().setInput(Rule::Width, *fixedWidth);
if(fixedHeight) widget->rule().setInput(Rule::Height, *fixedHeight);

if(spaceBefore)
{
advancePos(*spaceBefore);
}

RuleRectangle &rule = widget->rule();

// Update the minor axis.
Expand Down

0 comments on commit 3cb4e99

Please sign in to comment.