Compare commits
No commits in common. "c40b3eb953827eaa38daec543546253c670f805b" and "0f99994ae302c8a7b4f3b979bd32b282f7953953" have entirely different histories.
c40b3eb953
...
0f99994ae3
@ -46,7 +46,6 @@ 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,
|
||||||
@ -286,13 +285,8 @@ 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')
|
||||||
|
|
||||||
@ -354,9 +348,6 @@ 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
|
||||||
@ -411,10 +402,6 @@ 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
|
||||||
@ -442,23 +429,10 @@ 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
|
||||||
|
|||||||
@ -59,11 +59,6 @@ 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
|
||||||
@ -212,7 +207,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 and sub.active and sub.stack.element.settings.active then
|
if sub.currentEvent then
|
||||||
sub.currentEvent = false
|
sub.currentEvent = false
|
||||||
captured = true
|
captured = true
|
||||||
if sub.cleanUp then
|
if sub.cleanUp then
|
||||||
@ -224,7 +219,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 and sub.active and sub.stack.element.settings.active then
|
if sub.currentEvent then
|
||||||
sub.currentEvent = false
|
sub.currentEvent = false
|
||||||
captured = true
|
captured = true
|
||||||
if sub.cleanUp then
|
if sub.cleanUp then
|
||||||
@ -236,7 +231,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.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)
|
sub:emit(x-sub.x, y-sub.y, btn)
|
||||||
captured = true
|
captured = true
|
||||||
end
|
end
|
||||||
@ -246,7 +241,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.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)
|
sub:emit(x-sub.x, y-sub.y, btn)
|
||||||
captured = true
|
captured = true
|
||||||
end
|
end
|
||||||
@ -264,7 +259,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 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.cleanUp = sub:emit(x-sub.x, y-sub.y, btn) or dummyfunc
|
||||||
sub.currentEvent = true
|
sub.currentEvent = true
|
||||||
return true
|
return true
|
||||||
@ -275,7 +270,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.stack.element.settings.active and sub:checkInside(x, y) then
|
if sub.active and sub:checkInside(x, y) then
|
||||||
sub.currentEvent = true
|
sub.currentEvent = true
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -285,7 +280,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.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)
|
sub:emit(x-sub.x, y-sub.y, btn)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -295,7 +290,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.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)
|
sub:emit(x-sub.x, y-sub.y, btn)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -309,7 +304,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 and sub.stack.element.settings.active then
|
if sub.active then
|
||||||
sub:emit(btn, btncode)
|
sub:emit(btn, btncode)
|
||||||
captured = true
|
captured = true
|
||||||
end
|
end
|
||||||
@ -320,26 +315,11 @@ 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 and sub.stack.element.settings.active then
|
if sub.active then
|
||||||
sub:emit(btn, btncode)
|
sub:emit(btn, btncode)
|
||||||
captured = true
|
captured = true
|
||||||
end
|
end
|
||||||
@ -353,7 +333,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 and sub.stack.element.settings.active then
|
if sub.active then
|
||||||
sub:emit(text)
|
sub:emit(text)
|
||||||
captured = true
|
captured = true
|
||||||
end
|
end
|
||||||
@ -370,7 +350,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 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.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc
|
||||||
sub.currentEvent = true
|
sub.currentEvent = true
|
||||||
return true
|
return true
|
||||||
@ -387,7 +367,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.stack.element.settings.active and sub.currentEvent then
|
if sub.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
|
||||||
|
|||||||
@ -105,18 +105,6 @@ 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
|
||||||
|
|||||||
@ -105,13 +105,7 @@ Inside it renders immediately, so you can put it inbetween other graphics operat
|
|||||||
|
|
||||||
`Element:destroy()`
|
`Element:destroy()`
|
||||||
|
|
||||||
Use destroy to completely and irreversibly remove this element from the scene
|
Use destroy to 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
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@ -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 activeContext.element[name] then
|
if context.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
|
||||||
|
|
||||||
activeContext.element[name] = callback
|
context.element[name] = callback
|
||||||
end
|
end
|
||||||
@ -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
|
||||||
@ -14,7 +14,7 @@ function container.new(halign, valign)
|
|||||||
halign = halign or 'left',
|
halign = halign or 'left',
|
||||||
valign = valign or 'top',
|
valign = valign or 'top',
|
||||||
}, container)
|
}, container)
|
||||||
|
|
||||||
return layout(self, self.draw)
|
return layout(self, self.draw)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -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,22 +53,23 @@ 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, x, width, w)
|
x = alignHandlerX(self.halign, containerX, containerWidth, w)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.valign == 'stretch' then
|
if self.valign =='stretch' then
|
||||||
h = height
|
h = h
|
||||||
y = y
|
y = y
|
||||||
else
|
else
|
||||||
y = alignHandlerY(self.valign, y, height, h)
|
y = alignHandlerY(self.valign, containerY, containerHeight, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
children[1]:draw(x, y, w, h)
|
children[1]:draw(x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
return container
|
return container
|
||||||
@ -1,3 +1,4 @@
|
|||||||
|
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')
|
||||||
@ -410,4 +411,4 @@ function grid:draw(xRoot, yRoot, width, height, children)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return grid
|
return grid
|
||||||
@ -17,10 +17,10 @@ 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, y+vpad)
|
e:draw(x+carriagePos+hpad, y+vpad)
|
||||||
carriagePos = carriagePos + w + hpad
|
carriagePos = carriagePos + w + vpad
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return row
|
return row
|
||||||
Loading…
x
Reference in New Issue
Block a user