mirror of https://github.com/axmolengine/axmol.git
Merge pull request #13962 from ZhangMenghe/v3-scrollView
[ci skip] Testcase for multiple items in scrollView
This commit is contained in:
commit
149775ea10
|
@ -471,6 +471,12 @@
|
|||
func: function () {
|
||||
return new UIScrollViewDisableTest();
|
||||
}
|
||||
},
|
||||
{
|
||||
title:"UIScrollView Multiple Items Test",
|
||||
func: function () {
|
||||
return new UIScrollViewTest_Vertical_Multiple();
|
||||
}
|
||||
}
|
||||
],
|
||||
"UIPageView": [
|
||||
|
|
|
@ -478,4 +478,129 @@ var UIScrollViewDisableTest = UIMainLayer.extend({
|
|||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({
|
||||
_scrollView:null,
|
||||
_itemNumber:1000,
|
||||
init: function () {
|
||||
if (this._super()) {
|
||||
var widgetSize = this._widget.getContentSize();
|
||||
//init text
|
||||
this._topDisplayLabel.setString("Move by vertical direction");
|
||||
this._topDisplayLabel.x = widgetSize.width / 2.0;
|
||||
this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5;
|
||||
this._bottomDisplayLabel.setString("Compare drawCalls and FPS with Previous Version");
|
||||
this._bottomDisplayLabel.setFontSize(25);
|
||||
this._bottomDisplayLabel.x = widgetSize.width / 2;
|
||||
this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 4;
|
||||
|
||||
var background = this._widget.getChildByName("background_Panel");
|
||||
|
||||
// Create the scrollview
|
||||
var scrollView = this._scrollView = new ccui.ScrollView();
|
||||
scrollView.setDirection(ccui.ScrollView.DIR_VERTICAL);
|
||||
scrollView.setTouchEnabled(true);
|
||||
scrollView.setContentSize(cc.size(280, 150));
|
||||
|
||||
scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollView.width) / 2;
|
||||
scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollView.height) / 2;
|
||||
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 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);
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue