Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -----------------------------------------------------------------------------------------
- --
- -- main.lua
- --
- -----------------------------------------------------------------------------------------
- -- Your code here
- local composer = require("composer");
- local widget = require("widget");
- local json = require("json");
- composer.removeScene('scenes.menu')
- local scene = composer.newScene();
- function scene:show(event)
- local sceneGroup = self.view;
- -- создаём группу для ввода веса
- local contentGroup = display.newGroup();
- local function scrollListener(event)
- local phase = event.phase
- local direction = event.direction
- -- если долистает до конца - дойдет до лимита
- if event.limitReached then
- if "up" == direction then
- print("Reached Top Limit")
- elseif "down" == direction then
- print("Reached Bottom Limit")
- end
- end
- return true
- end
- -- создаем скролвью
- local scrollView = widget.newScrollView
- {
- left = 0,
- top = 0,
- width = display.contentWidth,
- height = display.contentHeight,
- topPadding = 50,
- bottomPadding = 50,
- horizontalScrollDisabled = true,
- verticalScrollDisabled = false,
- listener = scrollListener,
- }
- local contentGroup = display.newGroup()
- -- рисую первую карточку
- local backgrRect = display.newRect(contentGroup, 0, 5, display.contentWidth, 110 ):setFillColor(0.4)
- local textTitle = "dfdsf"
- local textTitleObject = display.newText(contentGroup, textTitle, 110, -20, 300, 50, "Helvetica", 20)
- local textDescr = "dfdsf sf df we fwef wefwefwef wef we fwe we wef we we few we we wef wef wef we fwe fwe fwe fwej wjef wej fiwoej fiowej fiwej fowiej foiwje fiowje foiwjef oiwej iofwej fiowje iofjweio fjweio fjwoiej fwioej owiejf oiwej oiwej fiowejf iowejf iofewj fiowjefo ifjweio jfweio jiowej iowefj fiowej oifwejf oifwejio ffjweofi jfweo jwoej eoiwjf oiwje iowjeo ifjwefio jfweoi jewoifj fwoefjf wio"
- local textDecsrObject = display.newText(contentGroup, textDescr, 60, 25, 200, 50, "Helvetica", 14)
- local imageContent = display.newImageRect(contentGroup, "img/img1.jpg", 100, 100);
- imageContent.x = -display.contentWidth/3
- imageContent.y = 5
- -- lotsOfTextObject:setTextColor(0)
- contentGroup.x = display.contentCenterX
- scrollView:insert(contentGroup)
- local function coroutineDraw()
- --логика создания карточки тут
- for i = 1,20 do
- local contentGroup = display.newGroup()
- local backgrRect = display.newRect(contentGroup, 0, 5, display.contentWidth, 110 ):setFillColor(0.4)
- local textTitle = "dfdsf"
- local textTitleObject = display.newText(contentGroup, textTitle, 110, -20, 300, 50, "Helvetica", 20)
- local textDescr = "dfdsf sf df we fwef wefwefwef wef we fwe we wef we we few we we wef wef wef we fwe fwe fwe fwej wjef wej fiwoej fiowej fiwej fowiej foiwje fiowje foiwjef oiwej iofwej fiowje iofjweio fjweio fjwoiej fwioej owiejf oiwej oiwej fiowejf iowejf iofewj fiowjefo ifjweio jfweio jiowej iowefj fiowej oifwejf oifwejio ffjweofi jfweo jwoej eoiwjf oiwje iowjeo ifjwefio jfweoi jewoifj fwoefjf wio"
- local textDecsrObject = display.newText(contentGroup, textDescr, 60, 25, 200, 50, "Helvetica", 14)
- local imageContent = display.newImageRect(contentGroup, "img/img1.jpg", 100, 100);
- imageContent.x = -display.contentWidth/3
- imageContent.y = 5
- -- lotsOfTextObject:setTextColor(0)
- contentGroup.x = display.contentCenterX
- contentGroup.y = (110+10)*i
- scrollView:insert(contentGroup)
- coroutine.yield()
- end
- end
- local loadingCoroutineData
- loadingCoroutineData = {
- clear = function()
- if (loadingCoroutineData.co == nil) then return end
- print("loadingCoroutineData clear")
- Runtime:removeEventListener("enterFrame", loadingCoroutineData)
- loadingCoroutineData.co = nil
- loadingCoroutineData.enterFrame = nil
- end
- }
- local function renderSomething()
- loadingCoroutineData.clear()
- loadingCoroutineData.co = coroutine.create(coroutineDraw)
- --захардкоженное значение: лучше вернуть возвращать из coroutine.yield координаты
- --нижней точки текущей карточки, чтобы определить что мы заполнили видимую часть скрола
- for i = 1, 5 do
- local res, err = coroutine.resume(loadingCoroutineData.co)
- if (not res) then
- print("coroutine.resume", res, err)
- loadingCoroutineData.co = nil
- return
- end
- end
- --продолжаем рисовать каждый кадр
- loadingCoroutineData.enterFrame = function()
- print("====loadingCoroutineData====")
- local t = os.clock()
- local res, err
- repeat
- res, err = coroutine.resume(loadingCoroutineData.co)
- print("resume ", res, os.clock() - t)
- until (not res or (os.clock() - t) > 0.015) --тут 15ms задержки, для плавности можно уменьшить это число
- if (not res) then
- print("coroutine ended", res, err)
- loadingCoroutineData.clear()
- end
- end
- Runtime:addEventListener("enterFrame", loadingCoroutineData)
- end
- end
- scene:addEventListener("show", scene)
- return scene
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement