Skip to content

Commit

Permalink
UI|Client: Added Stylist and DialogContentStylist
Browse files Browse the repository at this point in the history
A Stylist is an object that configures widgets with a particular
context in mind. DialogContentStylist adjusts margins and backgrounds
for widgets in a dialog.
  • Loading branch information
skyjake committed Sep 4, 2013
1 parent 4440644 commit 5dad337
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 25 deletions.
5 changes: 5 additions & 0 deletions doomsday/client/client.pro
Expand Up @@ -119,6 +119,7 @@ DENG_CONVENIENCE_HEADERS += \
include/BspNode \
include/CommandAction \
include/ContextWidgetOrganizer \
include/DialogContentStylist \
include/EntityDatabase \
include/Face \
include/FontLineWrapping \
Expand Down Expand Up @@ -164,6 +165,7 @@ DENG_CONVENIENCE_HEADERS += \
include/ui/Item \
include/ui/ListData \
include/ui/Margins \
include/ui/Stylist \
include/ui/SubmenuItem \
include/ui/VariableToggleItem \
include/Vertex \
Expand Down Expand Up @@ -365,6 +367,7 @@ DENG_HEADERS += \
include/ui/framework/commandaction.h \
include/ui/framework/contextwidgetorganizer.h \
include/ui/framework/data.h \
include/ui/framework/dialogcontentstylist.h \
include/ui/framework/fontlinewrapping.h \
include/ui/framework/gltextcomposer.h \
include/ui/framework/gridlayout.h \
Expand All @@ -377,6 +380,7 @@ DENG_HEADERS += \
include/ui/framework/proceduralimage.h \
include/ui/framework/sequentiallayout.h \
include/ui/framework/signalaction.h \
include/ui/framework/stylist.h \
include/ui/framework/submenuitem.h \
include/ui/framework/textdrawable.h \
include/ui/framework/variabletoggleitem.h \
Expand Down Expand Up @@ -696,6 +700,7 @@ SOURCES += \
src/ui/framework/commandaction.cpp \
src/ui/framework/contextwidgetorganizer.cpp \
src/ui/framework/data.cpp \
src/ui/framework/dialogcontentstylist.cpp \
src/ui/framework/fontlinewrapping.cpp \
src/ui/framework/gltextcomposer.cpp \
src/ui/framework/gridlayout.cpp \
Expand Down
1 change: 1 addition & 0 deletions doomsday/client/include/DialogContentStylist
@@ -0,0 +1 @@
#include "ui/framework/dialogcontentstylist.h"
1 change: 1 addition & 0 deletions doomsday/client/include/ui/Stylist
@@ -0,0 +1 @@
#include "framework/stylist.h"
51 changes: 51 additions & 0 deletions doomsday/client/include/ui/framework/dialogcontentstylist.h
@@ -0,0 +1,51 @@
/** @file dialogcontentstylist.h Sets the style for widgets in a dialog.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_DIALOGCONTENTSTYLIST_H
#define DENG_CLIENT_DIALOGCONTENTSTYLIST_H

#include "ui/Stylist"
#include <de/Widget>

class DialogWidget;

/**
* Sets the style for widgets in a dialog.
*/
class DialogContentStylist : public ui::Stylist,
DENG2_OBSERVES(de::Widget, ChildAddition)
{
public:
DialogContentStylist();
DialogContentStylist(DialogWidget &dialog);
DialogContentStylist(GuiWidget &container);

~DialogContentStylist();

void setContainer(GuiWidget &container);

void applyStyle(GuiWidget &widget);

// Observes when new children are added.
void widgetChildAdded(de::Widget &child);

private:
GuiWidget *_container;
};

#endif // DENG_CLIENT_DIALOGCONTENTSTYLIST_H
39 changes: 39 additions & 0 deletions doomsday/client/include/ui/framework/stylist.h
@@ -0,0 +1,39 @@
/** @file stylist.h Widget stylist.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#ifndef DENG_CLIENT_UI_STYLIST_H
#define DENG_CLIENT_UI_STYLIST_H

class GuiWidget;

namespace ui {

/**
* Widget stylist.
*/
class Stylist
{
public:
virtual ~Stylist() {}

virtual void applyStyle(GuiWidget &widget) = 0;
};

} // namespace ui

#endif // DENG_CLIENT_UI_STYLIST_H
78 changes: 78 additions & 0 deletions doomsday/client/src/ui/framework/dialogcontentstylist.cpp
@@ -0,0 +1,78 @@
/** @file dialogcontentstylist.cpp Sets the style for widgets in a dialog.
*
* @authors Copyright (c) 2013 Jaakko Keränen <jaakko.keranen@iki.fi>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. This program is distributed in the hope that it
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/

#include "DialogContentStylist"
#include "ui/widgets/dialogwidget.h"
#include "ui/widgets/togglewidget.h"
#include "ui/widgets/labelwidget.h"

using namespace de;

DialogContentStylist::DialogContentStylist() : _container(0)
{}

DialogContentStylist::DialogContentStylist(DialogWidget &dialog) : _container(0)
{
setContainer(dialog.area());
}

DialogContentStylist::DialogContentStylist(GuiWidget &container) : _container(0)
{
setContainer(container);
}

DialogContentStylist::~DialogContentStylist()
{
if(_container)
{
_container->audienceForChildAddition -= this;
}
}

void DialogContentStylist::setContainer(GuiWidget &container)
{
if(_container)
{
_container->audienceForChildAddition -= this;
}

_container = &container;
_container->audienceForChildAddition += this;
}

void DialogContentStylist::widgetChildAdded(Widget &child)
{
applyStyle(child.as<GuiWidget>());
}

void DialogContentStylist::applyStyle(GuiWidget &w)
{
w.margins().set("dialog.gap");

// All label-based widgets should expand on their own.
if(LabelWidget *lab = w.maybeAs<LabelWidget>())
{
lab->setSizePolicy(ui::Expand, ui::Expand);
}

// Toggles should have no background.
if(ToggleWidget *tog = w.maybeAs<ToggleWidget>())
{
tog->set(GuiWidget::Background());
}
}
28 changes: 3 additions & 25 deletions doomsday/client/src/ui/widgets/dialogwidget.cpp
Expand Up @@ -21,6 +21,7 @@
#include "ui/widgets/choicewidget.h"
#include "GuiRootWidget"
#include "SignalAction"
#include "DialogContentStylist"
#include "dd_main.h"

#include <de/KeyEvent>
Expand Down Expand Up @@ -78,7 +79,6 @@ static bool dialogButtonOrder(ui::Item const &a, ui::Item const &b)
DENG_GUI_PIMPL(DialogWidget),
DENG2_OBSERVES(ContextWidgetOrganizer, WidgetCreation),
DENG2_OBSERVES(ContextWidgetOrganizer, WidgetUpdate),
DENG2_OBSERVES(Widget, ChildAddition), // for styling the contents
DENG2_OBSERVES(ui::Data, Addition),
DENG2_OBSERVES(ui::Data, Removal)
{
Expand All @@ -92,6 +92,7 @@ DENG2_OBSERVES(ui::Data, Removal)
bool needButtonUpdate;
float normalGlow;
bool animatingGlow;
DialogContentStylist stylist;

Instance(Public *i, Flags const &dialogFlags)
: Base(i),
Expand All @@ -110,7 +111,6 @@ DENG2_OBSERVES(ui::Data, Removal)
GuiWidget *container = new GuiWidget("container");

area = new ScrollAreaWidget("area");
area->audienceForChildAddition += this;

buttons = new MenuWidget("buttons");
buttons->items().audienceForAddition += this;
Expand Down Expand Up @@ -303,29 +303,6 @@ DENG2_OBSERVES(ui::Data, Removal)
}
}

/**
* Applies the default dialog style for child widgets added to
* the content area.
*/
void widgetChildAdded(Widget &areaChild)
{
GuiWidget &w = areaChild.as<GuiWidget>();

w.margins().set("dialog.gap");

// All label-based widgets should expand on their own.
if(LabelWidget *lab = w.maybeAs<LabelWidget>())
{
lab->setSizePolicy(ui::Expand, ui::Expand);
}

// Toggles should have no background.
if(ToggleWidget *tog = w.maybeAs<ToggleWidget>())
{
tog->set(Background());
}
}

ui::ActionItem const *findDefaultAction() const
{
for(ui::Data::Pos i = 0; i < buttons->items().size(); ++i)
Expand Down Expand Up @@ -384,6 +361,7 @@ DENG2_OBSERVES(ui::Data, Removal)
DialogWidget::DialogWidget(String const &name, Flags const &flags)
: PopupWidget(name), d(new Instance(this, flags))
{
d->stylist.setContainer(area());
setOpeningDirection(ui::NoDirection);
d->updateBackground();
}
Expand Down

0 comments on commit 5dad337

Please sign in to comment.