axmol/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIFocusTest/UIFocusTest.cpp

582 lines
19 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
2022-08-08 18:02:17 +08:00
https://axys1.github.io/
2019-11-23 20:27:39 +08:00
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
2019-11-23 20:27:39 +08:00
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
2019-11-23 20:27:39 +08:00
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
//
// UIFocusTest.cpp
// cocos2d_tests
//
// Created by guanghui on 5/4/14.
//
//
#include "UIFocusTest.h"
USING_NS_AX;
using namespace ax::ui;
2019-11-23 20:27:39 +08:00
UIFocusTests::UIFocusTests()
{
ADD_TEST_CASE(UIFocusTestHorizontal);
ADD_TEST_CASE(UIFocusTestVertical);
ADD_TEST_CASE(UIFocusTestNestedLayout1);
ADD_TEST_CASE(UIFocusTestNestedLayout2);
ADD_TEST_CASE(UIFocusTestNestedLayout3);
}
UIFocusTestBase::UIFocusTestBase() {}
2019-11-23 20:27:39 +08:00
UIFocusTestBase::~UIFocusTestBase()
{
_eventDispatcher->removeEventListener(_eventListener);
}
bool UIFocusTestBase::init()
{
if (UIScene::init())
{
2019-11-23 20:27:39 +08:00
Layout* root = static_cast<Layout*>(_uiLayer->getChildByTag(81));
Layout* background = dynamic_cast<Layout*>(root->getChildByName("background_Panel"));
background->removeFromParentAndCleanup(true);
_dpadMenu = Menu::create();
auto winSize = Director::getInstance()->getVisibleSize();
2022-07-16 10:43:05 +08:00
auto leftItem = MenuItemFont::create("Left", AX_CALLBACK_0(UIFocusTestBase::onLeftKeyPressed, this));
leftItem->setPosition(Vec2(winSize.width - 100, winSize.height / 2));
2019-11-23 20:27:39 +08:00
_dpadMenu->addChild(leftItem);
2022-07-16 10:43:05 +08:00
auto rightItem = MenuItemFont::create("Right", AX_CALLBACK_0(UIFocusTestBase::onRightKeyPressed, this));
rightItem->setPosition(Vec2(winSize.width - 30, winSize.height / 2));
2019-11-23 20:27:39 +08:00
_dpadMenu->addChild(rightItem);
2022-07-16 10:43:05 +08:00
auto upItem = MenuItemFont::create("Up", AX_CALLBACK_0(UIFocusTestBase::onUpKeyPressed, this));
upItem->setPosition(Vec2(winSize.width - 60, winSize.height / 2 + 50));
2019-11-23 20:27:39 +08:00
_dpadMenu->addChild(upItem);
2022-07-16 10:43:05 +08:00
auto downItem = MenuItemFont::create("Down", AX_CALLBACK_0(UIFocusTestBase::onDownKeyPressed, this));
downItem->setPosition(Vec2(winSize.width - 60, winSize.height / 2 - 50));
2019-11-23 20:27:39 +08:00
_dpadMenu->addChild(downItem);
_dpadMenu->setPosition(Vec2::ZERO);
_uiLayer->addChild(_dpadMenu);
// call this method to enable Dpad focus navigation
2019-11-23 20:27:39 +08:00
Widget::enableDpadNavigation(true);
_eventListener = EventListenerFocus::create();
2022-07-16 10:43:05 +08:00
_eventListener->onFocusChanged = AX_CALLBACK_2(UIFocusTestBase::onFocusChanged, this);
2019-11-23 20:27:39 +08:00
_eventDispatcher->addEventListenerWithFixedPriority(_eventListener, 1);
2019-11-23 20:27:39 +08:00
_toggleButton = Button::create("cocosui/switch-mask.png");
_toggleButton->setTitleText("Toggle Loop");
_toggleButton->setPosition(Vec2(60.0f, winSize.height - 50));
_toggleButton->setTitleColor(Color3B::RED);
_toggleButton->setFocusEnabled(false);
this->addChild(_toggleButton);
return true;
}
return false;
}
void UIFocusTestBase::onImageViewClicked(axis::Ref* ref, Widget::TouchEventType touchType)
2019-11-23 20:27:39 +08:00
{
if (touchType == Widget::TouchEventType::ENDED)
{
Widget* w = (Widget*)ref;
if (w->isFocusEnabled())
{
2019-11-23 20:27:39 +08:00
w->setFocusEnabled(false);
w->setColor(Color3B::YELLOW);
}
else
{
2019-11-23 20:27:39 +08:00
w->setFocusEnabled(true);
w->setColor(Color3B::WHITE);
}
}
}
void UIFocusTestBase::onLeftKeyPressed()
{
axis::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_DPAD_LEFT;
axis::EventKeyboard event(cocos2dKey, false);
axis::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
2019-11-23 20:27:39 +08:00
}
void UIFocusTestBase::onRightKeyPressed()
{
axis::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_DPAD_RIGHT;
axis::EventKeyboard event(cocos2dKey, false);
axis::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
2019-11-23 20:27:39 +08:00
}
void UIFocusTestBase::onUpKeyPressed()
{
axis::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_DPAD_UP;
axis::EventKeyboard event(cocos2dKey, false);
axis::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
2019-11-23 20:27:39 +08:00
}
void UIFocusTestBase::onDownKeyPressed()
{
axis::EventKeyboard::KeyCode cocos2dKey = EventKeyboard::KeyCode::KEY_DPAD_DOWN;
axis::EventKeyboard event(cocos2dKey, false);
axis::Director::getInstance()->getEventDispatcher()->dispatchEvent(&event);
2019-11-23 20:27:39 +08:00
}
void UIFocusTestBase::onFocusChanged(axis::ui::Widget* widgetLostFocus, axis::ui::Widget* widgetGetFocus)
2019-11-23 20:27:39 +08:00
{
if (widgetGetFocus && widgetGetFocus->isFocusEnabled())
{
2019-11-23 20:27:39 +08:00
widgetGetFocus->setColor(Color3B::RED);
}
if (widgetLostFocus && widgetLostFocus->isFocusEnabled())
{
2019-11-23 20:27:39 +08:00
widgetLostFocus->setColor(Color3B::WHITE);
}
if (widgetLostFocus && widgetGetFocus)
{
2022-07-16 10:43:05 +08:00
AXLOG("on focus change, %d widget get focus, %d widget lose focus", widgetGetFocus->getTag(),
widgetLostFocus->getTag());
2019-11-23 20:27:39 +08:00
}
}
// UIFocusTestHorizontal
UIFocusTestHorizontal::UIFocusTestHorizontal() {}
2019-11-23 20:27:39 +08:00
UIFocusTestHorizontal::~UIFocusTestHorizontal() {}
2019-11-23 20:27:39 +08:00
bool UIFocusTestHorizontal::init()
{
if (UIFocusTestBase::init())
{
2019-11-23 20:27:39 +08:00
Size winSize = Director::getInstance()->getVisibleSize();
_horizontalLayout = HBox::create();
_horizontalLayout->setPosition(Vec2(20.0f, winSize.height / 2 + 40));
2019-11-23 20:27:39 +08:00
_uiLayer->addChild(_horizontalLayout);
_horizontalLayout->setFocused(true);
_horizontalLayout->setLoopFocus(true);
_horizontalLayout->setTag(100);
_firstFocusedWidget = _horizontalLayout;
int count = 3;
for (int i = 0; i < count; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setTouchEnabled(true);
w->setTag(i);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestHorizontal::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
_horizontalLayout->addChild(w);
}
_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width / 2, winSize.height - 50));
2019-11-23 20:27:39 +08:00
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);
2022-07-16 10:43:05 +08:00
_toggleButton->addTouchEventListener(AX_CALLBACK_2(UIFocusTestHorizontal::toggleFocusLoop, this));
2019-11-23 20:27:39 +08:00
return true;
}
return false;
}
void UIFocusTestHorizontal::toggleFocusLoop(axis::Ref* pObjc, Widget::TouchEventType type)
2019-11-23 20:27:39 +08:00
{
if (type == Widget::TouchEventType::ENDED)
{
2019-11-23 20:27:39 +08:00
_horizontalLayout->setLoopFocus(!_horizontalLayout->isLoopFocus());
if (_horizontalLayout->isLoopFocus())
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop enabled");
}
else
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop disabled");
}
}
}
// UIFocusTestVertical
UIFocusTestVertical::UIFocusTestVertical() {}
2019-11-23 20:27:39 +08:00
UIFocusTestVertical::~UIFocusTestVertical() {}
2019-11-23 20:27:39 +08:00
bool UIFocusTestVertical::init()
{
if (UIFocusTestBase::init())
{
2019-11-23 20:27:39 +08:00
Size winSize = Director::getInstance()->getVisibleSize();
_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vec2(winSize.width / 2 - 100, winSize.height - 70));
2019-11-23 20:27:39 +08:00
_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; i < count; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setTouchEnabled(true);
w->setTag(i);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestVertical::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
_verticalLayout->addChild(w);
}
_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width / 2, winSize.height - 50));
2019-11-23 20:27:39 +08:00
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);
2022-07-16 10:43:05 +08:00
_toggleButton->addTouchEventListener(AX_CALLBACK_2(UIFocusTestVertical::toggleFocusLoop, this));
2019-11-23 20:27:39 +08:00
return true;
}
return false;
}
void UIFocusTestVertical::toggleFocusLoop(axis::Ref* pObjc, Widget::TouchEventType type)
2019-11-23 20:27:39 +08:00
{
if (type == Widget::TouchEventType::ENDED)
{
2019-11-23 20:27:39 +08:00
_verticalLayout->setLoopFocus(!_verticalLayout->isLoopFocus());
if (_verticalLayout->isLoopFocus())
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop enabled");
}
else
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop disabled");
}
}
}
// UIFocusTestNestedLayout1
UIFocusTestNestedLayout1::UIFocusTestNestedLayout1() {}
2019-11-23 20:27:39 +08:00
UIFocusTestNestedLayout1::~UIFocusTestNestedLayout1() {}
2019-11-23 20:27:39 +08:00
bool UIFocusTestNestedLayout1::init()
{
if (UIFocusTestBase::init())
{
2019-11-23 20:27:39 +08:00
Size winSize = Director::getInstance()->getVisibleSize();
_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vec2(winSize.width / 2 - 80, winSize.height - 70));
2019-11-23 20:27:39 +08:00
_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; i < count1; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setAnchorPoint(Vec2::ZERO);
w->setTouchEnabled(true);
w->setScaleX(2.5);
w->setTag(i + count1);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
_verticalLayout->addChild(w);
}
// add HBox into VBox
HBox* hbox = HBox::create();
2019-11-23 20:27:39 +08:00
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");
w->setAnchorPoint(Vec2(0, 1));
2019-11-23 20:27:39 +08:00
w->setScaleY(2.0);
w->setTouchEnabled(true);
w->setTag(i + count1 + count2);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
hbox->addChild(w);
}
VBox* innerVBox = VBox::create();
2019-11-23 20:27:39 +08:00
hbox->addChild(innerVBox);
innerVBox->setTag(102);
// innerVBox->setPassFocusToChild(false);
// innerVBox->setFocusEnabled(false);
2019-11-23 20:27:39 +08:00
int count3 = 2;
for (int i = 0; i < count3; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setTouchEnabled(true);
w->setTag(i + count1 + count2 + count3);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout1::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
innerVBox->addChild(w);
}
_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width / 2, winSize.height - 50));
2019-11-23 20:27:39 +08:00
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);
2022-07-16 10:43:05 +08:00
_toggleButton->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout1::toggleFocusLoop, this));
2019-11-23 20:27:39 +08:00
return true;
}
return false;
}
void UIFocusTestNestedLayout1::toggleFocusLoop(axis::Ref* pObjc, Widget::TouchEventType type)
2019-11-23 20:27:39 +08:00
{
if (type == Widget::TouchEventType::ENDED)
{
2019-11-23 20:27:39 +08:00
_verticalLayout->setLoopFocus(!_verticalLayout->isLoopFocus());
if (_verticalLayout->isLoopFocus())
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop enabled");
}
else
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop disabled");
}
}
}
// UIFocusTestNestedLayout2
UIFocusTestNestedLayout2::UIFocusTestNestedLayout2() {}
2019-11-23 20:27:39 +08:00
UIFocusTestNestedLayout2::~UIFocusTestNestedLayout2() {}
2019-11-23 20:27:39 +08:00
bool UIFocusTestNestedLayout2::init()
{
if (UIFocusTestBase::init())
{
2019-11-23 20:27:39 +08:00
Size winSize = Director::getInstance()->getVisibleSize();
_horizontalLayout = HBox::create();
_horizontalLayout->setPosition(Vec2(winSize.width / 2 - 200, winSize.height - 70));
2019-11-23 20:27:39 +08:00
_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; i < count1; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
w->setAnchorPoint(Vec2(0, 1));
2019-11-23 20:27:39 +08:00
w->setTouchEnabled(true);
w->setTag(i + count1);
2019-11-23 20:27:39 +08:00
w->setScaleY(2.4f);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
_horizontalLayout->addChild(w);
}
// add HBox into VBox
VBox* vbox = VBox::create();
2019-11-23 20:27:39 +08:00
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");
w->setAnchorPoint(Vec2(0, 1));
2019-11-23 20:27:39 +08:00
w->setScaleX(2.0);
w->setTouchEnabled(true);
w->setTag(i + count1 + count2);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
vbox->addChild(w);
}
HBox* innerHBox = HBox::create();
2019-11-23 20:27:39 +08:00
vbox->addChild(innerHBox);
innerHBox->setTag(102);
// innerVBox->setPassFocusToChild(false);
// innerVBox->setFocusEnabled(false);
int count3 = 2;
for (int i = 0; i < count3; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setTouchEnabled(true);
w->setTag(i + count1 + count2 + count3);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout2::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
innerHBox->addChild(w);
}
_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width / 2, winSize.height - 50));
2019-11-23 20:27:39 +08:00
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);
2022-07-16 10:43:05 +08:00
_toggleButton->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout2::toggleFocusLoop, this));
2019-11-23 20:27:39 +08:00
return true;
}
return false;
}
void UIFocusTestNestedLayout2::toggleFocusLoop(axis::Ref* pObjc, Widget::TouchEventType type)
2019-11-23 20:27:39 +08:00
{
if (type == Widget::TouchEventType::ENDED)
{
2019-11-23 20:27:39 +08:00
_horizontalLayout->setLoopFocus(!_horizontalLayout->isLoopFocus());
if (_horizontalLayout->isLoopFocus())
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop enabled");
}
else
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop disabled");
}
}
}
// UIFocusTestNestedLayout3
UIFocusTestNestedLayout3::UIFocusTestNestedLayout3() {}
2019-11-23 20:27:39 +08:00
UIFocusTestNestedLayout3::~UIFocusTestNestedLayout3() {}
2019-11-23 20:27:39 +08:00
bool UIFocusTestNestedLayout3::init()
{
if (UIFocusTestBase::init())
{
2019-11-23 20:27:39 +08:00
Size winSize = Director::getInstance()->getVisibleSize();
_verticalLayout = VBox::create();
_verticalLayout->setPosition(Vec2(40.0f, 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();
2019-11-23 20:27:39 +08:00
upperHBox->setTag(-200);
_verticalLayout->addChild(upperHBox);
LinearLayoutParameter* params = LinearLayoutParameter::create();
params->setMargin(Margin(0.0f, 0.0f, 50.0f, 0.0f));
2019-11-23 20:27:39 +08:00
LinearLayoutParameter* vparams = LinearLayoutParameter::create();
2019-11-23 20:27:39 +08:00
vparams->setMargin(Margin(10.0f, 0.0f, 0.0f, 140.0f));
upperHBox->setLayoutParameter(vparams);
int count = 3;
for (int i = 0; i < count; ++i)
{
VBox* firstVbox = VBox::create();
2019-11-23 20:27:39 +08:00
firstVbox->setScale(0.5);
firstVbox->setLayoutParameter(params);
firstVbox->setTag((i + 1) * 100);
2019-11-23 20:27:39 +08:00
int count1 = 3;
for (int j = 0; j < count1; ++j)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setTouchEnabled(true);
w->setTag(j + firstVbox->getTag() + 1);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
firstVbox->addChild(w);
}
upperHBox->addChild(firstVbox);
}
HBox* bottomHBox = HBox::create();
2019-11-23 20:27:39 +08:00
bottomHBox->setScale(0.5);
bottomHBox->setTag(600);
bottomHBox->setLayoutParameter(vparams);
count = 3;
LinearLayoutParameter* bottomParams = LinearLayoutParameter::create();
2019-11-23 20:27:39 +08:00
bottomParams->setMargin(Margin(0.0f, 0.0f, 8.0f, 0.0f));
for (int i = 0; i < count; ++i)
{
ImageView* w = ImageView::create("cocosui/scrollviewbg.png");
2019-11-23 20:27:39 +08:00
w->setLayoutParameter(bottomParams);
w->setTouchEnabled(true);
w->setTag(i + 601);
2022-07-16 10:43:05 +08:00
w->addTouchEventListener(AX_CALLBACK_2(UIFocusTestBase::onImageViewClicked, this));
2019-11-23 20:27:39 +08:00
bottomHBox->addChild(w);
}
_verticalLayout->addChild(bottomHBox);
_loopText = Text::create("loop enabled", "Arial", 20);
_loopText->setPosition(Vec2(winSize.width / 2, winSize.height - 50));
2019-11-23 20:27:39 +08:00
_loopText->setColor(Color3B::GREEN);
this->addChild(_loopText);
2022-07-16 10:43:05 +08:00
_toggleButton->addTouchEventListener(AX_CALLBACK_2(UIFocusTestNestedLayout3::toggleFocusLoop, this));
2019-11-23 20:27:39 +08:00
return true;
}
return false;
}
void UIFocusTestNestedLayout3::toggleFocusLoop(axis::Ref* pObjc, Widget::TouchEventType type)
2019-11-23 20:27:39 +08:00
{
if (type == Widget::TouchEventType::ENDED)
{
2019-11-23 20:27:39 +08:00
_verticalLayout->setLoopFocus(!_verticalLayout->isLoopFocus());
if (_verticalLayout->isLoopFocus())
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop enabled");
}
else
{
2019-11-23 20:27:39 +08:00
_loopText->setString("loop disabled");
}
}
}