don't let toggle accept focus (#16982)

This commit is contained in:
minggo 2016-12-12 09:41:53 +08:00 committed by GitHub
parent 91daa7a12a
commit 2c2ed5c5f5
2 changed files with 14 additions and 36 deletions

View File

@ -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;
}

View File

@ -33,6 +33,7 @@ protected:
cocos2d::Menu* _dpadMenu;
cocos2d::ui::Widget* _firstFocusedWidget;
cocos2d::EventListenerFocus* _eventListener;
cocos2d::ui::Button* _toggleButton;
};
class UIFocusTestHorizontal : public UIFocusTestBase