void tryCreateSubBtns(unsigned tag)
{
for (auto it = m_subBtnVec.begin(); it != m_subBtnVec.end(); it++)
{
(it->first)->removeFromParent();
}
m_subBtnVec.clear();
const int btnNum = m_showIdsVec.size();
auto& tmpInfo = m_showIdsVec.at(tag);
auto scroll = static_cast<ui::ScrollView*>(Helper::seekWidgetByName(m_rootNode, "ScrollView_1"));
const int subCount = tmpInfo.childVec.size();
if (subCount > 0)
{
const int smallDis = 65;
scroll->setInnerContainerSize(Size(scroll->getContentSize().width, row_dis * btnNum + subCount * smallDis));
int h = scroll->getInnerContainerSize().height;
const int parentPosYD = h - (tag + 1) * row_dis;
for (int index = 0; index < subCount; index++)
{
auto& data = tmpInfo.childVec[index];
Button* btn = Button::create("Common/button_yq06_1.png", "Common/button_yq06_2.png", "", Widget::TextureResType::PLIST);;
btn->setPosition(Vec2(scroll->getContentSize().width * 0.5 + 10, parentPosYD - (index + 0.5) * smallDis));
btn->showLightState(0 == index);
auto nameLbl = Label::createWithTTF(data.name, TK_FONT_BTN, 20);
nameLbl->setPosition(btn->getContentSize() / 2);
btn->addChild(nameLbl);
scroll->addChild(btn);
btn->setTag(0xffff);
btn->setName(TK_ITS(data.id));
btn->addClickEventListener(std::bind(&TKActivityLayer::onSubBtnClick, this, data));
m_subBtnVec.push_back(std::make_pair(btn, data));
}
for (int index = 0; index < btnNum; index++)
{
auto btn = static_cast<Button*>(scroll->getChildByTag(index));
if (btn)
{
int oft = index > tag ? smallDis * subCount : 0;
btn->setPosition(Vec2(scroll->getContentSize().width * 0.5, h - (index + 0.5) * row_dis - oft));
}
}
}
else
{
scroll->setInnerContainerSize(Size(scroll->getContentSize().width, row_dis * btnNum));
float h = scroll->getInnerContainerSize().height;
for (int index = 0; index < btnNum; index++)
{
auto btn = static_cast<Button*>(scroll->getChildByTag(index));
if (btn)
{
btn->setPosition(Vec2(scroll->getContentSize().width * 0.5, h - (index + 0.5) * row_dis));
}
}
}
}