From c0dc8b06374fdef741f32bbe7086f64a558ed7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B5=D1=81=D1=88=D0=B0=D0=BF=D0=BE=D1=88=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 8 Apr 2016 11:14:45 +0300 Subject: [PATCH 1/4] Add scroll view bar js test --- tests/js-tests/src/GUITest/UISceneManager.js | 6 +++ .../UIScrollViewTest/UIScrollViewTest.js | 46 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/js-tests/src/GUITest/UISceneManager.js b/tests/js-tests/src/GUITest/UISceneManager.js index 1090c5efa9..e1067915d9 100644 --- a/tests/js-tests/src/GUITest/UISceneManager.js +++ b/tests/js-tests/src/GUITest/UISceneManager.js @@ -477,6 +477,12 @@ func: function () { return new UIScrollViewTest_Vertical_Multiple(); } + }, + { + title:"UIScrollView Scroll Bar Test", + func: function () { + return new UIScrollViewTest_ScrollBar(); + } } ], "UIPageView": [ diff --git a/tests/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js b/tests/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js index 0ea3fe81db..f5b712264c 100644 --- a/tests/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js +++ b/tests/js-tests/src/GUITest/UIScrollViewTest/UIScrollViewTest.js @@ -603,4 +603,48 @@ var UIScrollViewTest_Vertical_Multiple = UIMainLayer.extend({ scrollView.addChild(button_scale9); } } -}); \ No newline at end of file +}); + +var UIScrollViewTest_ScrollBar = UIMainLayer.extend({ + init: function () { + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + //init text + this._topDisplayLabel.setString("Scroll bar is red, 65% opacity, auto hide time: 5 sec"); + this._topDisplayLabel.setFontSize(14); + this._topDisplayLabel.x = widgetSize.width / 2.0; + this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; + + this._bottomDisplayLabel.setString(""); + this._bottomDisplayLabel.x = widgetSize.width / 2; + this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; + + var background = this._widget.getChildByName("background_Panel"); + + // Create the scrollview + var scrollView = new ccui.ScrollView(); + scrollView.setTouchEnabled(true); + scrollView.setBounceEnabled(true); + scrollView.setBackGroundColor(cc.color.GREEN); + scrollView.setBackGroundColorType(ccui.Layout.BG_COLOR_SOLID); + scrollView.setDirection(ccui.ScrollView.DIR_BOTH); + scrollView.setInnerContainerSize(cc.size(480, 320)); + scrollView.setContentSize(cc.size(100, 100)); + var scrollViewSize = scrollView.getContentSize(); + + scrollView.x = (widgetSize.width - background.width) / 2 + (background.width - scrollViewSize.width) / 2; + scrollView.y = (widgetSize.height - background.height) / 2 + (background.height - scrollViewSize.height) / 2; + + this._mainNode.addChild(scrollView); + + scrollView.setScrollBarAutoHideTime(5); + scrollView.setScrollBarColor(cc.color.RED); + scrollView.setScrollBarOpacity(255 * 0.65); + scrollView.setScrollBarWidth(5); + + return true; + } + return false; + } +}); + From dbd2b5fd0368dc87171a043ba426c7914878dddb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B5=D1=81=D1=88=D0=B0=D0=BF=D0=BE=D1=88=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 8 Apr 2016 13:40:21 +0300 Subject: [PATCH 2/4] Add ListView js tests --- .../GUITest/UIListViewTest/UIListViewTest.js | 255 ++++++++++++++++++ tests/js-tests/src/GUITest/UISceneManager.js | 24 ++ 2 files changed, 279 insertions(+) diff --git a/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js b/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js index 62f75f09d4..83f551158a 100644 --- a/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js +++ b/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js @@ -350,3 +350,258 @@ var UIListViewTest_TouchIntercept = UIMainLayer.extend({ return false; } }); + +var UIListViewTest_ScrollToItem = UIMainLayer.extend({ + _nextIndex: 0, + init: function () { + if(this._super()) { + var widgetSize = this._widget.getContentSize(); + var background = this._widget.getChildByName("background_Panel"); + var backgroundSize = background.getContentSize(); + + this._topDisplayLabel.setString(""); + this._topDisplayLabel.x = widgetSize.width / 2.0; + this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 1.5; + this._bottomDisplayLabel.setString(""); + this._bottomDisplayLabel.x = widgetSize.width / 2; + this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; + + // Create the list view + var listView = new ccui.ListView(); + // set list view ex direction + listView.setDirection(this._getListViewDirection()); + listView.setBounceEnabled(true); + listView.setBackGroundImage("ccs-res/cocosui/green_edit.png"); + listView.setBackGroundImageScale9Enabled(true); + listView.setContentSize(widgetSize.width / 2, widgetSize.height / 2); + listView.setScrollBarPositionFromCorner(cc.p(7, 7)); + listView.setItemsMargin(2.0); + + listView.x = (widgetSize.width - backgroundSize.width) / 2 + (backgroundSize.width - listView.width) / 2; + listView.y = (widgetSize.height - backgroundSize.height) / 2 + (backgroundSize.height - listView.height) / 2; + this._mainNode.addChild(listView); + + { + var pNode = new cc.DrawNode(); + + var center = cc.p(widgetSize.width / 2, widgetSize.height / 2); + if(this._getListViewDirection() == ccui.ScrollView.DIR_HORIZONTAL) + { + var halfY = 110; + pNode.drawLine(cc.p(center.x, center.y - halfY), cc.p(center.x, center.y + halfY), cc.color(0, 0, 0, 255)); + } + else + { + var halfX = 150; + pNode.drawLine(cc.p(center.x - halfX, center.y), cc.p(center.x + halfX, center.y), cc.color(0, 0, 0, 255)); + } + pNode.setLineWidth(2); + pNode.setContentSize(listView.getContentSize()); + this._mainNode.addChild(pNode); + } + + var NUMBER_OF_ITEMS = 31; + + // Button + var pButton = new ccui.Button("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png"); + pButton.setAnchorPoint(cc.p(0, 0.5)); + pButton.setScale(0.8); + pButton.setPosition(cc.pAdd(cc.p(widgetSize.width / 2, widgetSize.height / 2), cc.p(120, -60))); + pButton.setTitleText("Go to '" +this._nextIndex + "'"); + pButton.addClickEventListener(function(pButton) { + listView.scrollToItem(this._nextIndex, cc.p(0.5, 0.5), cc.p(0.5, 0.5)); + this._nextIndex = (this._nextIndex + Math.floor(NUMBER_OF_ITEMS / 2)) % NUMBER_OF_ITEMS; + pButton.setTitleText("Go to '" + this._nextIndex+ "'"); + }.bind(this)); + this._mainNode.addChild(pButton); + + // Add list items + var BUTTON_SIZE = cc.size(50, 40); + + for (var i = 0; i < NUMBER_OF_ITEMS; ++i) + { + var pButton = new ccui.Button("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png"); + pButton.setContentSize(BUTTON_SIZE); + pButton.setScale9Enabled(true); + pButton.setTitleText("Button-" + i); + listView.pushBackCustomItem(pButton); + } + + return true; + } + return false; + }, + _getListViewDirection: function() + { + + } +}); + +var UIListViewTest_ScrollToItemVertical = UIListViewTest_ScrollToItem.extend({ + _getListViewDirection: function() + { + return ccui.ScrollView.DIR_VERTICAL; + } +}); + +var UIListViewTest_ScrollToItemHorizontal = UIListViewTest_ScrollToItem.extend({ + _getListViewDirection: function() + { + return ccui.ScrollView.DIR_HORIZONTAL; + } +}); + +var UIListViewTest_Magnetic = UIMainLayer.extend({ + _listView: null, + init: function () { + if(this._super()) { + var widgetSize = this._widget.getContentSize(); + var background = this._widget.getChildByName("background_Panel"); + var backgroundSize = background.getContentSize(); + + this._indexLabels= []; + + this._topDisplayLabel.setString("1"); + this._topDisplayLabel.setFontSize(14); + this._topDisplayLabel.x = widgetSize.width / 2.0; + this._topDisplayLabel.y = widgetSize.height / 2 + 90; + this._bottomDisplayLabel.setString(""); + this._bottomDisplayLabel.x = widgetSize.width / 2; + this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; + + // Create the list view + this._listView = new ccui.ListView(); + // set list view ex direction + this._listView.setDirection(this._getListViewDirection()); + this._listView.setTouchEnabled(true); + this._listView.setBounceEnabled(true); + this._listView.setBackGroundImage("ccs-res/cocosui/green_edit.png"); + this._listView.setBackGroundImageScale9Enabled(true); + this._listView.setContentSize(widgetSize.width / 2, widgetSize.height / 2); + this._listView.setScrollBarPositionFromCorner(cc.p(7, 7)); + this._listView.setItemsMargin(2.0); + this._listView.setAnchorPoint(cc.p(0.5 ,0.5)); + + this._listView.x = widgetSize.width / 2; + this._listView.y = widgetSize.height / 2; + + this._mainNode.addChild(this._listView); + + { + var pNode = new cc.DrawNode(); + + var center = cc.p(widgetSize.width / 2, widgetSize.height / 2); + if(this._getListViewDirection() == ccui.ScrollView.DIR_HORIZONTAL) + { + var halfY = 110; + pNode.drawLine(cc.p(center.x, center.y - halfY), cc.p(center.x, center.y + halfY), cc.color(0, 0, 0, 255)); + } + else + { + var halfX = 150; + pNode.drawLine(cc.p(center.x - halfX, center.y), cc.p(center.x + halfX, center.y), cc.color(0, 0, 0, 255)); + } + pNode.setLineWidth(2); + pNode.setContentSize(this._listView.getContentSize()); + this._mainNode.addChild(pNode); + } + + // Initial magnetic type + this._listView.setMagneticType(ccui.ListView.MAGNETIC_NONE); + this._topDisplayLabel.setString("MagneticType - NONE"); + + // Magnetic change button + var pButton = new ccui.Button("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png"); + pButton.setAnchorPoint(cc.p(0.5, 0.5)); + pButton.setScale(0.8); + pButton.setPosition(cc.pAdd(cc.p(widgetSize.width / 2, widgetSize.height / 2), cc.p(130, -60))); + pButton.setTitleText("Next Magnetic"); + pButton.addClickEventListener(function() { + var eCurrentType = this._listView.getMagneticType(); + var eNextType; + var sString; + if(eCurrentType == ccui.ListView.MAGNETIC_NONE) + { + eNextType = ccui.ListView.MAGNETIC_CENTER; + sString = "CENTER"; + } + else if(eCurrentType == ccui.ListView.MAGNETIC_CENTER) + { + eNextType = ccui.ListView.MAGNETIC_BOTH_END; + sString = "BOTH_END"; + } + else if(eCurrentType == ccui.ListView.MAGNETIC_BOTH_END) + { + if(this._getListViewDirection() == ccui.ScrollView.DIR_HORIZONTAL) + { + eNextType = ccui.ListView.MAGNETIC_LEFT; + sString = "LEFT"; + } + else + { + eNextType = ccui.ListView.MAGNETIC_TOP; + sString = "TOP"; + } + } + else if(eCurrentType == ccui.ListView.MAGNETIC_LEFT) + { + eNextType = ccui.ListView.MAGNETIC_RIGHT; + sString = "RIGHT"; + } + else if(eCurrentType == ccui.ListView.MAGNETIC_RIGHT) + { + eNextType = ccui.ListView.MAGNETIC_NONE; + sString = "NONE"; + } + else if(eCurrentType == ccui.ListView.MAGNETIC_TOP) + { + eNextType = ccui.ListView.MAGNETIC_BOTTOM; + sString = "BOTTOM"; + } + else if(eCurrentType == ccui.ListView.MAGNETIC_BOTTOM) + { + eNextType = ccui.ListView.MAGNETIC_NONE; + sString = "NONE"; + } + this._listView.setMagneticType(eNextType); + + this._topDisplayLabel.setString("MagneticType - " + sString); + }.bind(this)); + this._mainNode.addChild(pButton); + + // Add list items + var BUTTON_SIZE = cc.size(50, 40); + + for (var i = 0; i < 40; ++i) + { + var pButton = new ccui.Button("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png"); + pButton.setContentSize(BUTTON_SIZE); + pButton.setScale9Enabled(true); + pButton.setTitleText("Button-" + i); + this._listView.pushBackCustomItem(pButton); + } + + return true; + } + return false; + }, + + _getListViewDirection: function() + { + + } +}); + +var UIListViewTest_MagneticVertical = UIListViewTest_Magnetic.extend({ + _getListViewDirection: function() + { + return ccui.ScrollView.DIR_VERTICAL; + } +}); + +var UIListViewTest_MagneticHorizontal = UIListViewTest_Magnetic.extend({ + _getListViewDirection: function() + { + return ccui.ScrollView.DIR_HORIZONTAL; + } +}); \ No newline at end of file diff --git a/tests/js-tests/src/GUITest/UISceneManager.js b/tests/js-tests/src/GUITest/UISceneManager.js index e1067915d9..2d9cd3333d 100644 --- a/tests/js-tests/src/GUITest/UISceneManager.js +++ b/tests/js-tests/src/GUITest/UISceneManager.js @@ -541,6 +541,30 @@ func: function() { return new UIListViewTest_TouchIntercept(); } + }, + { + title:"UIListViewTest Scroll to item vertical", + func: function() { + return new UIListViewTest_ScrollToItemVertical(); + } + }, + { + title:"UIListViewTest Scroll to item horizontal", + func: function() { + return new UIListViewTest_ScrollToItemHorizontal(); + } + }, + { + title:"UIListViewTest magnetic vertical", + func: function() { + return new UIListViewTest_MagneticVertical(); + } + }, + { + title:"UIListViewTest magnetic horizontal", + func: function() { + return new UIListViewTest_MagneticHorizontal(); + } } ], "UIWidget": [ From c7bea705aff40212858ad4dfdee95b20743d635e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B5=D1=81=D1=88=D0=B0=D0=BF=D0=BE=D1=88=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 8 Apr 2016 14:01:20 +0300 Subject: [PATCH 3/4] Add PageView js tests --- .../GUITest/UIPageViewTest/UIPageViewTest.js | 146 ++++++++++++++++++ tests/js-tests/src/GUITest/UISceneManager.js | 12 ++ 2 files changed, 158 insertions(+) diff --git a/tests/js-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js b/tests/js-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js index c0bf09af1c..d29d5a8ccd 100644 --- a/tests/js-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js +++ b/tests/js-tests/src/GUITest/UIPageViewTest/UIPageViewTest.js @@ -586,3 +586,149 @@ var UIPageViewDisableTouchTest = UIMainLayer.extend({ return false; } }); + +var UIPageViewJumpToPageTest = UIMainLayer.extend({ + init: function () { + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + //init text + this._topDisplayLabel.setString("setCurrentPageIndex API Test"); + this._topDisplayLabel.setFontSize(14); + this._topDisplayLabel.x = widgetSize.width / 2.0; + this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 4; + this._bottomDisplayLabel.setString(""); + this._bottomDisplayLabel.x = widgetSize.width / 2; + this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; + + var background = this._widget.getChildByName("background_Panel"); + + // Create the page view + var pageView = new ccui.PageView(); + pageView.setTouchEnabled(true); + pageView.setContentSize(cc.size(240, 130)); + pageView.x = (widgetSize.width - background.width) / 2 + (background.width - pageView.width) / 2; + pageView.y = (widgetSize.height - background.height) / 2 + (background.height - pageView.height) / 2; + pageView.setIndicatorEnabled(true); + pageView.removeAllItems(); + + var pageCount = 4; + for (var i = 0; i < pageCount; ++i) + { + var layout = new ccui.Layout(); + layout.setContentSize(cc.size(240.0, 130.0)); + + var imageView = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png"); + imageView.setScale9Enabled(true); + imageView.setContentSize(cc.size(240, 130)); + imageView.setPosition(cc.p(layout.width / 2.0, layout.height / 2.0)); + layout.addChild(imageView); + + var label = new ccui.Text("page " + (i+1), "Arial", 30); + label.setColor(cc.color(192, 192, 192)); + label.setPosition(cc.p(layout.width / 2.0, layout.height / 2.0)); + layout.addChild(label); + + pageView.insertCustomItem(layout, i); + } + + pageView.setCurrentPageIndex(1); + //add buttons to jump to specific page + var button1 = new ccui.Button(); + button1.setPosition(cc.p(pageView.x - 50, pageView.y + pageView.height)); + button1.setTitleText("Jump to Page1"); + + button1.addClickEventListener(function(){ + pageView.setCurrentPageIndex(0); + }); + this._mainNode.addChild(button1); + + var button2 = button1.clone(); + button2.setTitleText("Jump to Page2"); + button2.setPosition(cc.p(pageView.x - 50, pageView.y + pageView.height - 50)); + button2.addClickEventListener(function(){ + pageView.setCurrentPageIndex(1); + }); + this._mainNode.addChild(button2); + + var button3 = button2.clone(); + button3.setTitleText("Jump to Page3"); + button3.setPosition(cc.p(pageView.x + pageView.width + 50, pageView.y + pageView.height)); + button3.addClickEventListener(function(){ + pageView.setCurrentPageIndex(2); + }); + this._mainNode.addChild(button3); + + var button4 = button3.clone(); + button4.setTitleText("Jump to Page4"); + button4.setPosition(cc.p(pageView.x + pageView.width + 50, pageView.y + pageView.height - 50)); + button4.addClickEventListener(function(){ + pageView.setCurrentPageIndex(3); + }); + this._mainNode.addChild(button4); + + this._mainNode.addChild(pageView); + + return true; + } + return false; + } +}); + +var UIPageViewChildSizeTest = UIMainLayer.extend({ + init: function () { + if (this._super()) { + var widgetSize = this._widget.getContentSize(); + //init text + this._topDisplayLabel.setString("Move by horizontal direction"); + this._topDisplayLabel.setFontSize(14); + this._topDisplayLabel.x = widgetSize.width / 2.0; + this._topDisplayLabel.y = widgetSize.height / 2.0 + this._topDisplayLabel.height * 4; + this._bottomDisplayLabel.setString(""); + this._bottomDisplayLabel.x = widgetSize.width / 2; + this._bottomDisplayLabel.y = widgetSize.height / 2 - this._bottomDisplayLabel.height * 3; + + var background = this._widget.getChildByName("background_Panel"); + + // Create the page view + var pageView = new ccui.PageView(); + pageView.setTouchEnabled(true); + pageView.setContentSize(cc.size(240, 130)); + pageView.x = (widgetSize.width - background.width) / 2 + (background.width - pageView.width) / 2; + pageView.y = (widgetSize.height - background.height) / 2 + (background.height - pageView.height) / 2; + pageView.setIndicatorEnabled(true); + pageView.removeAllItems(); + + var pageCount = 4; + for (var i = 0; i < pageCount; ++i) + { + var imageView = new ccui.ImageView("ccs-res/cocosui/scrollviewbg.png"); + var label = new ccui.Text("page " + (i + 1), "Arial", 30); + + imageView.setScale9Enabled(true); + label.setColor(cc.color(192, 192, 192)); + label.setAnchorPoint(cc.p(0,0)); + imageView.addChild(label); + + pageView.insertCustomItem(imageView, i); + } + + pageView.addEventListener(this.pageViewEvent, this); + + this._mainNode.addChild(pageView); + + return true; + } + return false; + }, + + pageViewEvent: function (sender, type) { + switch (type) { + case ccui.PageView.EVENT_TURNING: + var pageView = sender; + this._topDisplayLabel.setString("page = " + (pageView.getCurPageIndex().valueOf()-0 + 1)); + break; + default: + break; + } + } +}); diff --git a/tests/js-tests/src/GUITest/UISceneManager.js b/tests/js-tests/src/GUITest/UISceneManager.js index 2d9cd3333d..18b0cd4d04 100644 --- a/tests/js-tests/src/GUITest/UISceneManager.js +++ b/tests/js-tests/src/GUITest/UISceneManager.js @@ -521,6 +521,18 @@ func: function () { return new UIPageViewDisableTouchTest(); } + }, + { + title: "UIPageViewJumpToPageTest", + func: function () { + return new UIPageViewJumpToPageTest(); + } + }, + { + title: "UIPageViewChildSizeTest", + func: function () { + return new UIPageViewChildSizeTest(); + } } ], "UIListView": [ From 9459d2b67e0cc46912e1e61497f017654d8ebdf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=B5=D1=81=D1=88=D0=B0=D0=BF=D0=BE=D1=88=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=BE=D0=B2=20=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0?= Date: Fri, 8 Apr 2016 15:31:51 +0300 Subject: [PATCH 4/4] Fixed ccui.ListView Test --- .../GUITest/UIListViewTest/UIListViewTest.js | 67 ++++++++++++------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js b/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js index 83f551158a..4ac1b4ad14 100644 --- a/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js +++ b/tests/js-tests/src/GUITest/UIListViewTest/UIListViewTest.js @@ -388,20 +388,17 @@ var UIListViewTest_ScrollToItem = UIMainLayer.extend({ if(this._getListViewDirection() == ccui.ScrollView.DIR_HORIZONTAL) { var halfY = 110; - pNode.drawLine(cc.p(center.x, center.y - halfY), cc.p(center.x, center.y + halfY), cc.color(0, 0, 0, 255)); + pNode.drawSegment(cc.p(center.x, center.y - halfY), cc.p(center.x, center.y + halfY), 2, cc.color(0, 0, 0, 255)); } else { var halfX = 150; - pNode.drawLine(cc.p(center.x - halfX, center.y), cc.p(center.x + halfX, center.y), cc.color(0, 0, 0, 255)); + pNode.drawSegment(cc.p(center.x - halfX, center.y), cc.p(center.x + halfX, center.y), 2, cc.color(0, 0, 0, 255)); } - pNode.setLineWidth(2); pNode.setContentSize(listView.getContentSize()); this._mainNode.addChild(pNode); } - var NUMBER_OF_ITEMS = 31; - // Button var pButton = new ccui.Button("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png"); pButton.setAnchorPoint(cc.p(0, 0.5)); @@ -416,15 +413,28 @@ var UIListViewTest_ScrollToItem = UIMainLayer.extend({ this._mainNode.addChild(pButton); // Add list items - var BUTTON_SIZE = cc.size(50, 40); + var default_button = new ccui.Button(); + default_button.setName("TextButton"); + default_button.setTouchEnabled(true); + default_button.loadTextures("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png", ""); + + var default_item = new ccui.Layout(); + default_item.setTouchEnabled(true); + default_item.setContentSize(default_button.getContentSize()); + default_button.x = default_item.width / 2; + default_button.y = default_item.height / 2; + default_item.addChild(default_button); + + // set model + listView.setItemModel(default_item); + + // Add list items for (var i = 0; i < NUMBER_OF_ITEMS; ++i) { - var pButton = new ccui.Button("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png"); - pButton.setContentSize(BUTTON_SIZE); - pButton.setScale9Enabled(true); - pButton.setTitleText("Button-" + i); - listView.pushBackCustomItem(pButton); + var item = default_item.clone(); + item.getChildByName("TextButton").setTitleText("Button-" + i); + listView.pushBackCustomItem(item); } return true; @@ -459,8 +469,6 @@ var UIListViewTest_Magnetic = UIMainLayer.extend({ var background = this._widget.getChildByName("background_Panel"); var backgroundSize = background.getContentSize(); - this._indexLabels= []; - this._topDisplayLabel.setString("1"); this._topDisplayLabel.setFontSize(14); this._topDisplayLabel.x = widgetSize.width / 2.0; @@ -485,6 +493,8 @@ var UIListViewTest_Magnetic = UIMainLayer.extend({ this._listView.x = widgetSize.width / 2; this._listView.y = widgetSize.height / 2; + this._listView.setGravity(ccui.ListView.GRAVITY_CENTER_VERTICAL); + this._mainNode.addChild(this._listView); { @@ -494,14 +504,13 @@ var UIListViewTest_Magnetic = UIMainLayer.extend({ if(this._getListViewDirection() == ccui.ScrollView.DIR_HORIZONTAL) { var halfY = 110; - pNode.drawLine(cc.p(center.x, center.y - halfY), cc.p(center.x, center.y + halfY), cc.color(0, 0, 0, 255)); + pNode.drawSegment(cc.p(center.x, center.y - halfY), cc.p(center.x, center.y + halfY), 2, cc.color(0, 0, 0, 255)); } else { var halfX = 150; - pNode.drawLine(cc.p(center.x - halfX, center.y), cc.p(center.x + halfX, center.y), cc.color(0, 0, 0, 255)); + pNode.drawSegment(cc.p(center.x - halfX, center.y), cc.p(center.x + halfX, center.y), 2, cc.color(0, 0, 0, 255)); } - pNode.setLineWidth(2); pNode.setContentSize(this._listView.getContentSize()); this._mainNode.addChild(pNode); } @@ -569,16 +578,28 @@ var UIListViewTest_Magnetic = UIMainLayer.extend({ }.bind(this)); this._mainNode.addChild(pButton); - // Add list items - var BUTTON_SIZE = cc.size(50, 40); + var default_button = new ccui.Button(); + default_button.setName("TextButton"); + default_button.setTouchEnabled(true); + default_button.loadTextures("ccs-res/cocosui/backtotoppressed.png", "ccs-res/cocosui/backtotopnormal.png", ""); + + var default_item = new ccui.Layout(); + default_item.setTouchEnabled(true); + default_item.setContentSize(default_button.getContentSize()); + default_button.x = default_item.width / 2; + default_button.y = default_item.height / 2; + default_item.addChild(default_button); + + // set model + this._listView.setItemModel(default_item); + + // Add list items for (var i = 0; i < 40; ++i) { - var pButton = new ccui.Button("ccs-res/cocosui/button.png", "ccs-res/cocosui/buttonHighlighted.png"); - pButton.setContentSize(BUTTON_SIZE); - pButton.setScale9Enabled(true); - pButton.setTitleText("Button-" + i); - this._listView.pushBackCustomItem(pButton); + var item = default_item.clone(); + item.getChildByName("TextButton").setTitleText("Button-" + i); + this._listView.pushBackCustomItem(item); } return true;