Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@gin0606
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gin0606/90788db9872b4d4378d7 to your computer and use it in GitHub Desktop.
Save gin0606/90788db9872b4d4378d7 to your computer and use it in GitHub Desktop.
CocoStudioで深い階層にあるButtonとかを楽に取得するUtil
//
// Created by gin0606 on 2014/07/07.
//
#include "UIWidget.h"
#ifndef __widget_util_H_
#define __widget_util_H_
class WidgetUtil {
public:
static cocos2d::ui::Widget *getChildByNameRecursively(cocos2d::ui::Widget *rootWidget, const std::string &name) {
if (!rootWidget) {return nullptr;}
if (rootWidget->getName() == name) {return rootWidget;}
for (auto child : rootWidget->getChildren()) {
auto _child = getChildByNameRecursively(dynamic_cast<cocos2d::ui::Widget *>(child), name);
if (_child) {return _child;}
}
return nullptr;
}
template<class T>
static T getChildByNameRecursivelyAs(cocos2d::ui::Widget *rootWidget, std::string name) {
return static_cast<T>(getChildByNameRecursively(rootWidget, name));
}
};
#endif //_widget_util_H_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment