Skip to content

Commit

Permalink
Client|MenuWidget: Menu items can be hidden and shown
Browse files Browse the repository at this point in the history
Allows menus to be more dynamic in terms of what is displayed.
  • Loading branch information
skyjake committed Jun 20, 2013
1 parent 8fdcc74 commit bd527f7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
3 changes: 2 additions & 1 deletion doomsday/client/include/ui/widgets/menuwidget.h
Expand Up @@ -64,7 +64,8 @@ class MenuWidget : public ScrollAreaWidget
void removeItem(GuiWidget *child);

/**
* Returns the number of items in the menu.
* Returns the number of visible items in the menu. Hidden items are not
* included in this count.
*/
int count() const;

Expand Down
43 changes: 33 additions & 10 deletions doomsday/client/src/ui/widgets/menuwidget.cpp
Expand Up @@ -84,15 +84,30 @@ DENG2_PIMPL(MenuWidget)
return pos;
}

bool isVisibleItem(Widget const *child) const
{
GuiWidget const *widget = dynamic_cast<GuiWidget const *>(child);
return widget && widget->isVisible();
}

int countVisible() const
{
int num = 0;
foreach(Widget *i, self.Widget::children())
{
if(isVisibleItem(i)) ++num;
}
return num;
}

Vector2i countGrid() const
{
Vector2i size;
int ord = 0;

foreach(Widget *i, self.Widget::children())
{
GuiWidget *widget = dynamic_cast<GuiWidget *>(i);
if(widget)
if(isVisibleItem(i))
{
size = size.max(ordinalToGridPos(ord++) + Vector2i(1, 1));
}
Expand All @@ -106,12 +121,11 @@ DENG2_PIMPL(MenuWidget)
int ord = 0;
foreach(Widget *i, self.Widget::children())
{
GuiWidget *widget = dynamic_cast<GuiWidget *>(i);
if(widget)
if(isVisibleItem(i))
{
if(ordinalToGridPos(ord) == Vector2i(col, row))
{
return widget;
return static_cast<GuiWidget *>(i);
}
ord++;
}
Expand All @@ -138,6 +152,7 @@ DENG2_PIMPL(MenuWidget)
releaseRef(old);
}
}
if(!total) return new ConstantRule(0);
return refless(total);
}

Expand All @@ -162,6 +177,7 @@ DENG2_PIMPL(MenuWidget)
releaseRef(old);
}
}
if(!total) return new ConstantRule(0);
return refless(total);
}

Expand All @@ -183,7 +199,7 @@ DENG2_PIMPL(MenuWidget)
releaseRef(old);
}
}
//qDebug() << "totalWidth:\n" << total->description();
if(!total) return new ConstantRule(0);
return refless(total);
}

Expand All @@ -205,7 +221,7 @@ DENG2_PIMPL(MenuWidget)
releaseRef(old);
}
}
//qDebug() << "totalHeight:\n" << total->description();
if(!total) return new ConstantRule(0);
return refless(total);
}
};
Expand Down Expand Up @@ -253,12 +269,12 @@ void MenuWidget::removeItem(GuiWidget *child)

int MenuWidget::count() const
{
return Widget::children().size();
return d->countVisible();
}

void MenuWidget::updateLayout()
{
if(!d->needLayout) return;
//qDebug() << path().toString() << "Menu has" << d->countVisible() << "visible items";

Rule const *baseVert = holdRef(&contentRule().top());

Expand Down Expand Up @@ -368,5 +384,12 @@ Rule const *MenuWidget::newColumnWidthRule(int column) const

void MenuWidget::update()
{
updateLayout();
if(isHidden()) return;

ScrollAreaWidget::update();

if(d->needLayout)
{
updateLayout();
}
}

0 comments on commit bd527f7

Please sign in to comment.