issue #4861, add nested focus test

This commit is contained in:
andyque 2014-05-06 14:38:45 +08:00
parent e52370e1c2
commit 29c57568bf
4 changed files with 93 additions and 2 deletions

View File

@ -274,7 +274,7 @@ g_guisTests[] =
UISceneManager* pManager = UISceneManager::sharedUISceneManager();
pManager->setCurrentUISceneId(KUIFocusTest_HBox);
pManager->setMinUISceneId(KUIFocusTest_HBox);
pManager->setMaxUISceneId(KUIFocusTest_VBox);
pManager->setMaxUISceneId(KUIFocusTest_NestedLayout1);
Scene* pScene = pManager->currentUIScene();
Director::getInstance()->replaceScene(pScene);
}

View File

@ -255,3 +255,90 @@ void UIFocusTestVertical::toggleFocusLoop(cocos2d::Ref * pObjc, TouchEventType t
}
//UIFocusTestNestedLayout1
UIFocusTestNestedLayout1::UIFocusTestNestedLayout1()
{
}
UIFocusTestNestedLayout1::~UIFocusTestNestedLayout1()
{
}
bool UIFocusTestNestedLayout1::init()
{
if (UIFocusTestBase::init()) {
Size winSize = Director::getInstance()->getVisibleSize();
_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vector2(winSize.width/2 - 100, winSize.height - 70));
_uiLayer->addChild(_verticalLayout);
_verticalLayout->setScale(0.8);
_verticalLayout->setFocused(true);
_verticalLayout->setLoopFocus(true);
_firstFocusedWidget = _verticalLayout;
int count = 1;
for (int i=0; i<count; ++i) {
ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
w->setTouchEnabled(true);
w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked));
_verticalLayout->addChild(w);
}
//add HBox into VBox
HBox *hbox = HBox::create();
hbox->setScale(0.8);
_verticalLayout->addChild(hbox);
count = 2;
for (int i=0; i < count; ++i) {
ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
w->setTouchEnabled(true);
w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked));
hbox->addChild(w);
}
VBox *innerVBox = VBox::create();
hbox->addChild(innerVBox);
count = 2;
for (int i=0; i<count; ++i) {
ImageView *w = ImageView::create("cocosui/scrollviewbg.png");
w->setTouchEnabled(true);
w->addTouchEventListener(this, toucheventselector(UIFocusTestVertical::onImageViewClicked));
innerVBox->addChild(w);
}
_loopText = Text::create("loop enabled", "Airal", 20);
_loopText->setPosition(Vector2(winSize.width/2, winSize.height - 50));
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);
auto btn = Button::create("cocosui/switch-mask.png");
btn->setTitleText("Toggle Loop");
btn->setPosition(Vector2(60, winSize.height - 50));
btn->setTitleColor(Color3B::RED);
btn->addTouchEventListener(this, toucheventselector(UIFocusTestHorizontal::toggleFocusLoop));
this->addChild(btn);
return true;
}
return false;
}
void UIFocusTestNestedLayout1::toggleFocusLoop(cocos2d::Ref * pObjc, TouchEventType type)
{
if (type == TouchEventType::TOUCH_EVENT_ENDED) {
_verticalLayout->setLoopFocus(!_verticalLayout->getLoopFocus());
if (_verticalLayout->getLoopFocus()) {
_loopText->setText("loop enabled");
}else{
_loopText->setText("loop disabled");
}
}
}

View File

@ -111,7 +111,8 @@ static const char* s_testArray[] =
"UIWidgetAddNodeTest",
"UIRichTextTest",
"UIFocusTest-HBox",
"UIFocusTest-VBox"
"UIFocusTest-VBox",
"UIFocusTest-NestedLayout1"
};
static UISceneManager *sharedInstance = NULL;
@ -366,6 +367,8 @@ Scene *UISceneManager::currentUIScene()
return UIFocusTestHorizontal::sceneWithTitle(s_testArray[_currentUISceneId]);
case KUIFocusTest_VBox:
return UIFocusTestVertical::sceneWithTitle(s_testArray[_currentUISceneId]);
case KUIFocusTest_NestedLayout1:
return UIFocusTestNestedLayout1::sceneWithTitle(s_testArray[_currentUISceneId]);
}
return NULL;

View File

@ -103,6 +103,7 @@ enum
kUIRichTextTest,
KUIFocusTest_HBox,
KUIFocusTest_VBox,
KUIFocusTest_NestedLayout1,
kUITestMax
};