fix ListView addChild problem

This commit is contained in:
andyque 2014-06-25 16:17:16 +08:00
parent e90e7699a6
commit a4bd3879ac
8 changed files with 51 additions and 21 deletions

View File

@ -152,6 +152,16 @@ bool Layout::init()
}
return false;
}
void Layout::addChild(Node* child)
{
Layout::addChild(child, child->getLocalZOrder(), child->getTag());
}
void Layout::addChild(Node * child, int localZOrder)
{
Layout::addChild(child, localZOrder, child->getTag());
}
void Layout::addChild(Node *child, int zOrder, int tag)
{

View File

@ -232,7 +232,6 @@ public:
virtual Type getLayoutType() const;
using Node::addChild;
/**
* Adds a child to the container with z order and tag
*
@ -242,6 +241,8 @@ public:
* @param zOrder Z order for drawing priority. Please refer to setLocalZOrder(int)
* @param tag A interger to identify the node easily. Please refer to setTag(int)
*/
virtual void addChild(Node* child)override;
virtual void addChild(Node * child, int localZOrder)override;
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void addChild(Node* child, int zOrder, const std::string &name) override;

View File

@ -272,6 +272,7 @@ void ListView::insertDefaultItem(ssize_t index)
_refreshViewDirty = true;
}
void ListView::pushBackCustomItem(Widget* item)
{
remedyLayoutParameter(item);
@ -289,6 +290,16 @@ void ListView::addChild(cocos2d::Node *child, int zOrder, int tag)
_items.pushBack(widget);
}
}
void ListView::addChild(cocos2d::Node *child)
{
ListView::addChild(child, child->getLocalZOrder(), child->getName());
}
void ListView::addChild(cocos2d::Node *child, int zOrder)
{
ListView::addChild(child, zOrder, child->getName());
}
void ListView::addChild(Node* child, int zOrder, const std::string &name)
{

View File

@ -163,7 +163,8 @@ public:
virtual void doLayout() override;
using ScrollView::addChild;
virtual void addChild(Node* child)override;
virtual void addChild(Node * child, int localZOrder)override;
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
virtual void removeAllChildren() override;

View File

@ -229,6 +229,16 @@ const Size& ScrollView::getInnerContainerSize() const
{
return _innerContainer->getContentSize();
}
void ScrollView::addChild(Node* child)
{
ScrollView::addChild(child, child->getLocalZOrder(), child->getTag());
}
void ScrollView::addChild(Node * child, int localZOrder)
{
ScrollView::addChild(child, localZOrder, child->getTag());
}
void ScrollView::addChild(Node *child, int zOrder, int tag)
{

View File

@ -254,12 +254,15 @@ public:
virtual void addEventListener(const ccScrollViewCallback& callback);
//all of these functions are related to innerContainer.
using Layout::addChild;
virtual void addChild(Node* child)override;
virtual void addChild(Node * child, int localZOrder)override;
virtual void addChild(Node* child, int zOrder, int tag) override;
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
virtual void removeAllChildren() override;
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
virtual void removeChild(Node* child, bool cleaup = true) override;
virtual Vector<Node*>& getChildren() override;
virtual const Vector<Node*>& getChildren() const override;
virtual ssize_t getChildrenCount() const override;

View File

@ -8,14 +8,12 @@ const char* font_UIListViewTest = "fonts/Marker Felt.ttf";
UIListViewTest_Vertical::UIListViewTest_Vertical()
: _displayValueLabel(nullptr)
, _array(nullptr)
{
}
UIListViewTest_Vertical::~UIListViewTest_Vertical()
{
CC_SAFE_RELEASE(_array);
}
bool UIListViewTest_Vertical::init()
@ -44,12 +42,11 @@ bool UIListViewTest_Vertical::init()
// create list view ex data
_array = Array::create();
CC_SAFE_RETAIN(_array);
for (int i = 0; i < 20; ++i)
{
__String* ccstr = __String::createWithFormat("listview_item_%d", i);
_array->addObject(ccstr);
std::string ccstr = StringUtils::format("listview_item_%d", i);
_array.push_back(ccstr);
}
@ -86,7 +83,7 @@ bool UIListViewTest_Vertical::init()
listView->setItemModel(default_item);
// add default item
ssize_t count = _array->count();
ssize_t count = _array.size();
for (int i = 0; i < count / 4; ++i)
{
listView->pushBackDefaultItem();
@ -144,7 +141,7 @@ bool UIListViewTest_Vertical::init()
Widget* item = listView->getItem(i);
Button* button = static_cast<Button*>(item->getChildByName("Title Button"));
ssize_t index = listView->getIndex(item);
button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString());
button->setTitleText(_array[index]);
}
// remove last item
@ -208,13 +205,11 @@ void UIListViewTest_Vertical::selectedItemEventScrollView(Ref* pSender, ui::Scro
UIListViewTest_Horizontal::UIListViewTest_Horizontal()
: _displayValueLabel(nullptr)
, _array(nullptr)
{
}
UIListViewTest_Horizontal::~UIListViewTest_Horizontal()
{
CC_SAFE_RELEASE(_array);
}
bool UIListViewTest_Horizontal::init()
@ -244,12 +239,11 @@ bool UIListViewTest_Horizontal::init()
// create list view ex data
_array = Array::create();
CC_SAFE_RETAIN(_array);
for (int i = 0; i < 20; ++i)
{
__String* ccstr = __String::createWithFormat("listview_item_%d", i);
_array->addObject(ccstr);
std::string ccstr = StringUtils::format("listview_item_%d", i);
_array.push_back(ccstr);
}
@ -284,7 +278,7 @@ bool UIListViewTest_Horizontal::init()
listView->setItemModel(default_item);
// add default item
ssize_t count = _array->count();
ssize_t count = _array.size();
for (int i = 0; i < count / 4; ++i)
{
listView->pushBackDefaultItem();
@ -335,7 +329,7 @@ bool UIListViewTest_Horizontal::init()
Widget *item = listView->getItem(i);
Button *button = static_cast<Button*>(item->getChildByName("Title Button"));
ssize_t index = listView->getIndex(item);
button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString());
button->setTitleText(_array[index]);
}
// remove last item
listView->removeLastItem();

View File

@ -41,7 +41,7 @@ protected:
UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical)
Text* _displayValueLabel;
__Array* _array;
std::vector<std::string> _array;
};
class UIListViewTest_Horizontal : public UIScene
@ -57,7 +57,7 @@ protected:
UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)
Text* _displayValueLabel;
__Array* _array;
std::vector<std::string> _array;
};
#endif /* defined(__TestCpp__UIListViewTest__) */