diff --git a/doomsday/client/include/ui/widgets/guiwidget.h b/doomsday/client/include/ui/widgets/guiwidget.h index 5969b7cdf8..b35fd8b9e4 100644 --- a/doomsday/client/include/ui/widgets/guiwidget.h +++ b/doomsday/client/include/ui/widgets/guiwidget.h @@ -24,6 +24,7 @@ #include #include +#include "../uidefs.h" #include "ui/style.h" class GuiRootWidget; @@ -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 diff --git a/doomsday/client/src/ui/widgets/gameselectionwidget.cpp b/doomsday/client/src/ui/widgets/gameselectionwidget.cpp index 191b5575e5..784519d719 100644 --- a/doomsday/client/src/ui/widgets/gameselectionwidget.cpp +++ b/doomsday/client/src/ui/widgets/gameselectionwidget.cpp @@ -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() @@ -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(); diff --git a/doomsday/client/src/ui/widgets/guiwidget.cpp b/doomsday/client/src/ui/widgets/guiwidget.cpp index ef6f2d4b1a..0a09cf3039 100644 --- a/doomsday/client/src/ui/widgets/guiwidget.cpp +++ b/doomsday/client/src/ui/widgets/guiwidget.cpp @@ -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; @@ -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), @@ -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) @@ -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; @@ -365,6 +396,10 @@ float GuiWidget::visibleOpacity() const opacity *= w->d->opacity; } } + + // Disabled widgets are automatically made translucent. + if(isDisabled()) opacity *= .3f; + return opacity; } diff --git a/doomsday/client/src/ui/widgets/labelwidget.cpp b/doomsday/client/src/ui/widgets/labelwidget.cpp index 60329032b7..16cb84b702 100644 --- a/doomsday/client/src/ui/widgets/labelwidget.cpp +++ b/doomsday/client/src/ui/widgets/labelwidget.cpp @@ -50,7 +50,8 @@ public Font::RichFormat::IStyle ConstantRule *height; // Style. - int margin; + Vector2i tlMargin; + Vector2i brMargin; DotPath gapId; int gap; ColorBank::Color highlightColor; @@ -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"); @@ -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; @@ -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)) { @@ -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); } }