Skip to content

Commit

Permalink
UI|Client: Separate margins, opacity for disabled widgets
Browse files Browse the repository at this point in the history
GuiWidget now supports a separate margin rule for each edge of the
rectangle. Presently LabelWidget applies all of them correctly.

The opacity of disabled widgets is now automatically reduced.
  • Loading branch information
skyjake committed Aug 20, 2013
1 parent 3d5cca3 commit 8c3b8fc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 25 deletions.
9 changes: 8 additions & 1 deletion doomsday/client/include/ui/widgets/guiwidget.h
Expand Up @@ -24,6 +24,7 @@
#include <de/GLBuffer>
#include <QObject>

#include "../uidefs.h"
#include "ui/style.h"

class GuiRootWidget;
Expand Down Expand Up @@ -151,12 +152,18 @@ class GuiWidget : public QObject, public de::Widget
void setFont(de::DotPath const &id);
void setTextColor(de::DotPath const &id);
void setMargin(de::DotPath const &id);
void setMargin(ui::Direction dir, de::DotPath const &id);
void setMargins(de::DotPath const &leftId,
de::DotPath const &topId,
de::DotPath const &rightId,
de::DotPath const &bottomId);
void set(Background const &bg);

de::Font const &font() const;
de::ColorBank::Color textColor() const;
de::ColorBank::Colorf textColorf() const;
de::Rule const &margin() const;

de::Rule const &margin(ui::Direction dir = ui::Left) const;

/**
* Determines whether the contents of the widget are supposed to be clipped
Expand Down
13 changes: 2 additions & 11 deletions doomsday/client/src/ui/widgets/gameselectionwidget.cpp
Expand Up @@ -101,7 +101,7 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
b.setAlignment(ui::AlignLeft);
b.setTextLineAlignment(ui::AlignLeft);
b.setHeightPolicy(ui::Expand);
b.setOpacity(.3f, .5f);
b.disable();
}

void appStartupCompleted()
Expand All @@ -118,16 +118,7 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation)
GuiWidget *w = self.organizer().itemWidget(item);
DENG2_ASSERT(w != 0);

if(item.game.allStartupFilesFound())
{
w->setOpacity(1.f, .5f);
w->enable();
}
else
{
w->setOpacity(.3f, .5f);
w->disable();
}
w->enable(item.game.allStartupFilesFound());
}

self.items().sort();
Expand Down
45 changes: 40 additions & 5 deletions doomsday/client/src/ui/widgets/guiwidget.cpp
Expand Up @@ -45,7 +45,10 @@ DENG2_PIMPL(GuiWidget)
// Style.
DotPath fontId;
DotPath textColorId;
DotPath marginId;
DotPath marginLeftId;
DotPath marginTopId;
DotPath marginRightId;
DotPath marginBottomId;

// Background blurring.
bool blurInited;
Expand All @@ -67,7 +70,10 @@ DENG2_PIMPL(GuiWidget)
opacity(1.f, Animation::Linear),
fontId("default"),
textColorId("text"),
marginId("gap"),
marginLeftId("gap"),
marginTopId("gap"),
marginRightId("gap"),
marginBottomId("gap"),
blurInited(false),
uBlurMvpMatrix("uMvpMatrix", GLUniform::Mat4),
uBlurColor ("uColor", GLUniform::Vec4),
Expand Down Expand Up @@ -272,9 +278,13 @@ ColorBank::Colorf GuiWidget::textColorf() const
return style().colors().colorf(d->textColorId);
}

Rule const &GuiWidget::margin() const
Rule const &GuiWidget::margin(ui::Direction dir) const
{
return style().rules().rule(d->marginId);
return style().rules().rule(
dir == ui::Left? d->marginLeftId :
dir == ui::Up? d->marginTopId :
dir == ui::Right? d->marginRightId :
d->marginBottomId);
}

void GuiWidget::setTextColor(DotPath const &id)
Expand All @@ -285,10 +295,31 @@ void GuiWidget::setTextColor(DotPath const &id)

void GuiWidget::setMargin(DotPath const &id)
{
d->marginId = id;
setMargins(id, id, id, id);
}

void GuiWidget::setMargin(ui::Direction dir, DotPath const &id)
{
switch(dir)
{
case ui::Left: d->marginLeftId = id; break;
case ui::Up: d->marginTopId = id; break;
case ui::Right: d->marginRightId = id; break;
case ui::Down: d->marginBottomId = id; break;
default: return;
}
d->styleChanged = true;
}

void GuiWidget::setMargins(DotPath const &leftId, DotPath const &topId, DotPath const &rightId, DotPath const &bottomId)
{
d->marginLeftId = leftId;
d->marginTopId = topId;
d->marginRightId = rightId;
d->marginBottomId = bottomId;
d->styleChanged = true;
}

RuleRectangle &GuiWidget::rule()
{
return d->rule;
Expand Down Expand Up @@ -365,6 +396,10 @@ float GuiWidget::visibleOpacity() const
opacity *= w->d->opacity;
}
}

// Disabled widgets are automatically made translucent.
if(isDisabled()) opacity *= .3f;

return opacity;
}

Expand Down
21 changes: 13 additions & 8 deletions doomsday/client/src/ui/widgets/labelwidget.cpp
Expand Up @@ -50,7 +50,8 @@ public Font::RichFormat::IStyle
ConstantRule *height;

// Style.
int margin;
Vector2i tlMargin;
Vector2i brMargin;
DotPath gapId;
int gap;
ColorBank::Color highlightColor;
Expand Down Expand Up @@ -101,8 +102,12 @@ public Font::RichFormat::IStyle
{
Style const &st = self.style();

margin = self.margin().valuei();
gap = st.rules().rule(gapId).valuei();
tlMargin = Vector2i(self.margin(ui::Left).valuei(),
self.margin(ui::Up).valuei());
brMargin = Vector2i(self.margin(ui::Right).valuei(),
self.margin(ui::Down).valuei());

gap = st.rules().rule(gapId).valuei();

// Colors.
highlightColor = st.colors().color("label.highlight");
Expand Down Expand Up @@ -193,7 +198,7 @@ public Font::RichFormat::IStyle
*/
void contentPlacement(ContentLayout &layout) const
{
Rectanglei const contentRect = self.rule().recti().shrunk(margin);
Rectanglei const contentRect = self.rule().recti().adjusted(tlMargin, -brMargin);

Vector2f const imgSize = imageSize() * imageScale;

Expand Down Expand Up @@ -344,11 +349,11 @@ public Font::RichFormat::IStyle
if(horizPolicy == Expand)
{
// Expansion can occur to full view width.
w = self.root().viewSize().x - 2 * margin;
w = self.root().viewSize().x - (tlMargin.x + brMargin.x);
}
else
{
w = self.rule().width().valuei() - 2 * margin;
w = self.rule().width().valuei() - (tlMargin.x + brMargin.x);
}
if(textAlign & (AlignLeft | AlignRight))
{
Expand Down Expand Up @@ -383,8 +388,8 @@ public Font::RichFormat::IStyle
ContentLayout layout;
contentPlacement(layout);
Rectanglef combined = layout.image | layout.text;
width->set(combined.width() + 2 * margin);
height->set(combined.height() + 2 * margin);
width->set(combined.width() + tlMargin.x + brMargin.x);
height->set(combined.height() + tlMargin.y + brMargin.y);
}
}

Expand Down

0 comments on commit 8c3b8fc

Please sign in to comment.