From 81b24eee598f216355a53f6f0f1ae75eb240689b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elm=C4=81rs=20=C4=80boli=C5=86=C5=A1?= Date: Sat, 3 Jul 2021 21:13:03 +0300 Subject: [PATCH] bug fixes and new conf values --- README.md | 6 ++ conf.lua | 15 +++- core/atlas.lua | 25 +++--- core/element.lua | 13 ++-- core/init.lua | 17 +++++ core/input.lua | 4 +- core/scene.lua | 4 +- core/stack.lua | 33 ++++++-- docs/Configuration.md | 85 +++++++++++++++++++++ docs/Core.md | 2 +- docs/Hooks.md | 20 +++++ hooks/callback.lua | 2 +- hooks/init.lua | 28 +++++++ hooks/setCaching.lua | 15 ++++ hooks/state.lua | 3 +- init.lua | 32 +++++++- layout/column.lua | 2 +- layout/container.lua | 2 +- layout/grid.lua | 4 +- layout/init.lua | 171 ++++-------------------------------------- layout/layout.lua | 154 +++++++++++++++++++++++++++++++++++++ layout/row.lua | 2 +- shell/checkbox.lua | 2 +- shell/init.lua | 13 ++++ shell/input.lua | 4 +- 25 files changed, 459 insertions(+), 199 deletions(-) create mode 100644 core/init.lua create mode 100644 docs/Configuration.md create mode 100644 hooks/init.lua create mode 100644 hooks/setCaching.lua create mode 100644 layout/layout.lua create mode 100644 shell/init.lua diff --git a/README.md b/README.md index 01005a3..378eff1 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,10 @@ ![alt text](https://i.imgur.com/ZQBQfsa.png "Helium") # Helium +![Helium main menu demo](https://j.gifs.com/nRrKmp.gif) + +*a main menu demo made with helium, in action, find [it here](https://github.com/qeffects/main-menu-example)* + ## Basic overview: Helium is practically more like a UI framework than a fully fledged UI library. The idea is to build custom and build simple. @@ -119,4 +123,6 @@ Or continue on to the State and Input guide: [Here](./docs/State-Input-Guide.md) If you are using gamestates, scene guide will be of interest: [Here](./docs/core/Scenes.md) For a more general overview of the whole library: [Module index](./docs/Modules-Index.md) +Also check out the helium configuration values: [Config](./docs/Configuration.md) + There's also a main menu example project available here: [Project](https://github.com/qeffects/main-menu-example) diff --git a/conf.lua b/conf.lua index c63997a..b45eba6 100644 --- a/conf.lua +++ b/conf.lua @@ -1,4 +1,15 @@ +---@class __HELIUM_CONFIG +---@field DEBUG boolean +---@field LOAD_HOOKS boolean +---@field LOAD_LAYOUT boolean +---@field LOAD_SHELL boolean +---@field MANUAL_CACHING boolean + +---@type __HELIUM_CONFIG return { - AUTO_RUN = true, --Replaces the default love.run - DEBUG = true, --Reserved for later + DEBUG = true, --Reserved for later + LOAD_HOOKS = false, --Loads the hooks module in to helium table + LOAD_LAYOUT = false, --Loads the layout module in to helium table + LOAD_SHELL = false, --Loads the shell mocule in to helium table + MANUAL_CACHING = false, --Whether or not to perform automatic caching } \ No newline at end of file diff --git a/core/atlas.lua b/core/atlas.lua index 55e56d7..67b0739 100644 --- a/core/atlas.lua +++ b/core/atlas.lua @@ -3,7 +3,8 @@ Copyright (c) 2021 Elmārs Āboliņš https://github.com/qeffects/helium ----------------------------------------------------]] - +local path = string.sub(..., 1, string.len(...) - string.len(".core.atlas")) +local helium = require(path..'.dummy') local atlas = {} atlas.__index = atlas ---@class atlases @@ -39,20 +40,22 @@ end function atlases:assign(element) local avg, sum, canvasID = 0, 0, element.context:getCanvasIndex(true) or 1 - for i, e in ipairs(element.renderBench) do - sum = sum + e - end + if not helium.conf.MANUAL_CACHING then + for i, e in ipairs(element.renderBench) do + sum = sum + e + end - avg = sum/#element.renderBench + avg = sum/#element.renderBench - local areaBelow = self:getFreeArea(canvasID) - local area = element.view.h*element.view.w + local areaBelow = self:getFreeArea(canvasID) + local area = element.view.h*element.view.w - local areaCoef = (2-(self:getRatio(canvasID)) )-(area/(areaBelow/(4+3*self:getRatio(canvasID)))) - local speedCoef = avg/selfRenderTime + local areaCoef = (2-(self:getRatio(canvasID)) )-(area/(areaBelow/(4+3*self:getRatio(canvasID)))) + local speedCoef = avg/selfRenderTime - if not ((areaCoef+speedCoef)>coefficient) then - return + if not ((areaCoef+speedCoef)>coefficient) then + return + end end local elW = element.view.w diff --git a/core/element.lua b/core/element.lua index a0f8727..62421fa 100644 --- a/core/element.lua +++ b/core/element.lua @@ -124,7 +124,6 @@ function element:posChange(i, v) if not self.deferRepos then self.deferRepos = true end - if self.callbacks.onPosChange then for i, cb in ipairs(self.callbacks.onPosChange) do @@ -258,13 +257,13 @@ local setColor, rectangle, setFont, printf = love.graphics.setColor, love.graphi local calcT function element:internalRender() - if self.settings.testRenderPasses > 0 and selfRenderTime then + if self.settings.testRenderPasses > 0 and selfRenderTime and not helium.conf.MANUAL_CACHING then calcT = love.timer.getTime() end self.renderer() - if self.settings.testRenderPasses > 0 and selfRenderTime then + if self.settings.testRenderPasses > 0 and selfRenderTime and not helium.conf.MANUAL_CACHING then self.settings.testRenderPasses = self.settings.testRenderPasses-1 local selfTime = love.timer.getTime()-calcT table.insert(self.renderBench, selfTime) @@ -334,10 +333,12 @@ end function element:externalUpdate() self.context:set() self.context:zIndex() - if not self.settings.failedCanvas + if ((not self.settings.failedCanvas and self.settings.testRenderPasses == 0 - and not self.settings.hasCanvas - and scene.activeScene.cached then + and scene.activeScene.cached + and not helium.conf.MANUAL_CACHING) + or self.settings.forcedCanvas) + and not self.settings.hasCanvas then self:createCanvas() diff --git a/core/init.lua b/core/init.lua new file mode 100644 index 0000000..ed9bd93 --- /dev/null +++ b/core/init.lua @@ -0,0 +1,17 @@ +local path = ... + +---@class __HELIUM_CORE +---@field atlas any +---@field element any +---@field events any +---@field input any +---@field scene any +---@field stack any +return { + atlas = require(path..'.atlas'), + element = require(path..'.element'), + events = require(path..'.events'), + input = require(path..'.input'), + scene = require(path..'.scene'), + stack = require(path..'.stack'), +} \ No newline at end of file diff --git a/core/input.lua b/core/input.lua index 086f8d7..fe50308 100644 --- a/core/input.lua +++ b/core/input.lua @@ -172,11 +172,11 @@ function subscription:emit(...) end function subscription:checkInside(x, y) - return x>self.stack.absX and xself.stack.absY and yself.x and xself.y and yself.stack.absX and xself.stack.absY and yself.x and xself.y and y