New input subscription model, nested elements work better with love translation operations
This commit is contained in:
parent
4e021c80b8
commit
8eab7d3d35
@ -63,6 +63,23 @@ end
|
||||
local element = {}
|
||||
element.__index = element
|
||||
|
||||
function element.newProxy(base)
|
||||
local base = base or {}
|
||||
local fakeBase = {}
|
||||
local activeContext = activeContext
|
||||
return setmetatable({},{
|
||||
__index = function(t, index)
|
||||
return fakeBase[index] or base[index]
|
||||
end,
|
||||
__newindex = function(t, index, val)
|
||||
if fakeBase[index] ~= val then
|
||||
fakeBase[index] = val
|
||||
activeContext:bubbleUpdate()
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local type,pcall = type,pcall
|
||||
setmetatable(element,{
|
||||
__call = function(cls, ...)
|
||||
@ -127,6 +144,9 @@ function element:new(w, h, param)
|
||||
self.baseView[index] = val
|
||||
self.context:bubbleUpdate()
|
||||
self:updateInputCtx()
|
||||
if self.view.onChange then
|
||||
self.view.onChange()
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
@ -147,6 +167,8 @@ function element:new(w, h, param)
|
||||
self.settings.restrictView = true
|
||||
return self.view
|
||||
end
|
||||
|
||||
self:setup()
|
||||
end
|
||||
|
||||
function element:updateInputCtx()
|
||||
@ -232,7 +254,10 @@ function element:classlessRender()
|
||||
|
||||
self.inputContext:set()
|
||||
if type(self.renderer)=='function' then
|
||||
love.graphics.push()
|
||||
love.graphics.origin()
|
||||
local status, err = pcall(self.renderer)
|
||||
love.graphics.pop()
|
||||
|
||||
if not status then
|
||||
setColor(1,0,0)
|
||||
@ -308,9 +333,6 @@ function element:draw(x, y)
|
||||
if y then self.view.y = y end
|
||||
end
|
||||
|
||||
if not self.settings.isSetup then
|
||||
self:setup()
|
||||
end
|
||||
|
||||
if activeContext then
|
||||
self:externalRender()
|
||||
|
||||
@ -136,7 +136,6 @@ function subscription.create(x, y, w, h, eventType, callback, doff)
|
||||
active = doff or true,
|
||||
callback = callback
|
||||
},subscription)
|
||||
|
||||
activeContext.subs[#activeContext.subs+1] = sub
|
||||
else
|
||||
sub = setmetatable({
|
||||
@ -154,7 +153,7 @@ function subscription.create(x, y, w, h, eventType, callback, doff)
|
||||
input.subscriptions[eventType] = {}
|
||||
end
|
||||
|
||||
table.insert(input.subscriptions[eventType],sub)
|
||||
input.subscriptions[eventType][#input.subscriptions[eventType]+1] = sub
|
||||
|
||||
return sub
|
||||
end
|
||||
@ -211,16 +210,24 @@ function subscription:checkOutside(x, y)
|
||||
end
|
||||
|
||||
input.subscribe = subscription.create
|
||||
|
||||
--Since the introduction of the relative subscriptions, there is more utility in ommiting coordinates by default
|
||||
setmetatable(input, {__call = function(eventType, callback, cbOff, x, y, w, h)
|
||||
---@param eventType string
|
||||
---@param callback function
|
||||
---@param cbOff boolean
|
||||
---@param x number
|
||||
---@param y number
|
||||
---@param w number
|
||||
---@param h number
|
||||
input.__call = function(self, eventType, callback, cbOff, x, y, w, h)
|
||||
x = x or 0
|
||||
y = y or 0
|
||||
w = w or 1
|
||||
h = h or 1
|
||||
|
||||
subscription.create(x,y,w,h,eventType,callback,cbOff)
|
||||
end})
|
||||
return subscription.create(x,y,w,h,eventType,callback,cbOff)
|
||||
end
|
||||
|
||||
--Since the introduction of the relative subscriptions, there is more utility in ommiting coordinates by default
|
||||
setmetatable(input, input)
|
||||
|
||||
function input.eventHandlers.mousereleased(x, y, btn)
|
||||
local captured = false
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user