This commit is contained in:
Elmārs Āboliņš 2020-06-28 18:43:28 +03:00
parent 32befc1a89
commit 3bd423243e
15 changed files with 468 additions and 450 deletions

View File

@ -3,5 +3,6 @@ local stack = require(path..'.core.stack')
--Sets the computed/minimum size of an element to be used with layout calculations and rendering --Sets the computed/minimum size of an element to be used with layout calculations and rendering
return function(w, h) return function(w, h)
local currentStack = stack.getContext()
currentStack.element:setCalculatedSize(w, h)
end end

View File

@ -1,8 +1,8 @@
local path = string.sub(..., 1, string.len(...) - string.len(".control.state")) local path = string.sub(..., 1, string.len(...) - string.len(".control.state"))
local context = require(path.. ".core.context") local context = require(path.. ".core.stack")
return function (base) return function (base)
local base = base or {} base = base or {}
local fakeBase = {} local fakeBase = {}
local activeContext = context.getContext() local activeContext = context.getContext()
return setmetatable({},{ return setmetatable({},{

View File

@ -87,14 +87,23 @@ function element:new(param)
self.context = context.new(self) self.context = context.new(self)
end end
function element:setCalculatedSize(w, h)
self.view.minW = w or self.view.minW
self.view.minH = h or self.view.minH
self.view.w = math.max(self.view.minW, self.view.w)
self.view.h = math.max(self.view.minH, self.view.h)
end
function element:updateInputCtx() function element:updateInputCtx()
self.context.inputContext:update() self.context.inputContext:update()
if self.settings.canvasW then if self.settings.canvasW then
--If canvas too small make a bigger one
if self.settings.canvasW < self.view.w or self.settings.canvasH < self.view.h then if self.settings.canvasW < self.view.w or self.settings.canvasH < self.view.h then
self.settings.canvasW = self.view.w*1.25 self.settings.canvasW = self.view.w*1.25
self.settings.canvasH = self.view.h*1.25 self.settings.canvasH = self.view.h*1.25
self.canvas = love.graphics.newCanvas(self.view.w*1.25, self.view.h*1.25) self.canvas = love.graphics.newCanvas(self.view.w*1.25, self.view.h*1.25)
--If canvas too big make a smaller one
elseif self.settings.canvasW > self.view.w*1.50 or self.settings.canvasH > self.view.h*1.50 then elseif self.settings.canvasW > self.view.w*1.50 or self.settings.canvasH > self.view.h*1.50 then
self.settings.canvasW = self.view.w*1.25 self.settings.canvasW = self.view.w*1.25
self.settings.canvasH = self.view.h*1.25 self.settings.canvasH = self.view.h*1.25
@ -246,10 +255,12 @@ local insert = table.insert
--Acts as the entrypoint for beginning rendering --Acts as the entrypoint for beginning rendering
---@param x number ---@param x number
---@param y number ---@param y number
function element:draw(x, y) function element:draw(x, y, w, h)
if not self.view.lock then if not self.view.lock then
if x then self.view.x = x end if x then self.view.x = x end
if y then self.view.y = y end if y then self.view.y = y end
if w then self.view.w = self.view.minW<=w and w or self.view.minW end
if h then self.view.h = self.view.minH<=h and h or self.view.minH end
end end
if self.settings.firstDraw then if self.settings.firstDraw then

View File

@ -12,10 +12,16 @@ helium.input = require(path..".core.input")
helium.loader = require(path..".loader") helium.loader = require(path..".loader")
helium.elementBuffer = {} helium.elementBuffer = {}
helium.__index = helium helium.__index = helium
setmetatable(helium, {__call = function(s,chunk)
return function(param,w,h) setmetatable(helium, {__call = function(s, chunk)
return helium.element(chunk,nil,w,h,param) return {
__call = function(s, param, w, h)
return helium.element(chunk, nil, w, h, param)
end,
draw = function (param, x, y, w, h)
return helium.element.immediate(param, chunk, x, y, w, h)
end end
}
end}) end})
function helium.render() function helium.render()