From 3c3d76fd9eb73ab9c3f21cf26df93dbe79928594 Mon Sep 17 00:00:00 2001 From: andyque Date: Tue, 14 Apr 2015 17:48:43 +0800 Subject: [PATCH] remove listview focus test --- .../UIFocusTest/UIFocusTest.cpp | 261 ++++++------------ .../UIFocusTest/UIFocusTest.h | 30 +- 2 files changed, 94 insertions(+), 197 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp index 3702b0b47f..29d32ba630 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp @@ -18,12 +18,11 @@ UIFocusTests::UIFocusTests() ADD_TEST_CASE(UIFocusTestNestedLayout1); ADD_TEST_CASE(UIFocusTestNestedLayout2); ADD_TEST_CASE(UIFocusTestNestedLayout3); - ADD_TEST_CASE(UIFocusTestListView); } UIFocusTestBase::UIFocusTestBase() { - + } UIFocusTestBase::~UIFocusTestBase() @@ -35,44 +34,44 @@ bool UIFocusTestBase::init() { if (UIScene::init()) { Layout* root = static_cast(_uiLayer->getChildByTag(81)); - + Layout* background = dynamic_cast(root->getChildByName("background_Panel")); background->removeFromParentAndCleanup(true); - + _dpadMenu = Menu::create(); - + auto winSize = Director::getInstance()->getVisibleSize(); auto leftItem = MenuItemFont::create("Left", CC_CALLBACK_0(UIFocusTestBase::onLeftKeyPressed, this)); leftItem->setPosition(Vec2(winSize.width - 100, winSize.height/2)); _dpadMenu->addChild(leftItem); - - + + auto rightItem = MenuItemFont::create("Right", CC_CALLBACK_0(UIFocusTestBase::onRightKeyPressed, this)); rightItem->setPosition(Vec2(winSize.width - 30, winSize.height/2)); _dpadMenu->addChild(rightItem); - + auto upItem = MenuItemFont::create("Up", CC_CALLBACK_0(UIFocusTestBase::onUpKeyPressed, this)); upItem->setPosition(Vec2(winSize.width - 60, winSize.height/2 + 50)); _dpadMenu->addChild(upItem); - + auto downItem = MenuItemFont::create("Down", CC_CALLBACK_0(UIFocusTestBase::onDownKeyPressed, this)); downItem->setPosition(Vec2(winSize.width - 60, winSize.height/2 - 50)); _dpadMenu->addChild(downItem); - + _dpadMenu->setPosition(Vec2::ZERO); _uiLayer->addChild(_dpadMenu); - + //call this method to enable Dpad focus navigation Widget::enableDpadNavigation(true); - + _eventListener = EventListenerFocus::create(); _eventListener->onFocusChanged = CC_CALLBACK_2(UIFocusTestBase::onFocusChanged, this); - + _eventDispatcher->addEventListenerWithFixedPriority(_eventListener, 1); - + return true; } - + return false; } @@ -109,7 +108,7 @@ void UIFocusTestBase::onUpKeyPressed() cocos2d::EventKeyboard::KeyCode cocos2dKey =EventKeyboard::KeyCode::KEY_DPAD_UP; cocos2d::EventKeyboard event(cocos2dKey, false); cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); - + } void UIFocusTestBase::onDownKeyPressed() @@ -117,7 +116,7 @@ void UIFocusTestBase::onDownKeyPressed() cocos2d::EventKeyboard::KeyCode cocos2dKey =EventKeyboard::KeyCode::KEY_DPAD_DOWN; cocos2d::EventKeyboard event(cocos2dKey, false); cocos2d::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); - + } void UIFocusTestBase::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus, cocos2d::ui::Widget *widgetGetFocus) @@ -125,11 +124,11 @@ void UIFocusTestBase::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus, cocos if (widgetGetFocus && widgetGetFocus->isFocusEnabled()) { widgetGetFocus->setColor(Color3B::RED); } - + if (widgetLostFocus && widgetLostFocus->isFocusEnabled()) { widgetLostFocus->setColor(Color3B::WHITE); } - + if (widgetLostFocus && widgetGetFocus) { CCLOG("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus->getTag(), widgetLostFocus->getTag()); } @@ -139,29 +138,29 @@ void UIFocusTestBase::onFocusChanged(cocos2d::ui::Widget *widgetLostFocus, cocos //UIFocusTestHorizontal UIFocusTestHorizontal::UIFocusTestHorizontal() { - + } UIFocusTestHorizontal::~UIFocusTestHorizontal() { - + } bool UIFocusTestHorizontal::init() { if (UIFocusTestBase::init()) { - + Size winSize = Director::getInstance()->getVisibleSize(); - + _horizontalLayout = HBox::create(); _horizontalLayout->setPosition(Vec2(20, winSize.height/2 + 40)); _uiLayer->addChild(_horizontalLayout); - + _horizontalLayout->setFocused(true); _horizontalLayout->setLoopFocus(true); _horizontalLayout->setTag(100); _firstFocusedWidget = _horizontalLayout; - + int count = 3; for (int i=0; iaddTouchEventListener(CC_CALLBACK_2(UIFocusTestHorizontal::onImageViewClicked, this)); _horizontalLayout->addChild(w); } - + _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(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(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestHorizontal::toggleFocusLoop,this)); this->addChild(btn); - - + + return true; } return false; @@ -208,30 +207,30 @@ void UIFocusTestHorizontal::toggleFocusLoop(cocos2d::Ref * pObjc, Widget::TouchE //UIFocusTestVertical UIFocusTestVertical::UIFocusTestVertical() { - + } UIFocusTestVertical::~UIFocusTestVertical() { - + } bool UIFocusTestVertical::init() { if (UIFocusTestBase::init()) { - + Size winSize = Director::getInstance()->getVisibleSize(); - + _verticalLayout = VBox::create(); _verticalLayout->setPosition(Vec2(winSize.width/2 - 100, winSize.height - 70)); _uiLayer->addChild(_verticalLayout); _verticalLayout->setTag(100); _verticalLayout->setScale(0.5); - + _verticalLayout->setFocused(true); _verticalLayout->setLoopFocus(true); _firstFocusedWidget = _verticalLayout; - + int count = 3; for (int i=0; irequestFocus(); } } - + _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(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(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::toggleFocusLoop, this)); this->addChild(btn); - - + + return true; } return false; @@ -278,30 +277,30 @@ void UIFocusTestVertical::toggleFocusLoop(cocos2d::Ref * pObjc, Widget::TouchEve //UIFocusTestNestedLayout1 UIFocusTestNestedLayout1::UIFocusTestNestedLayout1() { - + } UIFocusTestNestedLayout1::~UIFocusTestNestedLayout1() { - + } bool UIFocusTestNestedLayout1::init() { if (UIFocusTestBase::init()) { - + Size winSize = Director::getInstance()->getVisibleSize(); - + _verticalLayout = VBox::create(); _verticalLayout->setPosition(Vec2(winSize.width/2 - 80, winSize.height - 70)); _uiLayer->addChild(_verticalLayout); _verticalLayout->setScale(0.5); - + _verticalLayout->setFocused(true); _verticalLayout->setLoopFocus(true); _verticalLayout->setTag(100); _firstFocusedWidget = _verticalLayout; - + int count1 = 1; for (int i=0; iaddTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this)); _verticalLayout->addChild(w); } - + //add HBox into VBox HBox *hbox = HBox::create(); hbox->setScale(0.8f); hbox->setTag(101); _verticalLayout->addChild(hbox); - + int count2 = 2; for (int i=0; i < count2; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); @@ -329,14 +328,14 @@ bool UIFocusTestNestedLayout1::init() w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this)); hbox->addChild(w); } - + VBox *innerVBox = VBox::create(); hbox->addChild(innerVBox); innerVBox->setTag(102); // innerVBox->setPassFocusToChild(false); // innerVBox->setFocusEnabled(false); - - + + int count3 = 2; for (int i=0; isetPosition(Vec2(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(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::toggleFocusLoop, this)); this->addChild(btn); - - + + return true; } return false; @@ -380,30 +379,30 @@ void UIFocusTestNestedLayout1::toggleFocusLoop(cocos2d::Ref * pObjc, Widget::Tou //UIFocusTestNestedLayout2 UIFocusTestNestedLayout2::UIFocusTestNestedLayout2() { - + } UIFocusTestNestedLayout2::~UIFocusTestNestedLayout2() { - + } bool UIFocusTestNestedLayout2::init() { if (UIFocusTestBase::init()) { - + Size winSize = Director::getInstance()->getVisibleSize(); - + _horizontalLayout = HBox::create(); _horizontalLayout->setPosition(Vec2(winSize.width/2 - 200, winSize.height - 70)); _uiLayer->addChild(_horizontalLayout); _horizontalLayout->setScale(0.6f); - + _horizontalLayout->setFocused(true); _horizontalLayout->setLoopFocus(true); _horizontalLayout->setTag(100); _firstFocusedWidget = _horizontalLayout; - + int count1 = 2; for (int i=0; iaddTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); _horizontalLayout->addChild(w); } - + //add HBox into VBox VBox *vbox = VBox::create(); vbox->setScale(0.8f); vbox->setTag(101); _horizontalLayout->addChild(vbox); - + int count2 = 2; for (int i=0; i < count2; ++i) { ImageView *w = ImageView::create("cocosui/scrollviewbg.png"); @@ -431,14 +430,14 @@ bool UIFocusTestNestedLayout2::init() w->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); vbox->addChild(w); } - + HBox *innerHBox = HBox::create(); vbox->addChild(innerHBox); innerHBox->setTag(102); // innerVBox->setPassFocusToChild(false); // innerVBox->setFocusEnabled(false); - - + + int count3 = 2; for (int i=0; iaddTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this)); innerHBox->addChild(w); } - + _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(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(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::toggleFocusLoop, this)); this->addChild(btn); - - + + return true; } return false; @@ -482,49 +481,49 @@ void UIFocusTestNestedLayout2::toggleFocusLoop(cocos2d::Ref * pObjc, Widget::Tou //UIFocusTestNestedLayout3 UIFocusTestNestedLayout3::UIFocusTestNestedLayout3() { - + } UIFocusTestNestedLayout3::~UIFocusTestNestedLayout3() { - + } bool UIFocusTestNestedLayout3::init() { if (UIFocusTestBase::init()) { - + Size winSize = Director::getInstance()->getVisibleSize(); - + _verticalLayout = VBox::create(); _verticalLayout->setPosition(Vec2(40, winSize.height - 70)); _uiLayer->addChild(_verticalLayout); _verticalLayout->setScale(0.8f); - + _verticalLayout->setFocused(true); _verticalLayout->setLoopFocus(true); _verticalLayout->setTag(-1000); _firstFocusedWidget = _verticalLayout; - - + + HBox *upperHBox = HBox::create(); upperHBox->setTag(-200); _verticalLayout->addChild(upperHBox); - + LinearLayoutParameter *params = LinearLayoutParameter::create(); params->setMargin(Margin(0,0,50,0)); - + LinearLayoutParameter *vparams = LinearLayoutParameter::create(); vparams->setMargin(Margin(10, 0, 0, 140)); upperHBox->setLayoutParameter(vparams); - + int count = 3; for (int i=0; isetScale(0.5); firstVbox->setLayoutParameter(params); firstVbox->setTag((i+1) * 100); - + int count1 = 3; for (int j=0; jaddTouchEventListener(CC_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this)); firstVbox->addChild(w); } - + upperHBox->addChild(firstVbox); } - + HBox *bottomHBox = HBox::create(); bottomHBox->setScale(0.5); bottomHBox->setTag(600); - + bottomHBox->setLayoutParameter(vparams); count = 3; LinearLayoutParameter *bottomParams = LinearLayoutParameter::create(); @@ -555,22 +554,22 @@ bool UIFocusTestNestedLayout3::init() bottomHBox->addChild(w); } _verticalLayout->addChild(bottomHBox); - - - + + + _loopText = Text::create("loop enabled", "Arial", 20); _loopText->setPosition(Vec2(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(Vec2(60, winSize.height - 50)); btn->setTitleColor(Color3B::RED); btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this)); this->addChild(btn); - - + + return true; } return false; @@ -588,89 +587,3 @@ void UIFocusTestNestedLayout3::toggleFocusLoop(cocos2d::Ref * pObjc, Widget::Tou } } } - -//UIFocusTestListView -UIFocusTestListView::UIFocusTestListView() -{ - -} - -UIFocusTestListView::~UIFocusTestListView() -{ - -} - -bool UIFocusTestListView::init() -{ - if (UIFocusTestBase::init()) { - - Size winSize = Director::getInstance()->getVisibleSize(); - - _listView = ListView::create(); - _listView->setDirection(ui::ScrollView::Direction::VERTICAL); - _listView->setBounceEnabled(true); - _listView->setBackGroundImage("cocosui/green_edit.png"); - _listView->setBackGroundImageScale9Enabled(true); - _listView->setContentSize(Size(240, 130)); - - _listView->setPosition(Vec2(40, 70)); - _uiLayer->addChild(_listView); - _listView->setScale(0.8f); - - _listView->setFocused(true); - _listView->setLoopFocus(true); - _listView->setTag(-1000); - _firstFocusedWidget = _listView; - - // create model - Button* default_button = Button::create("cocosui/backtotoppressed.png", "cocosui/backtotopnormal.png"); - default_button->setName("Title Button"); - - - // set model - _listView->setItemModel(default_button); - - // add default item - ssize_t count = 20; - for (int i = 0; i < count / 4; ++i) - { - _listView->pushBackDefaultItem(); - } - // insert default item - for (int i = 0; i < count / 4; ++i) - { - _listView->insertDefaultItem(0); - } - - - - _loopText = Text::create("loop enabled", "Arial", 20); - _loopText->setPosition(Vec2(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(Vec2(60, winSize.height - 50)); - btn->setTitleColor(Color3B::RED); - btn->addTouchEventListener(CC_CALLBACK_2(UIFocusTestListView::toggleFocusLoop, this)); - this->addChild(btn); - - - return true; - } - return false; -} - - -void UIFocusTestListView::toggleFocusLoop(cocos2d::Ref * pObjc, Widget::TouchEventType type) -{ - if (type == Widget::TouchEventType::ENDED) { - _listView->setLoopFocus(!_listView->isLoopFocus()); - if (_listView->isLoopFocus()) { - _loopText->setString("loop enabled"); - }else{ - _loopText->setString("loop disabled"); - } - } -} diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h index a19bc5e54f..161c2f227b 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h @@ -20,7 +20,7 @@ public: virtual ~UIFocusTestBase(); virtual bool init() override; - + virtual void onLeftKeyPressed(); virtual void onRightKeyPressed(); virtual void onUpKeyPressed(); @@ -44,9 +44,9 @@ public: virtual ~UIFocusTestHorizontal(); virtual bool init() override; - + void toggleFocusLoop(cocos2d::Ref*,cocos2d::ui::Widget::TouchEventType); - + protected: cocos2d::ui::Layout* _horizontalLayout; cocos2d::ui::Text* _loopText; @@ -61,7 +61,7 @@ public: virtual ~UIFocusTestVertical(); virtual bool init() override; - + void toggleFocusLoop(cocos2d::Ref*,cocos2d::ui::Widget::TouchEventType); protected: cocos2d::ui::Layout* _verticalLayout; @@ -77,7 +77,7 @@ public: virtual ~UIFocusTestNestedLayout1(); virtual bool init() override; - + void toggleFocusLoop(cocos2d::Ref*,cocos2d::ui::Widget::TouchEventType); protected: cocos2d::ui::Layout* _verticalLayout; @@ -93,7 +93,7 @@ public: virtual ~UIFocusTestNestedLayout2(); virtual bool init() override; - + void toggleFocusLoop(cocos2d::Ref*,cocos2d::ui::Widget::TouchEventType); protected: cocos2d::ui::Layout* _horizontalLayout; @@ -109,29 +109,13 @@ public: virtual ~UIFocusTestNestedLayout3(); virtual bool init() override; - + void toggleFocusLoop(cocos2d::Ref*,cocos2d::ui::Widget::TouchEventType); protected: cocos2d::ui::Layout* _verticalLayout; cocos2d::ui::Text* _loopText; }; -class UIFocusTestListView : public UIFocusTestBase -{ -public: - CREATE_FUNC(UIFocusTestListView); - - UIFocusTestListView(); - virtual ~UIFocusTestListView(); - - virtual bool init() override; - - void toggleFocusLoop(cocos2d::Ref*,cocos2d::ui::Widget::TouchEventType); -protected: - cocos2d::ui::ListView* _listView; - cocos2d::ui::Text* _loopText; -}; - #endif /* defined(__cocos2d_tests__UIFocusTest__) */