Compare commits

..

No commits in common. "c40b3eb953827eaa38daec543546253c670f805b" and "0f99994ae302c8a7b4f3b979bd32b282f7953953" have entirely different histories.

8 changed files with 34 additions and 96 deletions

View File

@ -46,7 +46,6 @@ function element:new(param, immediate, w, h, flags)
isSetup = false,
pendingUpdate = true,
needsRendering = true,
active = true,
remove = false,
--Unused for now?
calculatedDimensions = true,
@ -286,13 +285,8 @@ function element:renderWrapper()
self.context:unset()
end
local lg = love.graphics
function element:externalRender()
if not self.settings.active then
return
end
local cnvs = getCanvas()
love.graphics.push('all')
@ -354,9 +348,6 @@ function element:externalRender()
end
function element:externalUpdate()
if not self.settings.active then
return
end
self.context:set()
self.context:zIndex()
if ((not self.settings.failedCanvas
@ -411,10 +402,6 @@ function element:draw(x, y, w, h)
if w then self.view.w = w end
if h then self.view.h = h end
if not self.settings.active then
self:redraw()
end
local cx = context.getContext()
if cx then
if cx:childRender(self) then
@ -442,23 +429,10 @@ end
---Destroys this element
function element:destroy()
self.settings.remove = true
self.settings.inserted = false
self.settings.active = false
self.settings.firstDraw = true
self.settings.isSetup = false
self:onDestroy()
self.context:destroy()
end
function element:redraw()
self.settings.active = true
self.context:redraw()
end
---Stops rendering, updates and draw
function element:undraw()
self.settings.active = false
self.context:undraw()
end
return element

View File

@ -59,11 +59,6 @@ love.handlers['mousemoved'] = function(x, y, dx, dy, e, f)
orig.mousemoved(x, y, dx, dy, e, f)
end
end
love.handlers['filedropped'] = function(file, y, dx, dy, e, f)
if not input.eventHandlers.filedropped(file, y, dx, dy, e, f) then
orig.filedropped(file, y, dx, dy, e, f)
end
end
local function sortFunc(t1, t2)
if t1 == t2 then
@ -212,7 +207,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
local captured = false
if input.subscriptions.clicked then
for index, sub in ipairs(input.subscriptions.clicked) do
if sub.currentEvent and sub.active and sub.stack.element.settings.active then
if sub.currentEvent then
sub.currentEvent = false
captured = true
if sub.cleanUp then
@ -224,7 +219,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
if input.subscriptions.dragged then
for index, sub in ipairs(input.subscriptions.dragged) do
if sub.currentEvent and sub.active and sub.stack.element.settings.active then
if sub.currentEvent then
sub.currentEvent = false
captured = true
if sub.cleanUp then
@ -236,7 +231,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
if input.subscriptions.mousereleased then
for index, sub in ipairs(input.subscriptions.mousereleased) do
if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
if sub.active and sub:checkInside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn)
captured = true
end
@ -246,7 +241,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
if input.subscriptions.mousereleased_outside then
for index, sub in ipairs(input.subscriptions.mousereleased_outside) do
if sub.active and sub.stack.element.settings.active and sub:checkOutside(x, y) then
if sub.active and sub:checkOutside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn)
captured = true
end
@ -264,7 +259,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
for index, sub in ipairs(input.subscriptions.clicked) do
local succ = sub:checkInside(x, y)
if succ and sub.active and sub.stack.element.settings.active then
if succ and sub.active then
sub.cleanUp = sub:emit(x-sub.x, y-sub.y, btn) or dummyfunc
sub.currentEvent = true
return true
@ -275,7 +270,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
if input.subscriptions.dragged then
for index, sub in ipairs(input.subscriptions.dragged) do
if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
if sub.active and sub:checkInside(x, y) then
sub.currentEvent = true
return true
end
@ -285,7 +280,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
if input.subscriptions.mousepressed then
for index, sub in ipairs(input.subscriptions.mousepressed) do
if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
if sub.active and sub:checkInside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn)
return true
end
@ -295,7 +290,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
if input.subscriptions.mousepressed_outside then
for index, sub in ipairs(input.subscriptions.mousepressed_outside) do
if sub.active and sub.stack.element.settings.active and sub:checkOutside(x, y) then
if sub.active and sub:checkOutside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn)
return true
end
@ -309,7 +304,7 @@ function input.eventHandlers.keypressed(btn, btncode)
local captured = false
if input.subscriptions.keypressed then
for index, sub in ipairs(input.subscriptions.keypressed) do
if sub.active and sub.stack.element.settings.active then
if sub.active then
sub:emit(btn, btncode)
captured = true
end
@ -320,26 +315,11 @@ function input.eventHandlers.keypressed(btn, btncode)
return captured
end
function input.eventHandlers.filedropped(file)
local captured = false
if input.subscriptions.filedropped then
for index, sub in ipairs(input.subscriptions.filedropped) do
if sub.active and sub.stack.element.settings.active then
sub:emit(file)
captured = true
end
end
end
return captured
end
function input.eventHandlers.keyreleased(btn, btncode)
local captured = false
if input.subscriptions.keyreleased then
for index, sub in ipairs(input.subscriptions.keyreleased) do
if sub.active and sub.stack.element.settings.active then
if sub.active then
sub:emit(btn, btncode)
captured = true
end
@ -353,7 +333,7 @@ function input.eventHandlers.textinput(text)
local captured = false
if input.subscriptions.textinput then
for index, sub in ipairs(input.subscriptions.textinput) do
if sub.active and sub.stack.element.settings.active then
if sub.active then
sub:emit(text)
captured = true
end
@ -370,7 +350,7 @@ function input.eventHandlers.mousemoved(x, y, dx, dy)
for index, sub in ipairs(input.subscriptions.hover) do
local succ = sub:checkInside(x, y)
if sub.active and sub.stack.element.settings.active and not sub.currentEvent and succ then
if sub.active and not sub.currentEvent and succ then
sub.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc
sub.currentEvent = true
return true
@ -387,7 +367,7 @@ function input.eventHandlers.mousemoved(x, y, dx, dy)
if input.subscriptions.dragged then
for index, sub in ipairs(input.subscriptions.dragged) do
if sub.active and sub.stack.element.settings.active and sub.currentEvent then
if sub.active and sub.currentEvent then
if not sub.cleanUp then
sub.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc
else

View File

@ -105,18 +105,6 @@ function context:destroy()
end
end
function context:undraw()
for i = 1, #self.childrenContexts do
self.childrenContexts[i].element:undraw()
end
end
function context:redraw()
for i = 1, #self.childrenContexts do
self.childrenContexts[i].element:redraw()
end
end
function context:getCanvasIndex(forCanvas)
if self.parentCtx then
if self.element.settings.hasCanvas then

View File

@ -105,13 +105,7 @@ Inside it renders immediately, so you can put it inbetween other graphics operat
`Element:destroy()`
Use destroy to completely and irreversibly remove this element from the scene
---
`Element:undraw()`
Use undraw to hide this element for now with the intention of re-drawing it sometime later, to do that just :draw() it again
Use destroy to remove this element from the scene
---

View File

@ -8,9 +8,9 @@ local context = require(path.. ".core.stack")
return function (name, callback)
local activeContext = context.getContext()
if activeContext.element[name] then
if context.element[name] then
error('callback with name '..name..' would interfere with internal fields')
end
activeContext.element[name] = callback
context.element[name] = callback
end

View File

@ -1,5 +1,5 @@
local path = string.sub(..., 1, string.len(...) - string.len(".container"))
local layout = require(path .. '.layout')
local layout = require(path..'.layout')
---@class Container
local container = {}
@ -23,11 +23,11 @@ local function alignLeft(x, wroot, wchild)
end
local function alignCenter(x, wroot, wchild)
return x + (wroot / 2 - wchild / 2)
return x+(wroot/2-wchild/2)
end
local function alignRight(x, wroot, wchild)
return x + (wroot - wchild)
return x+(wroot-wchild)
end
@ -53,19 +53,20 @@ end
function container:draw(x, y, width, height, children, hpad, vpad, alignX)
local w, h = children[1]:getSize()
local x, y
if self.halign == 'stretch' then
if self.halign =='stretch' then
w = width
x = x
else
x = alignHandlerX(self.halign, x, width, w)
x = alignHandlerX(self.halign, containerX, containerWidth, w)
end
if self.valign == 'stretch' then
h = height
if self.valign =='stretch' then
h = h
y = y
else
y = alignHandlerY(self.valign, y, height, h)
y = alignHandlerY(self.valign, containerY, containerHeight, h)
end
children[1]:draw(x, y, w, h)

View File

@ -1,3 +1,4 @@
local column = require "helium.layout.column"
--my copy of the cssssss grids
local path = string.sub(..., 1, string.len(...) - string.len(".grid"))
local layout = require(path..'.layout')

View File

@ -17,8 +17,8 @@ function row:draw(x, y, width, height, children, hpad, vpad, alignX)
if children then
for i, e in ipairs(children) do
local w, _ = e:getSize()
e:draw(x+carriagePos, y+vpad)
carriagePos = carriagePos + w + hpad
e:draw(x+carriagePos+hpad, y+vpad)
carriagePos = carriagePos + w + vpad
end
end
end