Merge branch 'layout' of https://github.com/qfluxstudio/helium into layout

This commit is contained in:
Elmārs Āboliņš 2021-07-03 21:13:05 +03:00
commit 9370c1f456
4 changed files with 33 additions and 15 deletions

View File

@ -60,18 +60,18 @@ function atlases:assign(element)
local elW = element.view.w
local elH = element.view.h
local canvas, quad, interQuad = self.atlases[canvasID]:assignElement(element)
local canvas, quad = self.atlases[canvasID]:assignElement(element)
if not canvas and self.atlases[canvasID].ideal_area < self.atlases[canvasID].taken_area*4 then
--print('refragmenting ;3')
self.atlases[canvasID]:refragment()
canvas, quad, interQuad = self.atlases[canvasID]:assignElement(element)
canvas, quad = self.atlases[canvasID]:assignElement(element)
if not canvas then
--print('ran out of space')
end
else
--print('wont refragment', createdAtlas.ideal_area, createdAtlas.taken_area)
end
return canvas, quad, interQuad
return canvas, quad, canvasID
end
function atlases:unassign(element)
@ -145,12 +145,9 @@ function atlas:assignElement(element)
if self.users[element] and self.users[element].quad and self.users[element].interQuad then
--update by reference owo
self.users[element].quad:setViewport((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH)
self.users[element].interQuad:setViewport(0, 0, elW, elH)
quad = self.users[element].quad
iquad = self.users[element].interQuad
else
quad = love.graphics.newQuad((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH, self.w, self.h)
iquad = love.graphics.newQuad(0, 0, elW, elH, sw, sh)
end
self.users[element] = {
@ -165,7 +162,7 @@ function atlas:assignElement(element)
self:markTiles(x, y, tileSizeX, tileSizeY)
self.taken_area = self.taken_area + ((tileSizeY*BLOCK_SIZE)*(tileSizeX*BLOCK_SIZE))
return self.canvas, self.users[element].quad, iquad
return self.canvas, self.users[element].quad
else
print('failed to allocate :X')
return false

View File

@ -8,6 +8,8 @@ local helium = require(path .. ".dummy")
local context = require(path.. ".core.stack")
local scene = require(path.. ".core.scene")
local currentCanvasID
---@class Element
local element = {}
element.__index = element
@ -55,6 +57,8 @@ function element:new(param, immediate, w, h, flags)
immediate = immediate or false,
--Whether this element has a canvas assigned
hasCanvas = false,
--Which canvas is it assigned to
currentCanvasIndex = nil,
--Current test render passes to be benchmarked
testRenderPasses = 20,
--
@ -197,7 +201,7 @@ end
local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad
function element:createCanvas()
self.canvas, self.quad = scene.activeScene.atlas:assign(self)
self.canvas, self.quad, self.settings.currentCanvasIndex = scene.activeScene.atlas:assign(self)
if not self.canvas then
self.settings.failedCanvas = true
@ -291,6 +295,18 @@ function element:externalRender()
self.settings.isSetup = true
end
local oldCanvasId
if self.settings.hasCanvas then
if self.settings.currentCanvasIndex == currentCanvasID then
--problem lol
self.settings.renderingParentCanvasIndex = currentCanvasID
self:reassignCanvas()
else
oldCanvasId = currentCanvasID
currentCanvasID = self.settings.currentCanvasIndex
end
end
if self.settings.needsRendering then
if self.settings.hasCanvas then
setCanvas(self.canvas)
@ -328,6 +344,7 @@ function element:externalRender()
lg.setScissor()
love.graphics.pop()
currentCanvasID = oldCanvasId
end
function element:externalUpdate()

View File

@ -112,6 +112,9 @@ function context:getCanvasIndex(forCanvas)
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
else
if forCanvas then
if self.element.settings.renderingParentCanvasIndex then
return self.element.settings.renderingParentCanvasIndex == 1 and 2 or 1
end
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
end
end

View File

@ -21,22 +21,23 @@ local input = require(path.. ".core.input")
return function(onClick, onRelease, onEnter, onExit, startOn, x, y, w, h)
local checkbox = state {
down = false,
toggled = not not startOn,
toggled = false,
over = false,
}
checkbox.toggled = startOn
input('clicked', function(x, y, w, h)
checkbox.down = true
if onClick then
onClick(x, y, w, h)
end
checkbox.down = true
return function(x, y, w, h)
if onRelease then
onRelease(x, y, w, h)
end
checkbox.toggled = not checkbox.toggled
checkbox.down = false
if onRelease then
onRelease(checkbox.toggled, y, w, h)
end
end
end)