issue #9986:Add lua bindings for Component and related test cases

This commit is contained in:
samuele3hu 2015-01-14 16:58:35 +08:00
parent 6850c7497b
commit 77912270f9
5 changed files with 338 additions and 1 deletions

View File

@ -179,3 +179,17 @@ ccui.TextType = {
SYSTEM = 0,
TTF = 1,
}
ccui.LayoutComponent.HorizontalEdge = {
None = 0,
Left = 1,
Right = 2,
Center = 3,
}
ccui.LayoutComponent.VerticalEdge = {
None = 0,
Bottom = 1,
Top = 2,
Center = 3,
}

View File

@ -2102,6 +2102,204 @@ function UIPanelLayoutLinearHorizontalTest.create()
return scene
end
local UILayoutComponentBerthTest = class("UILayoutComponentBerthTest",UIScene)
function UILayoutComponentBerthTest.extend(target)
local t = tolua.getpeer(target)
if not t then
t = {}
tolua.setpeer(target, t)
end
setmetatable(t, UILayoutComponentBerthTest)
return target
end
function UILayoutComponentBerthTest:initExtend()
self:init()
local widgetSize = self._widget:getContentSize()
local baseLayer = cc.LayerColor:create()
baseLayer:setColor(cc.c3b(50, 100, 0))
baseLayer:setOpacity(100)
baseLayer:setContentSize(cc.size(200, 200))
self._uiLayer:addChild(baseLayer)
button = ccui.Button:create("cocosui/animationbuttonnormal.png")
print(string.format("content size should be greater than 0: width = %f, height = %f", button:getContentSize().width,
button:getContentSize().height))
button:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))
button:addTouchEventListener(function(sender, eventType)
if eventType == ccui.TouchEventType.began then
elseif eventType == ccui.TouchEventType.moved then
elseif eventType == ccui.TouchEventType.ended then
local touchWidgetSize = self._widget:getContentSize()
local layerSize = baseLayer:getContentSize()
if (layerSize.width == touchWidgetSize.width and layerSize.height == touchWidgetSize.height) then
baseLayer:setContentSize(cc.size(200, 200))
else
baseLayer:setContentSize(widgetSize)
end
ccui.Helper:doLayout(baseLayer)
else
end
end)
button:setZoomScale(0.4)
button:setPressedActionEnabled(true)
self._uiLayer:addChild(button)
local leftTopSprite = cc.Sprite:create("cocosui/CloseSelected.png")
local leftTop = ccui.LayoutComponent:bindLayoutComponent(leftTopSprite)
leftTop:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Left)
leftTop:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Top)
baseLayer:addChild(leftTopSprite)
local leftBottomSprite = cc.Sprite:create("cocosui/CloseSelected.png")
local leftBottom = ccui.LayoutComponent:bindLayoutComponent(leftBottomSprite)
leftBottom:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Left)
leftBottom:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Bottom)
baseLayer:addChild(leftBottomSprite)
local rightTopSprite = cc.Sprite:create("cocosui/CloseSelected.png")
local rightTop = ccui.LayoutComponent:bindLayoutComponent(rightTopSprite)
rightTop:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Right)
rightTop:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Top)
baseLayer:addChild(rightTopSprite)
local rightBottomSprite = cc.Sprite:create("cocosui/CloseSelected.png")
local rightBottom = ccui.LayoutComponent:bindLayoutComponent(rightBottomSprite)
rightBottom:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Right)
rightBottom:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Bottom)
baseLayer:addChild(rightBottomSprite)
ccui.Helper:doLayout(baseLayer)
end
function UILayoutComponentBerthTest.create()
local scene = cc.Scene:create()
local layer = UILayoutComponentBerthTest.extend(cc.Layer:create())
layer:initExtend()
scene:addChild(layer)
return scene
end
local UILayoutComponentBerthStretchTest = class("UILayoutComponentBerthStretchTest",UIScene)
function UILayoutComponentBerthStretchTest.extend(target)
local t = tolua.getpeer(target)
if not t then
t = {}
tolua.setpeer(target, t)
end
setmetatable(t, UILayoutComponentBerthStretchTest)
return target
end
function UILayoutComponentBerthStretchTest:initExtend()
self:init()
local widgetSize = self._widget:getContentSize()
local baseLayer = cc.LayerColor:create()
baseLayer:setColor(cc.c3b(50, 100, 0))
baseLayer:setOpacity(100)
baseLayer:setContentSize(cc.size(200, 200))
self._uiLayer:addChild(baseLayer)
button = ccui.Button:create("cocosui/animationbuttonnormal.png")
print(string.format("content size should be greater than 0: width = %f, height = %f", button:getContentSize().width,
button:getContentSize().height))
button:setPosition(cc.p(widgetSize.width / 2.0, widgetSize.height / 2.0))
button:addTouchEventListener(function(sender, eventType)
if eventType == ccui.TouchEventType.began then
elseif eventType == ccui.TouchEventType.moved then
elseif eventType == ccui.TouchEventType.ended then
local touchWidgetSize = self._widget:getContentSize()
local layerSize = baseLayer:getContentSize()
if (layerSize.width == touchWidgetSize.width and layerSize.height == touchWidgetSize.height) then
baseLayer:setContentSize(cc.size(200, 200))
else
baseLayer:setContentSize(widgetSize)
end
ccui.Helper:doLayout(baseLayer)
else
end
end)
button:setZoomScale(0.4)
button:setPressedActionEnabled(true)
self._uiLayer:addChild(button)
local leftTopSprite = ccui.ImageView:create("cocosui/CloseSelected.png")
leftTopSprite:ignoreContentAdaptWithSize(false)
local leftTop = ccui.LayoutComponent:bindLayoutComponent(leftTopSprite)
leftTop:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Left)
leftTop:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Top)
leftTop:setStretchWidthEnabled(true)
leftTop:setStretchHeightEnabled(true)
baseLayer:addChild(leftTopSprite)
leftTop:setSize(leftTopSprite:getContentSize())
leftTop:setLeftMargin(0)
leftTop:setTopMargin(0)
local leftBottomSprite = ccui.ImageView:create("cocosui/CloseSelected.png")
leftBottomSprite:ignoreContentAdaptWithSize(false)
local leftBottom = ccui.LayoutComponent:bindLayoutComponent(leftBottomSprite)
leftBottom:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Left)
leftBottom:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Bottom)
leftBottom:setStretchWidthEnabled(true)
leftBottom:setStretchHeightEnabled(true)
baseLayer:addChild(leftBottomSprite)
leftBottom:setSize(leftBottomSprite:getContentSize())
leftBottom:setLeftMargin(0)
leftBottom:setBottomMargin(0)
local rightTopSprite = ccui.ImageView:create("cocosui/CloseSelected.png")
rightTopSprite:ignoreContentAdaptWithSize(false)
local rightTop = ccui.LayoutComponent:bindLayoutComponent(rightTopSprite)
rightTop:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Right)
rightTop:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Top)
rightTop:setStretchWidthEnabled(true)
rightTop:setStretchHeightEnabled(true)
baseLayer:addChild(rightTopSprite)
rightTop:setSize(rightTopSprite:getContentSize())
rightTop:setTopMargin(0)
rightTop:setRightMargin(0)
local rightBottomSprite = ccui.ImageView:create("cocosui/CloseSelected.png")
rightBottomSprite:ignoreContentAdaptWithSize(false)
local rightBottom = ccui.LayoutComponent:bindLayoutComponent(rightBottomSprite)
rightBottom:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Right)
rightBottom:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Bottom)
rightBottom:setStretchWidthEnabled(true)
rightBottom:setStretchHeightEnabled(true)
baseLayer:addChild(rightBottomSprite)
rightBottom:setSize(rightBottomSprite:getContentSize())
rightBottom:setBottomMargin(0)
rightBottom:setRightMargin(0)
ccui.Helper:doLayout(baseLayer)
end
function UILayoutComponentBerthStretchTest.create()
local scene = cc.Scene:create()
local layer = UILayoutComponentBerthStretchTest.extend(cc.Layer:create())
layer:initExtend()
scene:addChild(layer)
return scene
end
local UIScrollViewVerticalTest = class("UIScrollViewVerticalTest",UIScene)
UIScrollViewVerticalTest._displayValueLabel = nil
@ -4049,6 +4247,20 @@ local cocoStudioGuiArray =
end,
},
{
title = "UILayoutComponentBerthTest",
func = function()
return UILayoutComponentBerthTest.create()
end
},
{
title = "UILayoutComponentBerthStretchTest",
func = function()
return UILayoutComponentBerthStretchTest.create()
end
},
{
title = "UIScrollViewVerticalTest",
func = function ( )

View File

@ -649,6 +649,66 @@ local function runLayoutEditorTestScene()
LayoutEditorTest.create()
end
local LayoutComponentTest = class("LayoutComponentTest",UIScene)
LayoutComponentTest._displayValueLabel = nil
function LayoutComponentTest.extend(target)
local t = tolua.getpeer(target)
if not t then
t = {}
tolua.setpeer(target, t)
end
setmetatable(t, LayoutComponentTest)
return target
end
function LayoutComponentTest:configureGUIScene()
local screenSize = cc.Director:getInstance():getWinSize()
self._displayValueLabel = ccui.Text:create("UILayoutComponentTest_Editor", "", 20)
self._displayValueLabel:setPosition(cc.p(screenSize.width / 2, screenSize.height - self._displayValueLabel:getContentSize().height / 2))
self._uiLayer:addChild(self._displayValueLabel)
local back_label = ccui.Text:create("Back", "", 20)
back_label:setTouchEnabled(true)
local labelLayout = ccui.LayoutComponent:bindLayoutComponent(back_label)
labelLayout:setHorizontalEdge(ccui.LayoutComponent.HorizontalEdge.Right)
labelLayout:setVerticalEdge(ccui.LayoutComponent.VerticalEdge.Bottom)
back_label:addTouchEventListener(function(sender, eventType)
if eventType == ccui.TouchEventType.ended then
self:unscheduleUpdate()
runCocoStudioUIEditorTestScene()
end
end)
self._layout:addChild(back_label)
end
function LayoutComponentTest:initExtend()
self:init()
local screenSize = cc.Director:getInstance():getWinSize()
self._layout = ccui.Layout:create()
self._uiLayer:addChild(self._layout)
self._layout:setContentSize(screenSize)
local node = cc.CSLoader:createNode("cocosui/UIEditorTest/UILayout/LayoutComponent/Scene.csb")
node:setContentSize(screenSize)
self._layout:addChild(node)
self:configureGUIScene()
ccui.Helper:doLayout(self._layout)
end
function LayoutComponentTest.create()
local scene = cc.Scene:create()
local layer = LayoutComponentTest.extend(cc.Layer:create())
layer:initExtend()
scene:addChild(layer)
cc.Director:getInstance():replaceScene(scene)
end
local function runLayoutComponentTestScene()
LayoutComponentTest.create()
end
local ScrollViewEditorTest = class("ScrollViewEditorTest",UIScene)
ScrollViewEditorTest._displayValueLabel = nil
@ -927,6 +987,13 @@ local UIEditorTestItemNames =
end
},
{
itemTitle = "gui Editor UILayoutComponentTest",
testScene = function ()
runLayoutComponentTestScene()
end
},
{
itemTitle = "gui Editor ScrollViewTest",
testScene = function ()

View File

@ -54,6 +54,28 @@ local function addSearchPath(resPrefix, height)
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/TmxMapComponentTest")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/UIComponentTest")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/scenetest/TriggerTest")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIButton")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UICheckBox")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIImageView")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILabel")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILabelBMFont")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILayout/BackgroundImage")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILayout/Color")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILayout/Layout")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILayout/Gradient_Color")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILayout/LayoutComponent")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UILoadingBar")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIPageView")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Both")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Horizontal")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIScrollView/Vertical")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UISlider")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UITextField")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIWidgetAddNode")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/hd/cocosui/UIEditorTest/UIListView/New")
table.insert(searchPaths, 1, resPrefix .. "hd/ActionTimeline")
else
table.insert(searchPaths, 1, resPrefix .. "ccs-res/Images")
@ -67,6 +89,28 @@ local function addSearchPath(resPrefix, height)
table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/TmxMapComponentTest")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/UIComponentTest")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/scenetest/TriggerTest")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIButton")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UICheckBox")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIImageView")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILabel")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILabelBMFont")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILayout/BackgroundImage")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILayout/Color")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILayout/Layout")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILayout/Gradient_Color")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILayout/Scale9_BackgroundImage")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILayout/LayoutComponent")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UILoadingBar")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIPageView")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIScrollView/Both")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIScrollView/Horizontal")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIScrollView/Vertical")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UISlider")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UITextField")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIWidgetAddNode")
table.insert(searchPaths, 1, resPrefix .. "ccs-res/cocosui/UIEditorTest/UIListView/New")
table.insert(searchPaths, 1, resPrefix .. "ActionTimeline")
end

View File

@ -30,7 +30,7 @@ headers = %(cocosdir)s/cocos/ui/CocosGUI.h
# what classes to produce code for. You can use regular expressions here. When testing the regular
# expression, it will be enclosed in "^$", like this: "^Menu*$".
classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox Scale9Sprite EditBox
classes = Helper Widget Layer Layout RootWidget Button CheckBox ImageView Text TextAtlas TextBMFont LoadingBar Slider Switch TextField ScrollView ListView PageView LayoutParameter LinearLayoutParameter RelativeLayoutParameter Rich.* HBox VBox RelativeBox Scale9Sprite EditBox LayoutComponent
# what should we skip? in the format ClassName::[function function]
# ClassName is a regular expression, but will be used like this: "^ClassName$" functions are also