PuzzleSDK
UITabControlTest.cpp
浏览该文件的文档.
1/****************************************************************************
2 Copyright(c) 2016 cocos2d - x.org
3 Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
4
5 http ://www.cocos2d-x.org
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software and associated documentation files(the "Software"), to deal
9 in the Software without restriction, including without limitation the rights
10 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
11 copies of the Software, and to permit persons to whom the Software is
12 furnished to do so, subject to the following conditions :
13
14 The above copyright notice and this permission notice shall be included in
15 all copies or substantial portions of the Software.
16
17 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
20 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 THE SOFTWARE.
24 ****************************************************************************/
25
26#include "ui/UITabControl.h"
27#include "UITabControlTest.h"
28
30using namespace cocos2d::ui;
31
32UITabControlTests::UITabControlTests()
33{
35}
36
37
39{
40}
41
43{
44
45}
46
48{
49
50 if (UIScene::init())
51 {
52 Size widgetSize = _widget->getContentSize();
53
54 auto displayText = Text::create();
55 displayText->setPosition(VisibleRect::bottom() + Vec2(0, 50));
56 _uiLayer->addChild(displayText);
57
58 auto tab = TabControl::create();
59 tab->setContentSize(Size(200.f, 200.f));
60 tab->setHeaderHeight(20.f);
61 tab->setHeaderWidth(70.f);
62 tab->setHeaderSelectedZoom(.1f);
63 tab->setHeaderDockPlace(TabControl::Dock::TOP);
64
65 auto header1 = TabHeader::create();
66 header1->setTitleText("background");
67 header1->loadTextureBackGround("cocosui/check_box_normal_disable.png");
68 auto header2 = TabHeader::create("cross", "cocosui/check_box_normal_disable.png", "cocosui/check_box_active.png");
69 auto header3 = TabHeader::create("press&cross", "cocosui/check_box_normal.png",
70 "cocosui/check_box_normal_press.png",
71 "cocosui/check_box_active.png",
72 "cocosui/check_box_normal_disable.png",
73 "cocosui/check_box_active_disable.png");
74
75 auto container1 = Layout::create();
76 container1->setOpacity(255);
77 container1->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
78 container1->setBackGroundColor(Color3B::GRAY);
79 container1->setBackGroundColorOpacity(255);
80 auto container2 = Layout::create();
81 container2->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
82 container2->setOpacity(255);
83 container2->setBackGroundColor(Color3B::BLUE);
84 container2->setBackGroundColorOpacity(255);
85 auto container3 = Layout::create();
86 container3->setBackGroundColorType(Layout::BackGroundColorType::SOLID);
87 container3->setOpacity(255);
88 container3->setBackGroundColor(Color3B::RED);
89 container3->setBackGroundColorOpacity(255);
90
91 tab->insertTab(0, header1, container1);
92 tab->insertTab(1, header2, container2);
93 tab->insertTab(2, header3, container3);
94
95 tab->setSelectTab(2);
96
97 _uiLayer->addChild(tab);
98 tab->setPosition(Vec2(widgetSize.width * .5f, widgetSize.height * .5f));
99
100 tab->setTabChangedEventListener(
101 [displayText](int index, TabControl::EventType evtType)
102 {
103 displayText->retain();
104 char display[20];
105 sprintf(display, "tab %d selected", index);
106 displayText->setString(display);
107 displayText->release();
108 }
109 );
110
111 return true;
112 }
113 return false;
114}
115
#define ADD_TEST_CASE(__className__)
Definition: BaseTest.h:211
USING_NS_CC
cocos2d::Layer * _uiLayer
Definition: UIScene.h:44
virtual bool init() override
Definition: UIScene.cpp:46
cocos2d::ui::Layout * _widget
Definition: UIScene.h:45
bool init() override
static cocos2d::Vec2 bottom()
Definition: VisibleRect.cpp:63