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,
pendingUpdate = true,
needsRendering = true,
active = true,
remove = false,
--Unused for now?
calculatedDimensions = true,
@ -285,8 +286,13 @@ 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')
@ -348,6 +354,9 @@ 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
@ -402,6 +411,10 @@ 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
@ -429,10 +442,23 @@ 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,6 +59,11 @@ 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
@ -207,7 +212,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 then
if sub.currentEvent and sub.active and sub.stack.element.settings.active then
sub.currentEvent = false
captured = true
if sub.cleanUp then
@ -219,7 +224,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 then
if sub.currentEvent and sub.active and sub.stack.element.settings.active then
sub.currentEvent = false
captured = true
if sub.cleanUp then
@ -231,7 +236,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: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)
captured = true
end
@ -241,7 +246,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: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)
captured = true
end
@ -259,7 +264,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 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.currentEvent = true
return true
@ -270,7 +275,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:checkInside(x, y) then
if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
sub.currentEvent = true
return true
end
@ -280,7 +285,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: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)
return true
end
@ -290,7 +295,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: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)
return true
end
@ -304,7 +309,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 then
if sub.active and sub.stack.element.settings.active then
sub:emit(btn, btncode)
captured = true
end
@ -315,11 +320,26 @@ 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 then
if sub.active and sub.stack.element.settings.active then
sub:emit(btn, btncode)
captured = true
end
@ -333,7 +353,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 then
if sub.active and sub.stack.element.settings.active then
sub:emit(text)
captured = true
end
@ -350,7 +370,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 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.currentEvent = true
return true
@ -367,7 +387,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.currentEvent then
if sub.active and sub.stack.element.settings.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,6 +105,18 @@ 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,7 +105,13 @@ Inside it renders immediately, so you can put it inbetween other graphics operat
`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)
local activeContext = context.getContext()
if context.element[name] then
if activeContext.element[name] then
error('callback with name '..name..' would interfere with internal fields')
end
context.element[name] = callback
activeContext.element[name] = callback
end

View File

@ -1,8 +1,8 @@
local path = string.sub(..., 1, string.len(...) - string.len(".container"))
local layout = require(path..'.layout')
local path = string.sub(..., 1, string.len(...) - string.len(".container"))
local layout = require(path .. '.layout')
---@class Container
local container = {}
local container = {}
container.__index = container
---Positions an element within a container
@ -14,7 +14,7 @@ function container.new(halign, valign)
halign = halign or 'left',
valign = valign or 'top',
}, container)
return layout(self, self.draw)
end
@ -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,23 +53,22 @@ 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, containerX, containerWidth, w)
x = alignHandlerX(self.halign, x, width, w)
end
if self.valign =='stretch' then
h = h
if self.valign == 'stretch' then
h = height
y = y
else
y = alignHandlerY(self.valign, containerY, containerHeight, h)
y = alignHandlerY(self.valign, y, height, h)
end
children[1]:draw(x, y, w, h)
end
return container
return container

View File

@ -1,4 +1,3 @@
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')
@ -411,4 +410,4 @@ function grid:draw(xRoot, yRoot, width, height, children)
end
end
return grid
return grid

View File

@ -17,10 +17,10 @@ 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+hpad, y+vpad)
carriagePos = carriagePos + w + vpad
e:draw(x+carriagePos, y+vpad)
carriagePos = carriagePos + w + hpad
end
end
end
return row
return row