Compare commits

...

10 Commits

Author SHA1 Message Date
Elmārs
c40b3eb953
Merge pull request #32 from TotoEnF5/layout
fix uninitialized variables in container layout
2025-04-01 16:24:27 +03:00
TotoEnF5
fc2d5c862a fix uninitialized variables in container layout
variables `x` and `y` shadowed the parameters, and `containerX`, `containerY`,
`containerWidth` and `containerHeight` were used without being initialized.
they could be replaced by the parameters `width` and `height`
2025-03-25 14:25:33 +01:00
qeffects
cac01a34c9 callbacks fix 2021-12-27 00:53:16 +02:00
Elmārs
72c4eb8689
Merge pull request #20 from Aweptimum/patch-1
Delete require call for `column` layout
2021-11-07 16:41:53 +02:00
Sam
662d1fcfdf
Delete require call for column layout
It's just sitting there

menacingly
2021-11-07 09:38:06 -05:00
qeffects
186d06f887 added filedropped handler 2021-11-06 19:35:42 +02:00
Elmārs
46a9ae4b2f
Merge pull request #19 from SlimeBOOS/fix-row-layout-typo
Fix typo in row layout.
2021-07-22 16:01:17 +03:00
SlimeBOOS
8ac9c72d44
Update row.lua again, so that row elements are not offset. 2021-07-21 23:13:56 +03:00
SlimeBOOS
efe3cf577a
Update row.lua 2021-07-21 23:07:27 +03:00
qeffects
2144c5ab21 added undraw 2021-07-21 22:40:20 +03:00
8 changed files with 96 additions and 34 deletions

View File

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

View File

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

View File

@ -105,6 +105,18 @@ function context:destroy()
end end
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) function context:getCanvasIndex(forCanvas)
if self.parentCtx then if self.parentCtx then
if self.element.settings.hasCanvas then if self.element.settings.hasCanvas then

View File

@ -105,7 +105,13 @@ Inside it renders immediately, so you can put it inbetween other graphics operat
`Element:destroy()` `Element:destroy()`
Use destroy to remove this element from the scene 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
--- ---

View File

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

View File

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

View File

@ -1,4 +1,3 @@
local column = require "helium.layout.column"
--my copy of the cssssss grids --my copy of the cssssss grids
local path = string.sub(..., 1, string.len(...) - string.len(".grid")) local path = string.sub(..., 1, string.len(...) - string.len(".grid"))
local layout = require(path..'.layout') 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 if children then
for i, e in ipairs(children) do for i, e in ipairs(children) do
local w, _ = e:getSize() local w, _ = e:getSize()
e:draw(x+carriagePos+hpad, y+vpad) e:draw(x+carriagePos, y+vpad)
carriagePos = carriagePos + w + vpad carriagePos = carriagePos + w + hpad
end end
end end
end end