Multiple items testcase

This commit is contained in:
ZhangMenghe 2015-09-21 18:22:58 +08:00
parent 4054686903
commit 68713d2074
1 changed files with 94 additions and 18 deletions

View File

@ -481,6 +481,8 @@ var UIScrollViewDisableTest = UIMainLayer.extend({
});
var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
_scrollView:null,
_itemNumber:1000,
init: function () {
if (this._super()) {
var widgetSize = this._widget.getContentSize();
@ -496,7 +498,7 @@ var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
var background = this._widget.getChildByName("background_Panel");
// Create the scrollview
var scrollView = new ccui.ScrollView();
var scrollView = this._scrollView = new ccui.ScrollView();
scrollView.setDirection(ccui.ScrollView.DIR_VERTICAL);
scrollView.setTouchEnabled(true);
scrollView.setContentSize(cc.size(280, 150));
@ -505,26 +507,100 @@ var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollView.height) / 2;
this._mainNode.addChild(scrollView);
var Texts = [];
var start = new ccui.Text("---start---", "Thonburi", 10);
var innerWidth = scrollView.width;
var innerHeight = 1000 * start.height;
scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
var labelText = new cc.LabelTTF("Texts", "Arial", 25);
var labelButton = new cc.LabelTTF("Buttons", "Arial", 25);
var labelS9sprite = new cc.LabelTTF("s9Sprites", "Arial", 25);
start.x = innerWidth / 2;
start.y = scrollView.getInnerContainerSize().height - start.height / 2;
Texts[0] = start;
scrollView.addChild(start);
for(var i=1; i<2000; i++) {
var text = new ccui.Text("This is a test label: "+i, "Thonburi", 10);
text.x = innerWidth / 2;
text.y = Texts[i-1].getBottomBoundary() - text.height / 2;
Texts[i] = text;
scrollView.addChild(Texts[i]);
}
var menuItem1 = new cc.MenuItemLabel(labelText, this.drawTexts, this);
var menuItem2 = new cc.MenuItemLabel(labelButton, this.drawButtons, this, false);
var menuItem3 = new cc.MenuItemLabel(labelS9sprite, this.drawS9Buttons, this);
var menu = new cc.Menu(menuItem1, menuItem2, menuItem3);
menu.x = 0;
menu.y = 0;
menuItem1.x = menuItem2.x = menuItem3.x = 120;
menuItem1.y = 150;
menuItem2.y = 200;
menuItem3.y = 250;
this.addChild(menu, 1);
this.drawTexts();
return true;
}
return false;
},
drawTexts:function() {
var scrollView = this._scrollView;
var n = this._itemNumber/2;
if(scrollView.getChildren())
scrollView.removeAllChildren(true);
var Texts = [];
var start = new ccui.Text("---start---", "Thonburi", 10);
var innerWidth = scrollView.width;
var innerHeight = n * start.height;
scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
start.x = innerWidth / 2;
start.y = scrollView.getInnerContainerSize().height - start.height / 2;
Texts[0] = start;
scrollView.addChild(start);
for (var i = 1; i < n; i++) {
var text = new ccui.Text("This is a test label: " + i, "Thonburi", 10);
text.x = innerWidth / 2;
text.y = Texts[i - 1].getBottomBoundary() - text.height / 2;
Texts[i] = text;
scrollView.addChild(Texts[i]);
}
},
drawButtons:function() {
var scrollView = this._scrollView;
var n = this._itemNumber/2;
if(scrollView.getChildren())
scrollView.removeAllChildren(true);
var Buttons = [];
var innerWidth = scrollView.width;
for (var j = 0; j < n; j++) {
var button = new ccui.Button();
button.setTouchEnabled(true);
button.loadTextures("ccs-res/cocosui/animationbuttonnormal.png", "ccs-res/cocosui/animationbuttonpressed.png", "");
button.x = innerWidth / 2;
if(j===0) {
var innerHeight = n * button.height;
scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
button.y =scrollView.getInnerContainerSize().height - button.height / 2;
}
else
button.y =Buttons[j - 1].getBottomBoundary() - button.height / 2;
Buttons.push(button);
scrollView.addChild(button);
}
},
drawS9Buttons: function() {
var scrollView = this._scrollView;
var n = this._itemNumber;
if(scrollView.getChildren())
scrollView.removeAllChildren(true);
var Buttons = [];
var innerWidth = scrollView.width;
for (var j = 0; j < n; j++) {
var button_scale9 = new ccui.Button();
button_scale9.setTouchEnabled(true);
button_scale9.setScale9Enabled(true);
button_scale9.loadTextures("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png", "");
button_scale9.width = 100;
button_scale9.height = 32;
button_scale9.x = innerWidth / 2;
if(j === 0) {
var innerHeight = n * 32;
scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
button_scale9.y = scrollView.getInnerContainerSize().height - button_scale9.height / 2;
}
else
button_scale9.y = Buttons[j-1].getBottomBoundary() - button_scale9.height / 2;
Buttons.push(button_scale9);
scrollView.addChild(button_scale9);
}
}
});