mirror of https://github.com/axmolengine/axmol.git
fix ListView addChild problem
This commit is contained in:
parent
e90e7699a6
commit
a4bd3879ac
|
@ -152,6 +152,16 @@ bool Layout::init()
|
||||||
}
|
}
|
||||||
return false;
|
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)
|
void Layout::addChild(Node *child, int zOrder, int tag)
|
||||||
{
|
{
|
||||||
|
|
|
@ -232,7 +232,6 @@ public:
|
||||||
|
|
||||||
virtual Type getLayoutType() const;
|
virtual Type getLayoutType() const;
|
||||||
|
|
||||||
using Node::addChild;
|
|
||||||
/**
|
/**
|
||||||
* Adds a child to the container with z order and tag
|
* 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 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)
|
* @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, int tag) override;
|
||||||
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
|
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
|
||||||
|
|
||||||
|
|
|
@ -272,6 +272,7 @@ void ListView::insertDefaultItem(ssize_t index)
|
||||||
_refreshViewDirty = true;
|
_refreshViewDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ListView::pushBackCustomItem(Widget* item)
|
void ListView::pushBackCustomItem(Widget* item)
|
||||||
{
|
{
|
||||||
remedyLayoutParameter(item);
|
remedyLayoutParameter(item);
|
||||||
|
@ -289,6 +290,16 @@ void ListView::addChild(cocos2d::Node *child, int zOrder, int tag)
|
||||||
_items.pushBack(widget);
|
_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)
|
void ListView::addChild(Node* child, int zOrder, const std::string &name)
|
||||||
{
|
{
|
||||||
|
|
|
@ -163,7 +163,8 @@ public:
|
||||||
|
|
||||||
virtual void doLayout() override;
|
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, int tag) override;
|
||||||
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
|
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
|
||||||
virtual void removeAllChildren() override;
|
virtual void removeAllChildren() override;
|
||||||
|
|
|
@ -229,6 +229,16 @@ const Size& ScrollView::getInnerContainerSize() const
|
||||||
{
|
{
|
||||||
return _innerContainer->getContentSize();
|
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)
|
void ScrollView::addChild(Node *child, int zOrder, int tag)
|
||||||
{
|
{
|
||||||
|
|
|
@ -254,12 +254,15 @@ public:
|
||||||
virtual void addEventListener(const ccScrollViewCallback& callback);
|
virtual void addEventListener(const ccScrollViewCallback& callback);
|
||||||
|
|
||||||
//all of these functions are related to innerContainer.
|
//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, int tag) override;
|
||||||
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
|
virtual void addChild(Node* child, int zOrder, const std::string &name) override;
|
||||||
|
|
||||||
virtual void removeAllChildren() override;
|
virtual void removeAllChildren() override;
|
||||||
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
|
virtual void removeAllChildrenWithCleanup(bool cleanup) override;
|
||||||
virtual void removeChild(Node* child, bool cleaup = true) override;
|
virtual void removeChild(Node* child, bool cleaup = true) override;
|
||||||
|
|
||||||
virtual Vector<Node*>& getChildren() override;
|
virtual Vector<Node*>& getChildren() override;
|
||||||
virtual const Vector<Node*>& getChildren() const override;
|
virtual const Vector<Node*>& getChildren() const override;
|
||||||
virtual ssize_t getChildrenCount() const override;
|
virtual ssize_t getChildrenCount() const override;
|
||||||
|
|
|
@ -8,14 +8,12 @@ const char* font_UIListViewTest = "fonts/Marker Felt.ttf";
|
||||||
|
|
||||||
UIListViewTest_Vertical::UIListViewTest_Vertical()
|
UIListViewTest_Vertical::UIListViewTest_Vertical()
|
||||||
: _displayValueLabel(nullptr)
|
: _displayValueLabel(nullptr)
|
||||||
, _array(nullptr)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UIListViewTest_Vertical::~UIListViewTest_Vertical()
|
UIListViewTest_Vertical::~UIListViewTest_Vertical()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIListViewTest_Vertical::init()
|
bool UIListViewTest_Vertical::init()
|
||||||
|
@ -44,12 +42,11 @@ bool UIListViewTest_Vertical::init()
|
||||||
|
|
||||||
|
|
||||||
// create list view ex data
|
// create list view ex data
|
||||||
_array = Array::create();
|
|
||||||
CC_SAFE_RETAIN(_array);
|
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
{
|
{
|
||||||
__String* ccstr = __String::createWithFormat("listview_item_%d", i);
|
std::string ccstr = StringUtils::format("listview_item_%d", i);
|
||||||
_array->addObject(ccstr);
|
_array.push_back(ccstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,7 +83,7 @@ bool UIListViewTest_Vertical::init()
|
||||||
listView->setItemModel(default_item);
|
listView->setItemModel(default_item);
|
||||||
|
|
||||||
// add default item
|
// add default item
|
||||||
ssize_t count = _array->count();
|
ssize_t count = _array.size();
|
||||||
for (int i = 0; i < count / 4; ++i)
|
for (int i = 0; i < count / 4; ++i)
|
||||||
{
|
{
|
||||||
listView->pushBackDefaultItem();
|
listView->pushBackDefaultItem();
|
||||||
|
@ -144,7 +141,7 @@ bool UIListViewTest_Vertical::init()
|
||||||
Widget* item = listView->getItem(i);
|
Widget* item = listView->getItem(i);
|
||||||
Button* button = static_cast<Button*>(item->getChildByName("Title Button"));
|
Button* button = static_cast<Button*>(item->getChildByName("Title Button"));
|
||||||
ssize_t index = listView->getIndex(item);
|
ssize_t index = listView->getIndex(item);
|
||||||
button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString());
|
button->setTitleText(_array[index]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove last item
|
// remove last item
|
||||||
|
@ -208,13 +205,11 @@ void UIListViewTest_Vertical::selectedItemEventScrollView(Ref* pSender, ui::Scro
|
||||||
|
|
||||||
UIListViewTest_Horizontal::UIListViewTest_Horizontal()
|
UIListViewTest_Horizontal::UIListViewTest_Horizontal()
|
||||||
: _displayValueLabel(nullptr)
|
: _displayValueLabel(nullptr)
|
||||||
, _array(nullptr)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
UIListViewTest_Horizontal::~UIListViewTest_Horizontal()
|
UIListViewTest_Horizontal::~UIListViewTest_Horizontal()
|
||||||
{
|
{
|
||||||
CC_SAFE_RELEASE(_array);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool UIListViewTest_Horizontal::init()
|
bool UIListViewTest_Horizontal::init()
|
||||||
|
@ -244,12 +239,11 @@ bool UIListViewTest_Horizontal::init()
|
||||||
|
|
||||||
|
|
||||||
// create list view ex data
|
// create list view ex data
|
||||||
_array = Array::create();
|
|
||||||
CC_SAFE_RETAIN(_array);
|
|
||||||
for (int i = 0; i < 20; ++i)
|
for (int i = 0; i < 20; ++i)
|
||||||
{
|
{
|
||||||
__String* ccstr = __String::createWithFormat("listview_item_%d", i);
|
std::string ccstr = StringUtils::format("listview_item_%d", i);
|
||||||
_array->addObject(ccstr);
|
_array.push_back(ccstr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +278,7 @@ bool UIListViewTest_Horizontal::init()
|
||||||
listView->setItemModel(default_item);
|
listView->setItemModel(default_item);
|
||||||
|
|
||||||
// add default item
|
// add default item
|
||||||
ssize_t count = _array->count();
|
ssize_t count = _array.size();
|
||||||
for (int i = 0; i < count / 4; ++i)
|
for (int i = 0; i < count / 4; ++i)
|
||||||
{
|
{
|
||||||
listView->pushBackDefaultItem();
|
listView->pushBackDefaultItem();
|
||||||
|
@ -335,7 +329,7 @@ bool UIListViewTest_Horizontal::init()
|
||||||
Widget *item = listView->getItem(i);
|
Widget *item = listView->getItem(i);
|
||||||
Button *button = static_cast<Button*>(item->getChildByName("Title Button"));
|
Button *button = static_cast<Button*>(item->getChildByName("Title Button"));
|
||||||
ssize_t index = listView->getIndex(item);
|
ssize_t index = listView->getIndex(item);
|
||||||
button->setTitleText(static_cast<__String*>(_array->getObjectAtIndex(index))->getCString());
|
button->setTitleText(_array[index]);
|
||||||
}
|
}
|
||||||
// remove last item
|
// remove last item
|
||||||
listView->removeLastItem();
|
listView->removeLastItem();
|
||||||
|
|
|
@ -41,7 +41,7 @@ protected:
|
||||||
UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical)
|
UI_SCENE_CREATE_FUNC(UIListViewTest_Vertical)
|
||||||
Text* _displayValueLabel;
|
Text* _displayValueLabel;
|
||||||
|
|
||||||
__Array* _array;
|
std::vector<std::string> _array;
|
||||||
};
|
};
|
||||||
|
|
||||||
class UIListViewTest_Horizontal : public UIScene
|
class UIListViewTest_Horizontal : public UIScene
|
||||||
|
@ -57,7 +57,7 @@ protected:
|
||||||
UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)
|
UI_SCENE_CREATE_FUNC(UIListViewTest_Horizontal)
|
||||||
Text* _displayValueLabel;
|
Text* _displayValueLabel;
|
||||||
|
|
||||||
__Array* _array;
|
std::vector<std::string> _array;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* defined(__TestCpp__UIListViewTest__) */
|
#endif /* defined(__TestCpp__UIListViewTest__) */
|
||||||
|
|
Loading…
Reference in New Issue