Skip to content

Commit

Permalink
libdeng2|Widget: Partial tree traversal
Browse files Browse the repository at this point in the history
Made it possible for Widget::notifyTree() to abort the traversal
when encountering a specific widget.

Todo: Collect all the arguments into a single NotifyArgs struct so
it can be passed more conveniently to child widgets.
  • Loading branch information
skyjake committed Jun 11, 2013
1 parent ff61400 commit dac008a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
13 changes: 9 additions & 4 deletions doomsday/libdeng2/include/de/widgets/widget.h
Expand Up @@ -148,10 +148,15 @@ class DENG2_PUBLIC Widget

// Utilities.
String uniqueName(String const &name) const;
void notifyTree(void (Widget::*notifyFunc)(),
bool (Widget::*conditionFunc)() const = 0,
void (Widget::*preNotifyFunc)() = 0,
void (Widget::*postNotifyFunc)() = 0);
enum NotifyResult {
AbortNotify,
ContinueNotify
};
NotifyResult notifyTree(void (Widget::*notifyFunc)(),
bool (Widget::*conditionFunc)() const = 0,
void (Widget::*preNotifyFunc)() = 0,
void (Widget::*postNotifyFunc)() = 0,
Widget *until = 0);
void notifyTreeReversed(void (Widget::*notifyFunc)(),
bool (Widget::*conditionFunc)() const = 0,
void (Widget::*preNotifyFunc)() = 0,
Expand Down
22 changes: 17 additions & 5 deletions doomsday/libdeng2/src/widgets/widget.cpp
Expand Up @@ -275,10 +275,11 @@ String Widget::uniqueName(String const &name) const
return String("#%1.%2").arg(id().asInt64()).arg(name);
}

void Widget::notifyTree(void (Widget::*notifyFunc)(),
bool (Widget::*conditionFunc)() const,
void (Widget::*preFunc)(),
void (Widget::*postFunc)())
Widget::NotifyResult Widget::notifyTree(void (Widget::*notifyFunc)(),
bool (Widget::*conditionFunc)() const,
void (Widget::*preFunc)(),
void (Widget::*postFunc)(),
Widget *until)
{
if(preFunc)
{
Expand All @@ -287,17 +288,28 @@ void Widget::notifyTree(void (Widget::*notifyFunc)(),

DENG2_FOR_EACH(Instance::Children, i, d->children)
{
if(*i == until)
{
return AbortNotify;
}

if(conditionFunc && !((*i)->*conditionFunc)())
continue; // Skip this one.

((*i)->*notifyFunc)();
(*i)->notifyTree(notifyFunc, conditionFunc, preFunc, postFunc);

if((*i)->notifyTree(notifyFunc, conditionFunc, preFunc, postFunc, until) == AbortNotify)
{
return AbortNotify;
}
}

if(postFunc)
{
(this->*postFunc)();
}

return ContinueNotify;
}

void Widget::notifyTreeReversed(void (Widget::*notifyFunc)(),
Expand Down

0 comments on commit dac008a

Please sign in to comment.