This commit is contained in:
qfx 2020-02-14 03:11:53 +02:00
parent 90ba400380
commit 87551314cc
4 changed files with 56 additions and 11 deletions

View File

@ -202,8 +202,8 @@ helium.input
```
## All the user intended interfaces, classes and methods
## User facing functions
-> is return value
values with Capital are classes
```lua
helium.element(function,reloader,w,h,parameters)
->Element --Creates a new element

View File

@ -1,6 +1,6 @@
return {
HOTSWAP = true, --Turns on hotswap, disable this once it's deployed
HOTSWAP = true, --Turns on hotswap, disable this once you're deploying a project
AUTO_RUN = true, --Replaces the default love.run
DEBUG = true, --Reserved for later
PURE_G = true, --whether to set HeliumLoader global
PURE_G = true, --whether to keep _G pure
}

View File

@ -104,6 +104,8 @@ function element:new(w, h, param)
pendingUpdate = true,
needsRendering = true,
calculatedDimensions = true,
--Stabilize the internal canvas, draw it twice on first load
stabilize = true,
inserted = false
}
@ -268,6 +270,11 @@ local draw = love.graphics.draw
function element:externalRender()
self.context:set()
if self.settings.stabilize and not self.settings.needsRendering then
self.settings.stabilize = false
self.settings.needsRendering = true
end
if self.settings.needsRendering then
self:renderWrapper()
self.settings.needsRendering = false

View File

@ -59,7 +59,13 @@ function context:set()
end
function context:update()
if self.parentCtx then
self.absX = self.parentCtx.absX + self.elem.view.x
self.absY = self.parentCtx.absY + self.elem.view.y
end
for i, e in ipairs(self.childContexts) do
e:update()
end
for i, sub in ipairs(self.subs) do
sub:contextUpdate(self.absX,self.absY,self)
end
@ -93,8 +99,26 @@ end
function subscription.create(x, y, w, h, eventType, callback, doff)
local sub
if activeContext then
local wratio = w/activeContext.elem.view.w
local hratio = h/activeContext.elem.view.h
local wratio,hratio,xratio,yratio
if x<=1 and x~=0 then
xratio = x
x = activeContext.elem.view.w * x
end
if y<=1 and y~=0 then
yratio = y
y = activeContext.elem.view.h * y
end
if w<=1 and w~=0 then
wratio = w
w = activeContext.elem.view.w * w
end
if h<=1 and h~=0 then
hratio = h
h = activeContext.elem.view.h * h
end
sub = setmetatable({
x = activeContext.absX + x,
@ -103,6 +127,8 @@ function subscription.create(x, y, w, h, eventType, callback, doff)
h = h,
wratio = wratio,
hratio = hratio,
xratio = xratio,
yratio = yratio,
ix = x,
iy = y,
eventType = eventType,
@ -146,10 +172,22 @@ function subscription:destroy()
end
function subscription:contextUpdate(absX, absY,activeContext)
if self.xratio then
self.x = absX + activeContext.elem.view.w * self.xratio
else
self.x = absX + self.ix
end
if self.yratio then
self.y = absY + activeContext.elem.view.h * self.yratio
else
self.y = absY + self.iy
self.w = activeContext.elem.view.w * self.wratio
end
if self.hratio then
self.h = activeContext.elem.view.h * self.hratio
end
if self.wratio then
self.w = activeContext.elem.view.w * self.wratio
end
end
function subscription:update(x, y, w, h)