Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UI|Client: Added Stylist and DialogContentStylist
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
Showing
7 changed files
with
178 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "ui/framework/dialogcontentstylist.h" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
#include "framework/stylist.h" |
51 changes: 51 additions & 0 deletions
51
doomsday/client/include/ui/framework/dialogcontentstylist.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters