mirror of https://github.com/axmolengine/axmol.git
Multiple items testcase
This commit is contained in:
parent
4054686903
commit
68713d2074
|
@ -481,6 +481,8 @@ var UIScrollViewDisableTest = UIMainLayer.extend({
|
||||||
});
|
});
|
||||||
|
|
||||||
var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
|
var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
|
||||||
|
_scrollView:null,
|
||||||
|
_itemNumber:1000,
|
||||||
init: function () {
|
init: function () {
|
||||||
if (this._super()) {
|
if (this._super()) {
|
||||||
var widgetSize = this._widget.getContentSize();
|
var widgetSize = this._widget.getContentSize();
|
||||||
|
@ -496,7 +498,7 @@ var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
|
||||||
var background = this._widget.getChildByName("background_Panel");
|
var background = this._widget.getChildByName("background_Panel");
|
||||||
|
|
||||||
// Create the scrollview
|
// Create the scrollview
|
||||||
var scrollView = new ccui.ScrollView();
|
var scrollView = this._scrollView = new ccui.ScrollView();
|
||||||
scrollView.setDirection(ccui.ScrollView.DIR_VERTICAL);
|
scrollView.setDirection(ccui.ScrollView.DIR_VERTICAL);
|
||||||
scrollView.setTouchEnabled(true);
|
scrollView.setTouchEnabled(true);
|
||||||
scrollView.setContentSize(cc.size(280, 150));
|
scrollView.setContentSize(cc.size(280, 150));
|
||||||
|
@ -505,10 +507,35 @@ var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
|
||||||
scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollView.height) / 2;
|
scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollView.height) / 2;
|
||||||
this._mainNode.addChild(scrollView);
|
this._mainNode.addChild(scrollView);
|
||||||
|
|
||||||
|
var labelText = new cc.LabelTTF("Texts", "Arial", 25);
|
||||||
|
var labelButton = new cc.LabelTTF("Buttons", "Arial", 25);
|
||||||
|
var labelS9sprite = new cc.LabelTTF("s9Sprites", "Arial", 25);
|
||||||
|
|
||||||
|
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 Texts = [];
|
||||||
var start = new ccui.Text("---start---", "Thonburi", 10);
|
var start = new ccui.Text("---start---", "Thonburi", 10);
|
||||||
var innerWidth = scrollView.width;
|
var innerWidth = scrollView.width;
|
||||||
var innerHeight = 1000 * start.height;
|
var innerHeight = n * start.height;
|
||||||
scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
|
scrollView.setInnerContainerSize(cc.size(innerWidth, innerHeight));
|
||||||
|
|
||||||
start.x = innerWidth / 2;
|
start.x = innerWidth / 2;
|
||||||
|
@ -516,15 +543,64 @@ var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
|
||||||
Texts[0] = start;
|
Texts[0] = start;
|
||||||
scrollView.addChild(start);
|
scrollView.addChild(start);
|
||||||
|
|
||||||
for(var i=1; i<2000; i++) {
|
for (var i = 1; i < n; i++) {
|
||||||
var text = new ccui.Text("This is a test label: " + i, "Thonburi", 10);
|
var text = new ccui.Text("This is a test label: " + i, "Thonburi", 10);
|
||||||
text.x = innerWidth / 2;
|
text.x = innerWidth / 2;
|
||||||
text.y = Texts[i - 1].getBottomBoundary() - text.height / 2;
|
text.y = Texts[i - 1].getBottomBoundary() - text.height / 2;
|
||||||
Texts[i] = text;
|
Texts[i] = text;
|
||||||
scrollView.addChild(Texts[i]);
|
scrollView.addChild(Texts[i]);
|
||||||
}
|
}
|
||||||
return true;
|
},
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
Loading…
Reference in New Issue