From 2c2ed5c5f527e46723ef137baf4b2d50df4d476f Mon Sep 17 00:00:00 2001 From: minggo Date: Mon, 12 Dec 2016 09:41:53 +0800 Subject: [PATCH] don't let toggle accept focus (#16982) --- .../UIFocusTest/UIFocusTest.cpp | 49 +++++-------------- .../UIFocusTest/UIFocusTest.h | 1 + 2 files changed, 14 insertions(+), 36 deletions(-) diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp index ffa3599db1..af1cb441e4 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp @@ -68,6 +68,13 @@ bool UIFocusTestBase::init() _eventListener->onFocusChanged = CC_CALLBACK_2(UIFocusTestBase::onFocusChanged, this); _eventDispatcher->addEventListenerWithFixedPriority(_eventListener, 1); + + _toggleButton = Button::create("cocosui/switch-mask.png"); + _toggleButton->setTitleText("Toggle Loop"); + _toggleButton->setPosition(Vec2(60, winSize.height - 50)); + _toggleButton->setTitleColor(Color3B::RED); + _toggleButton->setFocusEnabled(false); + this->addChild(_toggleButton); return true; } @@ -175,13 +182,7 @@ bool UIFocusTestHorizontal::init() _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); - + _toggleButton->addTouchEventListener(CC_CALLBACK_2(UIFocusTestHorizontal::toggleFocusLoop,this)); return true; } @@ -244,14 +245,8 @@ bool UIFocusTestVertical::init() _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); - + + _toggleButton->addTouchEventListener(CC_CALLBACK_2(UIFocusTestVertical::toggleFocusLoop, this)); return true; } @@ -347,13 +342,7 @@ bool UIFocusTestNestedLayout1::init() _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); - + _toggleButton->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout1::toggleFocusLoop, this)); return true; } @@ -449,13 +438,7 @@ bool UIFocusTestNestedLayout2::init() _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); - + _toggleButton->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout2::toggleFocusLoop, this)); return true; } @@ -559,13 +542,7 @@ bool UIFocusTestNestedLayout3::init() _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); - + _toggleButton->addTouchEventListener(CC_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this)); return true; } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h index 161c2f227b..b8a2286114 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.h @@ -33,6 +33,7 @@ protected: cocos2d::Menu* _dpadMenu; cocos2d::ui::Widget* _firstFocusedWidget; cocos2d::EventListenerFocus* _eventListener; + cocos2d::ui::Button* _toggleButton; }; class UIFocusTestHorizontal : public UIFocusTestBase