Skip to content

Commit

Permalink
Widgets|libcore: Checking for a potential ancestor widget
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Apr 13, 2016
1 parent a4fffde commit 065a50d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions doomsday/sdk/libcore/include/de/widgets/widget.h
Expand Up @@ -223,6 +223,7 @@ class DENG2_PUBLIC Widget
Widget *remove(Widget &child);
Widget *find(String const &name);
bool isInTree(Widget const &child) const;
bool hasAncestor(Widget const &ancestorOrParent) const;
Widget const *find(String const &name) const;
void moveChildBefore(Widget *child, Widget const &otherChild);
void moveChildToLast(Widget &child);
Expand Down
9 changes: 9 additions & 0 deletions doomsday/sdk/libcore/src/widgets/widget.cpp
Expand Up @@ -393,6 +393,15 @@ bool Widget::isInTree(Widget const &child) const
return false;
}

bool Widget::hasAncestor(Widget const &ancestorOrParent) const
{
for(Widget const *iter = parent(); iter; iter = iter->parent())
{
if(iter == &ancestorOrParent) return true;
}
return false;
}

Widget const *Widget::find(String const &name) const
{
return const_cast<Widget *>(this)->find(name);
Expand Down

0 comments on commit 065a50d

Please sign in to comment.