Skip to content

Commit

Permalink
Refactor|UI|ButtonWidget: Buttons have a separate text color for the …
Browse files Browse the repository at this point in the history
…Hover state

This makes life easier for PopupMenuWidget and the FoldPanelWidget
titles look better (the normal button frames were distracting).
  • Loading branch information
skyjake committed Sep 9, 2013
1 parent 1fe5f6d commit 0f9518d
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
1 change: 1 addition & 0 deletions doomsday/client/include/ui/framework/guiwidget.h
Expand Up @@ -182,6 +182,7 @@ class GuiWidget : public QObject, public de::Widget
void set(Background const &bg);

de::Font const &font() const;
de::DotPath const &textColorId() const;
de::ColorBank::Color textColor() const;
de::ColorBank::Colorf textColorf() const;

Expand Down
8 changes: 8 additions & 0 deletions doomsday/client/include/ui/widgets/buttonwidget.h
Expand Up @@ -59,6 +59,14 @@ class ButtonWidget : public LabelWidget
public:
ButtonWidget(de::String const &name = "");

/**
* Text color to use in the Hover state. The default is to use the normal text
* color of the button (label).
*
* @param hoverTextId Style color identifier.
*/
void setHoverTextColor(de::DotPath const &hoverTextId);

/**
* Sets the action of the button. It gets triggered when the button is
* pressed.
Expand Down
5 changes: 5 additions & 0 deletions doomsday/client/src/ui/framework/guiwidget.cpp
Expand Up @@ -295,6 +295,11 @@ Font const &GuiWidget::font() const
return style().fonts().font(d->fontId);
}

DotPath const &GuiWidget::textColorId() const
{
return d->textColorId;
}

void GuiWidget::setFont(DotPath const &id)
{
d->fontId = id;
Expand Down
19 changes: 19 additions & 0 deletions doomsday/client/src/ui/widgets/buttonwidget.cpp
Expand Up @@ -28,6 +28,8 @@ DENG_GUI_PIMPL(ButtonWidget),
DENG2_OBSERVES(Action, Triggered)
{
State state;
DotPath hoverTextColor;
DotPath textColor;
QScopedPointer<Action> action;
Animation scale;
Animation frameOpacity;
Expand Down Expand Up @@ -56,12 +58,24 @@ DENG2_OBSERVES(Action, Triggered)
scale.setValue(1.f, .3f);
scale.setStyle(prev == Down? Animation::Bounce : Animation::EaseOut);
frameOpacity.setValue(.08f, .6f);
if(!hoverTextColor.isEmpty())
{
// Restore old color.
self.setTextColor(textColor);
}
break;

case Hover:
//scale.setValue(1.1f, .15f);
//scale.setStyle(Animation::EaseOut);
frameOpacity.setValue(.4f, .15f);
if(!hoverTextColor.isEmpty())
{
// Remember the old color.
textColor = self.textColorId();

self.setTextColor(hoverTextColor);
}
break;

case Down:
Expand Down Expand Up @@ -137,6 +151,11 @@ DENG2_OBSERVES(Action, Triggered)
ButtonWidget::ButtonWidget(String const &name) : LabelWidget(name), d(new Instance(this))
{}

void ButtonWidget::setHoverTextColor(const DotPath &hoverTextId)
{
d->hoverTextColor = hoverTextId;
}

void ButtonWidget::setAction(Action *action)
{
if(!d->action.isNull())
Expand Down
7 changes: 4 additions & 3 deletions doomsday/client/src/ui/widgets/foldpanelwidget.cpp
Expand Up @@ -71,10 +71,11 @@ FoldPanelWidget::FoldPanelWidget(String const &name) : PanelWidget(name), d(new
{
d->title = new ButtonWidget;
d->title->setSizePolicy(Expand, Expand);
d->title->set(d->title->background().withSolidFill(Vector4f()));
d->title->set(Background()); // no frame or background
d->title->setHoverTextColor("text");
d->title->setFont("heading");
d->title->setAction(new SignalAction(this, SLOT(toggleFold())));
d->title->setOpacity(.7f);
d->title->setOpacity(.8f);

// Icon is disabled for now, doesn't look quite right.
//d->title->setImage(new Instance::FoldImage(*this));
Expand Down Expand Up @@ -134,7 +135,7 @@ void FoldPanelWidget::panelDismissed()
{
PanelWidget::panelDismissed();

d->title->setOpacity(.7f, .5f);
d->title->setOpacity(.8f, .5f);

content().notifySelfAndTree(&Widget::deinitialize);

Expand Down
11 changes: 1 addition & 10 deletions doomsday/client/src/ui/widgets/popupmenuwidget.cpp
Expand Up @@ -53,6 +53,7 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetUpdate)
// gets triggered.
if(ButtonWidget *b = widget.maybeAs<ButtonWidget>())
{
b->setHoverTextColor("inverted.text");
b->setSizePolicy(ui::Expand, ui::Expand);
b->margins().set("unit");

Expand Down Expand Up @@ -110,16 +111,6 @@ DENG2_OBSERVES(ContextWidgetOrganizer, WidgetUpdate)

void buttonStateChanged(ButtonWidget &button, ButtonWidget::State state)
{
// Update button style.
if(state == ButtonWidget::Up)
{
button.setTextColor("text");
}
else
{
button.setTextColor("inverted.text");
}

// Position item highlight.
if(&button == hover && state == ButtonWidget::Up)
{
Expand Down

0 comments on commit 0f9518d

Please sign in to comment.