Skip to content

Commit

Permalink
libappfw|MenuWidget: Finding item index based on widget
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 23, 2016
1 parent 499d530 commit 4a4a211
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
10 changes: 10 additions & 0 deletions doomsday/sdk/libappfw/include/de/widgets/menuwidget.h
Expand Up @@ -110,6 +110,16 @@ class LIBAPPFW_PUBLIC MenuWidget : public ScrollAreaWidget, public IAssetGroup
return organizer().itemWidget(item)->as<WidgetType>();
}

template <typename WidgetType>
WidgetType *itemWidget(ui::DataPos itemPos) const {
if(itemPos < items().size()) {
return organizer().itemWidget(items().at(itemPos))->maybeAs<WidgetType>();
}
return nullptr;
}

ui::DataPos findItem(GuiWidget const &widget) const;

/**
* Returns the number of visible items in the menu. Hidden items are not
* included in this count.
Expand Down
9 changes: 9 additions & 0 deletions doomsday/sdk/libappfw/src/widgets/menuwidget.cpp
Expand Up @@ -551,6 +551,15 @@ ChildWidgetOrganizer const &MenuWidget::organizer() const
return d->organizer;
}

ui::DataPos MenuWidget::findItem(GuiWidget const &widget) const
{
if(auto const *item = organizer().findItemForWidget(widget))
{
return items().find(*item);
}
return ui::Data::InvalidPos;
}

void MenuWidget::update()
{
if(d->needLayout)
Expand Down
2 changes: 1 addition & 1 deletion doomsday/sdk/libappfw/src/widgets/scrollareawidget.cpp
Expand Up @@ -499,7 +499,7 @@ void ScrollAreaWidget::scrollToRight(TimeDelta span)
void ScrollAreaWidget::scrollToWidget(GuiWidget const &widget, TimeDelta span)
{
int off = widget.rule().midY().valuei() - contentRule().top().valuei() -
rule().height().valuei()/2;
rule().height().valuei()/2;
scrollY(off, span);
}

Expand Down

0 comments on commit 4a4a211

Please sign in to comment.