Skip to content

Commit

Permalink
Refactor|libappfw: Use IAssetGroup for labels and menus
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 19, 2016
1 parent ab187a8 commit d766f5d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
4 changes: 3 additions & 1 deletion doomsday/sdk/libappfw/include/de/widgets/labelwidget.h
Expand Up @@ -68,11 +68,13 @@ class Image;
*
* @ingroup guiWidgets
*/
class LIBAPPFW_PUBLIC LabelWidget : public GuiWidget, public AssetGroup
class LIBAPPFW_PUBLIC LabelWidget : public GuiWidget, public IAssetGroup
{
public:
LabelWidget(String const &name = "");

AssetGroup &assets() override;

void setText(String const &text);
void setImage(Image const &image);

Expand Down
6 changes: 5 additions & 1 deletion doomsday/sdk/libappfw/include/de/widgets/menuwidget.h
Expand Up @@ -29,6 +29,8 @@
#include "../ButtonWidget"
#include "../PanelWidget"

#include <de/Asset>

namespace de {

/**
Expand All @@ -48,13 +50,15 @@ namespace de {
*
* @ingroup guiWidgets
*/
class LIBAPPFW_PUBLIC MenuWidget : public ScrollAreaWidget
class LIBAPPFW_PUBLIC MenuWidget : public ScrollAreaWidget, public IAssetGroup
{
Q_OBJECT

public:
MenuWidget(String const &name = "");

AssetGroup &assets() override;

/**
* Configures the layout grid.
*
Expand Down
12 changes: 9 additions & 3 deletions doomsday/sdk/libappfw/src/widgets/labelwidget.cpp
Expand Up @@ -33,6 +33,7 @@ public Font::RichFormat::IStyle
{
typedef DefaultVertexBuf VertexBuf;

AssetGroup assets;
SizePolicy horizPolicy;
SizePolicy vertPolicy;
AlignmentMode alignMode;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Font::RichFormat::IStyle
updateStyle();

// The readiness of the LabelWidget depends on glText being ready.
self += glText;
assets += glText;
}

~Instance()
Expand Down Expand Up @@ -578,6 +579,11 @@ public Font::RichFormat::IStyle
LabelWidget::LabelWidget(String const &name) : GuiWidget(name), d(new Instance(this))
{}

AssetGroup &LabelWidget::assets()
{
return d->assets;
}

void LabelWidget::setText(String const &text)
{
if(text != d->glText.text())
Expand Down Expand Up @@ -756,11 +762,11 @@ void LabelWidget::update()
bool visibleNow = isVisible();
if(d->wasVisible && !visibleNow)
{
setPolicy(d->glText, Ignore);
d->assets.setPolicy(d->glText, AssetGroup::Ignore);
}
else if(!d->wasVisible && visibleNow)
{
setPolicy(d->glText, Required);
d->assets.setPolicy(d->glText, AssetGroup::Required);
}
d->wasVisible = visibleNow;

Expand Down
20 changes: 18 additions & 2 deletions doomsday/sdk/libappfw/src/widgets/menuwidget.cpp
Expand Up @@ -147,6 +147,7 @@ DENG2_PIMPL(MenuWidget)
ui::SubwidgetItem const &_item;
};

AssetGroup assets;
bool needLayout = false;
GridLayout layout;
ListData defaultItems;
Expand Down Expand Up @@ -219,18 +220,28 @@ DENG2_PIMPL(MenuWidget)
needLayout = true;
}

void widgetChildAdded(Widget &)
void widgetChildAdded(Widget &child)
{
// Make sure we redo the layout with the new child. This occurs
// when filtered items are accepted again as widgets.
needLayout = true;

if(IAssetGroup *asset = child.maybeAs<IAssetGroup>())
{
assets += *asset; // part of the asset group
}
}

void widgetChildRemoved(Widget &)
void widgetChildRemoved(Widget &child)
{
// Make sure we redo the layout without this child. This occurs
// when filtered items are removed from the menu.
needLayout = true;

if(IAssetGroup *asset = child.maybeAs<IAssetGroup>())
{
assets -= *asset; // no longer part of the asset group
}
}

static void setFoldIndicatorForDirection(LabelWidget &label, ui::Direction dir)
Expand Down Expand Up @@ -414,6 +425,11 @@ MenuWidget::MenuWidget(String const &name)
setBehavior(ChildVisibilityClipping, UnsetFlags);
}

AssetGroup &MenuWidget::assets()
{
return d->assets;
}

void MenuWidget::setGridSize(int columns, ui::SizePolicy columnPolicy,
int rows, ui::SizePolicy rowPolicy,
GridLayout::Mode layoutMode)
Expand Down

0 comments on commit d766f5d

Please sign in to comment.