Skip to content

Commit

Permalink
UI|Client: Popup nesting level affects appearance
Browse files Browse the repository at this point in the history
Deeply nested popups should be opaque to avoid visual clutter.
  • Loading branch information
skyjake committed Sep 12, 2013
1 parent df6096a commit 25f4b5c
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 10 deletions.
1 change: 1 addition & 0 deletions doomsday/client/include/ui/framework/margins.h
Expand Up @@ -51,6 +51,7 @@ class Margins
void setBottom(de::Rule const &rule);
void set (ui::Direction dir, de::Rule const &rule);
void set (de::Rule const &rule);
void setAll (Margins const &margins);

de::Rule const &left() const;
de::Rule const &right() const;
Expand Down
9 changes: 9 additions & 0 deletions doomsday/client/include/ui/widgets/popupwidget.h
Expand Up @@ -35,6 +35,14 @@ class PopupWidget : public PanelWidget
public:
PopupWidget(de::String const &name = "");

/**
* Determines how deeply nested this popup is within parent popups.
*
* @return 0, if parents include no other popups. Otherwise +1 for each popup
* present in the parents (i.e., number of popups among ancestors).
*/
int levelOfNesting() const;

void setAnchorAndOpeningDirection(de::RuleRectangle const &rule, ui::Direction dir);

void setAnchor(de::Vector2i const &pos);
Expand Down Expand Up @@ -74,6 +82,7 @@ class PopupWidget : public PanelWidget

protected:
void glMakeGeometry(DefaultVertexBuf::Builder &verts);
void updateStyle();

virtual void preparePanelForOpening();
virtual void panelDismissed();
Expand Down
10 changes: 10 additions & 0 deletions doomsday/client/src/ui/framework/margins.cpp
Expand Up @@ -174,6 +174,16 @@ void Margins::set(Rule const &rule)
set(Down, rule);
}

void Margins::setAll(Margins const &margins)
{
if(this == &margins) return;

set(Left, margins.left());
set(Right, margins.right());
set(Up, margins.top());
set(Down, margins.bottom());
}

void Margins::setLeft(Rule const &rule)
{
set(ui::Left, rule);
Expand Down
63 changes: 53 additions & 10 deletions doomsday/client/src/ui/widgets/popupwidget.cpp
Expand Up @@ -34,6 +34,7 @@ static TimeDelta const CLOSING_ANIM_SPAN = 0.3;

DENG_GUI_PIMPL(PopupWidget)
{
bool useInfoStyle;
bool deleteAfterDismiss;
bool clickToClose;
Widget *realParent;
Expand All @@ -43,6 +44,7 @@ DENG_GUI_PIMPL(PopupWidget)

Instance(Public *i)
: Base(i),
useInfoStyle(false),
deleteAfterDismiss(false),
clickToClose(true),
realParent(0),
Expand Down Expand Up @@ -110,18 +112,51 @@ DENG_GUI_PIMPL(PopupWidget)
break;
}
}

void updateStyle()
{
Style const &st = style();

if(useInfoStyle)
{
self.set(Background(st.colors().colorf("popup.info.background"),
Background::BorderGlow,
st.colors().colorf("popup.info.glow"),
st.rules().rule("glow").valuei()));
}
else
{
self.set(Background(st.colors().colorf("background"),
Background::BorderGlow,
st.colors().colorf("glow"),
st.rules().rule("glow").valuei()));
}

if(self.levelOfNesting() > 0)
{
// If nested, use an opaque background.
self.set(self.background().withSolidFillOpacity(1));
}
}
};

PopupWidget::PopupWidget(String const &name) : PanelWidget(name), d(new Instance(this))
{
setOpeningDirection(ui::Up);
d->updateStyle();
}

/// @todo Move these to an updateStyle.
Style const &st = style();
set(Background(st.colors().colorf("background"),
Background::BorderGlow,
st.colors().colorf("glow"),
st.rules().rule("glow").valuei()));
int PopupWidget::levelOfNesting() const
{
int nesting = 0;
for(Widget const *p = d->realParent? d->realParent : parentWidget(); p; p = p->parent())
{
if(p->is<PopupWidget>())
{
++nesting;
}
}
return nesting;
}

void PopupWidget::setAnchorAndOpeningDirection(RuleRectangle const &rule, ui::Direction dir)
Expand Down Expand Up @@ -201,10 +236,8 @@ void PopupWidget::setClickToClose(bool clickCloses)

void PopupWidget::useInfoStyle()
{
set(Background(style().colors().colorf("popup.info.background"),
Background::BorderGlow,
style().colors().colorf("popup.info.glow"),
style().rules().rule("glow").valuei()));
d->useInfoStyle = true;
d->updateStyle();
}

bool PopupWidget::handleEvent(Event const &event)
Expand Down Expand Up @@ -295,8 +328,17 @@ void PopupWidget::glMakeGeometry(DefaultVertexBuf::Builder &verts)
verts += tri;
}

void PopupWidget::updateStyle()
{
PanelWidget::updateStyle();

d->updateStyle();
}

void PopupWidget::preparePanelForOpening()
{
d->updateStyle();

PanelWidget::preparePanelForOpening();

// Reparent the popup into the root widget, on top of everything else.
Expand All @@ -314,6 +356,7 @@ void PopupWidget::panelDismissed()
// Move back to the original parent widget.
root().remove(*this);
d->realParent->add(this);
d->realParent = 0;

if(d->deleteAfterDismiss)
{
Expand Down

0 comments on commit 25f4b5c

Please sign in to comment.