Skip to content

Commit

Permalink
Fixed|libappfw|MenuWidget: Take padding into account in layout
Browse files Browse the repository at this point in the history
Also added a helper template method for getting widgets representing
items.
  • Loading branch information
skyjake committed Feb 2, 2014
1 parent 43549b1 commit 8b30915
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions doomsday/libappfw/include/de/widgets/menuwidget.h
Expand Up @@ -94,6 +94,11 @@ class LIBAPPFW_PUBLIC MenuWidget : public ScrollAreaWidget
ChildWidgetOrganizer &organizer();
ChildWidgetOrganizer const &organizer() const;

template <typename WidgetType>
WidgetType &itemWidget(ui::Item const &item) const {
return organizer().itemWidget(item)->as<WidgetType>();
}

/**
* Returns the number of visible items in the menu. Hidden items are not
* included in this count.
Expand Down
6 changes: 4 additions & 2 deletions doomsday/libappfw/src/widgets/menuwidget.cpp
Expand Up @@ -385,13 +385,15 @@ void MenuWidget::setGridSize(int columns, ui::SizePolicy columnPolicy,
if(d->colPolicy == ui::Filled)
{
DENG2_ASSERT(columns > 0);
d->layout.setOverrideWidth((rule().width() - margins().width()) / float(columns));
d->layout.setOverrideWidth((rule().width() - margins().width() -
(columns - 1) * d->layout.columnPadding()) / float(columns));
}

if(d->rowPolicy == ui::Filled)
{
DENG2_ASSERT(rows > 0);
d->layout.setOverrideHeight((rule().height() - margins().height()) / float(rows));
d->layout.setOverrideHeight((rule().height() - margins().height() -
(rows - 1) * d->layout.rowPadding()) / float(rows));
}

d->needLayout = true;
Expand Down

0 comments on commit 8b30915

Please sign in to comment.