mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8629 from andyque/fixPageVeiwRemoveAllPageIssue
Fix page veiw remove all page issue
This commit is contained in:
commit
344db304f6
|
@ -223,7 +223,7 @@ g_guisTests[] =
|
|||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||
sceneManager->setCurrentUISceneId(kUIPageViewTest);
|
||||
sceneManager->setMinUISceneId(kUIPageViewTest);
|
||||
sceneManager->setMaxUISceneId(kUIPageViewTouchPropagationTest);
|
||||
sceneManager->setMaxUISceneId(kUIPageViewDynamicAddAndRemoveTest);
|
||||
Scene* scene = sceneManager->currentUIScene();
|
||||
Director::getInstance()->replaceScene(scene);
|
||||
}
|
||||
|
|
|
@ -505,3 +505,180 @@ void UIPageViewTouchPropagationTest::pageViewEvent(Ref *pSender, PageView::Event
|
|||
}
|
||||
}
|
||||
|
||||
// UIPageViewDynamicAddAndRemoveTest
|
||||
UIPageViewDynamicAddAndRemoveTest::UIPageViewDynamicAddAndRemoveTest()
|
||||
: _displayValueLabel(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UIPageViewDynamicAddAndRemoveTest::~UIPageViewDynamicAddAndRemoveTest()
|
||||
{
|
||||
}
|
||||
|
||||
bool UIPageViewDynamicAddAndRemoveTest::init()
|
||||
{
|
||||
if (UIScene::init())
|
||||
{
|
||||
Size widgetSize = _widget->getContentSize();
|
||||
|
||||
// Add a label in which the dragpanel events will be displayed
|
||||
_displayValueLabel = Text::create("Click Buttons on the Left", "fonts/Marker Felt.ttf", 32);
|
||||
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
|
||||
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
|
||||
widgetSize.height / 2.0f +
|
||||
_displayValueLabel->getContentSize().height * 1.5));
|
||||
_uiLayer->addChild(_displayValueLabel);
|
||||
|
||||
// Add the black background
|
||||
Text* alert = Text::create("PageView Dynamic Modification", "fonts/Marker Felt.ttf", 30);
|
||||
alert->setColor(Color3B(159, 168, 176));
|
||||
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.075f));
|
||||
_uiLayer->addChild(alert);
|
||||
|
||||
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
|
||||
|
||||
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
|
||||
|
||||
// Create the page view
|
||||
PageView* pageView = PageView::create();
|
||||
pageView->setContentSize(Size(240.0f, 130.0f));
|
||||
pageView->setAnchorPoint(Vec2(0.5,0.5));
|
||||
Size backgroundSize = background->getContentSize();
|
||||
pageView->setPosition(Vec2(widgetSize.width / 2.0f ,widgetSize.height / 2.0f));
|
||||
pageView->setBackGroundColor(Color3B::GREEN);
|
||||
pageView->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
|
||||
|
||||
int pageCount = 4;
|
||||
for (int i = 0; i < pageCount; ++i)
|
||||
{
|
||||
HBox* outerBox = HBox::create();
|
||||
outerBox->setContentSize(Size(240.0f, 130.0f));
|
||||
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
VBox* innerBox = VBox::create();
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
Button *btn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
btn->setName(StringUtils::format("button %d", j));
|
||||
|
||||
innerBox->addChild(btn);
|
||||
}
|
||||
|
||||
LinearLayoutParameter *parameter = LinearLayoutParameter::create();
|
||||
parameter->setMargin(Margin(0,0,100,0));
|
||||
innerBox->setLayoutParameter(parameter);
|
||||
|
||||
outerBox->addChild(innerBox);
|
||||
|
||||
}
|
||||
|
||||
pageView->insertPage(outerBox,i);
|
||||
}
|
||||
|
||||
pageView->addEventListener(CC_CALLBACK_2(UIPageViewDynamicAddAndRemoveTest::pageViewEvent, this));
|
||||
pageView->setName("pageView");
|
||||
_uiLayer->addChild(pageView);
|
||||
|
||||
//add buttons
|
||||
auto button = Button::create();
|
||||
button->setNormalizedPosition(Vec2(0.12,0.7));
|
||||
button->setTitleText("Add A Page");
|
||||
button->setZoomScale(0.3);
|
||||
button->setPressedActionEnabled(true);
|
||||
button->setTitleColor(Color3B::RED);
|
||||
button->addClickEventListener([=](Ref* sender)
|
||||
{
|
||||
HBox* outerBox = HBox::create();
|
||||
outerBox->setContentSize(Size(240.0f, 130.0f));
|
||||
|
||||
for (int k = 0; k < 2; ++k)
|
||||
{
|
||||
VBox* innerBox = VBox::create();
|
||||
|
||||
for (int j = 0; j < 3; j++)
|
||||
{
|
||||
Button *btn = Button::create("cocosui/animationbuttonnormal.png",
|
||||
"cocosui/animationbuttonpressed.png");
|
||||
btn->setName(StringUtils::format("button %d", j));
|
||||
|
||||
innerBox->addChild(btn);
|
||||
}
|
||||
|
||||
LinearLayoutParameter *parameter = LinearLayoutParameter::create();
|
||||
parameter->setMargin(Margin(0,0,100,0));
|
||||
innerBox->setLayoutParameter(parameter);
|
||||
|
||||
outerBox->addChild(innerBox);
|
||||
|
||||
}
|
||||
|
||||
pageView->addPage(outerBox);
|
||||
_displayValueLabel->setString(CCString::createWithFormat("page count = %ld", pageView->getPages().size())->getCString());
|
||||
|
||||
});
|
||||
_uiLayer->addChild(button);
|
||||
|
||||
auto button2 = Button::create();
|
||||
button2->setNormalizedPosition(Vec2(0.12,0.5));
|
||||
button2->setTitleText("Remove A Page");
|
||||
button2->setZoomScale(0.3);
|
||||
button2->setPressedActionEnabled(true);
|
||||
button2->setTitleColor(Color3B::RED);
|
||||
button2->addClickEventListener([=](Ref* sender)
|
||||
{
|
||||
if (pageView->getPages().size() > 0)
|
||||
{
|
||||
pageView->removePageAtIndex(pageView->getPages().size()-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCLOG("There is no page to remove!");
|
||||
}
|
||||
_displayValueLabel->setString(CCString::createWithFormat("page count = %ld", pageView->getPages().size())->getCString());
|
||||
|
||||
});
|
||||
_uiLayer->addChild(button2);
|
||||
|
||||
auto button3 = Button::create();
|
||||
button3->setNormalizedPosition(Vec2(0.12,0.3));
|
||||
button3->setTitleText("Remove All Pages");
|
||||
button3->setZoomScale(0.3);
|
||||
button3->setPressedActionEnabled(true);
|
||||
button3->setTitleColor(Color3B::RED);
|
||||
button3->addClickEventListener([=](Ref* sender)
|
||||
{
|
||||
pageView->removeAllPages();
|
||||
_displayValueLabel->setString(CCString::createWithFormat("page count = %ld", pageView->getPages().size())->getCString());
|
||||
|
||||
});
|
||||
_uiLayer->addChild(button3);
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void UIPageViewDynamicAddAndRemoveTest::pageViewEvent(Ref *pSender, PageView::EventType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case PageView::EventType::TURNING:
|
||||
{
|
||||
PageView* pageView = dynamic_cast<PageView*>(pSender);
|
||||
|
||||
_displayValueLabel->setString(CCString::createWithFormat("page = %ld", pageView->getCurPageIndex() + 1)->getCString());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,4 +85,19 @@ protected:
|
|||
Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
class UIPageViewDynamicAddAndRemoveTest : public UIScene
|
||||
{
|
||||
public:
|
||||
UIPageViewDynamicAddAndRemoveTest();
|
||||
~UIPageViewDynamicAddAndRemoveTest();
|
||||
bool init();
|
||||
|
||||
void pageViewEvent(Ref* pSender, PageView::EventType type);
|
||||
void onButtonClicked(Ref* pSender, Widget::TouchEventType type);
|
||||
|
||||
protected:
|
||||
UI_SCENE_CREATE_FUNC(UIPageViewDynamicAddAndRemoveTest)
|
||||
Text* _displayValueLabel;
|
||||
};
|
||||
|
||||
#endif /* defined(__TestCpp__UIPageViewTest__) */
|
||||
|
|
|
@ -55,6 +55,7 @@ static const char* s_testArray[] =
|
|||
"UIImageViewTest",
|
||||
"UIImageViewTest_Scale9",
|
||||
"UIImageViewTest_ContentSize",
|
||||
|
||||
"UILoadingBarTest_Left",
|
||||
"UILoadingBarTest_Right",
|
||||
"UILoadingBarTest_Left_Scale9",
|
||||
|
@ -63,17 +64,17 @@ static const char* s_testArray[] =
|
|||
"UITextAtlasTest",
|
||||
"UITextTest",
|
||||
"UITextTest_LineWrap",
|
||||
|
||||
"UILabelTest_Effect",
|
||||
|
||||
"UITextTest_TTF",
|
||||
"UITextBMFontTest",
|
||||
|
||||
"UITextFieldTest",
|
||||
"UITextFieldTest_MaxLength",
|
||||
"UITextFieldTest_Password",
|
||||
"UITextFieldTest_LineWrap",
|
||||
"UITextFieldTest_TrueTypeFont",
|
||||
"UITextFieldTest_PlaceHolderColor",
|
||||
|
||||
"UILayoutTest",
|
||||
"UILayoutTest_Color",
|
||||
"UILayoutTest_Gradient",
|
||||
|
@ -90,15 +91,20 @@ static const char* s_testArray[] =
|
|||
"UIScrollViewTest_ScrollToPercentBothDirection",
|
||||
"UIScrollViewTest_ScrollToPercentBothDirection_Bounce",
|
||||
"UIScrollViewNestTest",
|
||||
|
||||
"UIPageViewTest",
|
||||
"UIPageViewButtonTest",
|
||||
"UIPageViewCustomScrollThreshold",
|
||||
"UIPageViewTouchPropagationTest",
|
||||
"UIPageViewDynamicAddAndRemoveTest",
|
||||
|
||||
"UIListViewTest_Vertical",
|
||||
"UIListViewTest_Horizontal",
|
||||
|
||||
"UIWidgetAddNodeTest",
|
||||
|
||||
"UIRichTextTest",
|
||||
|
||||
"UIFocusTest-HBox",
|
||||
"UIFocusTest-VBox",
|
||||
"UIFocusTest-NestedLayout1",
|
||||
|
@ -325,7 +331,8 @@ Scene *UISceneManager::currentUIScene()
|
|||
return UIPageViewCustomScrollThreshold::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case kUIPageViewTouchPropagationTest:
|
||||
return UIPageViewTouchPropagationTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
|
||||
case kUIPageViewDynamicAddAndRemoveTest:
|
||||
return UIPageViewDynamicAddAndRemoveTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
case kUIListViewTest_Vertical:
|
||||
return UIListViewTest_Vertical::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||
|
||||
|
|
|
@ -86,6 +86,7 @@ enum
|
|||
kUIPageViewButtonTest,
|
||||
kUIPageViewCustomScrollThreshold,
|
||||
kUIPageViewTouchPropagationTest,
|
||||
kUIPageViewDynamicAddAndRemoveTest,
|
||||
kUIListViewTest_Vertical,
|
||||
kUIListViewTest_Horizontal,
|
||||
kUIWidgetAddNodeTest,
|
||||
|
|
Loading…
Reference in New Issue