Final touches

This commit is contained in:
qfx 2020-02-13 20:10:56 +02:00
parent 354abe1954
commit 4caa5722bf
2 changed files with 16 additions and 14 deletions

View File

@ -1,3 +1,4 @@
![alt text](https://i.imgur.com/2i2MS2l.png "Helium")
# Helium # Helium
## user facing functions ## user facing functions
```lua ```lua
@ -89,31 +90,32 @@ button:draw(10,10)
Now theres a lot to explain, but its fairly simple, so lets take it by chunks Now theres a lot to explain, but its fairly simple, so lets take it by chunks
Here we import the input module of Helium, so that we can later subscribe to an event:
```lua ```lua
local input = require "helium.core.input" local input = require "helium.core.input"
``` ```
Here we import the input module of Helium, so that we can later subscribe to an event
--- ---
Here we create a state field called pressed, think of state as a helium elements self
It works like a regular table, with the caveat that you shouldnt overwrite it directly like state = {}
```lua ```lua
state.pressed = false state.pressed = false
``` ```
Here we create a state field called pressed, think of state as a helium elements self
It works like a regular table, with the caveat that you shouldnt overwrite it directly like state = {}
--- ---
Then we overwrite that state.pressed inside a callback which will be called every time our button is pressed
```lua ```lua
local callback = function() state.pressed = true end local callback = function() state.pressed = true end
``` ```
Then we overwrite that state.pressed inside a callback which will be called every time our button is pressed
--- ---
This is creating an input subscription for the event of your choice
```lua ```lua
input.subscribe(0,0,view.w,view.h,'clicked',callback) input.subscribe(0,0,view.w,view.h,'clicked',callback)
``` ```
This is creating an input subscription for the event of your choice
--- ---
Is the rendering code, it works more or less like a mini window of a love.draw()
```lua ```lua
return function() return function()
if state.pressed then if state.pressed then
@ -126,7 +128,6 @@ return function()
love.graphics.printf("Pressed? "..tostring(state.pressed),0,view.h/2-5,view.w,'center') love.graphics.printf("Pressed? "..tostring(state.pressed),0,view.h/2-5,view.w,'center')
end end
``` ```
Is the rendering code, it works more or less like a mini window of a love.draw()
### Additional details: ### Additional details:
**view** is a table that holds the information about the position and size of an element **view** is a table that holds the information about the position and size of an element
@ -136,6 +137,7 @@ Setting this from inside the element works as expected(so you can dynamically re
param is the table that you pass in buttonFactory({}, 200, 100), it can be anything you need param is the table that you pass in buttonFactory({}, 200, 100), it can be anything you need
there's a configuration table inside of helium, which has a couple of default settings there's a configuration table inside of helium, which has a couple of default settings
AUTO_RUN if true will give you a basic 11.3 version love.run
if autorun is off then you NEED to place helium.update(dt), helium.render() somewhere if autorun is off then you NEED to place helium.update(dt), helium.render() somewhere
and if you need input, hook it up to the eventHandlers in your own love.run: and if you need input, hook it up to the eventHandlers in your own love.run:

View File

@ -3,13 +3,13 @@
Copyright (c) 2019 Elmārs Āboliņš Copyright (c) 2019 Elmārs Āboliņš
gitlab.com/project link here gitlab.com/project link here
----------------------------------------------------]] ----------------------------------------------------]]
local path = ... local path = ...
local helium = require(path..".dummy") local helium = require(path..".dummy")
helium.conf = require(path..".conf") helium.conf = require(path..".conf")
helium.utils = require(path..".utils") helium.utils = require(path..".utils")
helium.element = require(path..".core.element") helium.element = require(path..".core.element")
helium.input = require(path..".core.input") helium.input = require(path..".core.input")
helium.loader = require(path..".loader") helium.loader = require(path..".loader")
helium.elementBuffer = {} helium.elementBuffer = {}
function helium.render() function helium.render()
@ -63,7 +63,7 @@ end
end end
end end
if not(gui.eventHandlers[name]) or not(helium.eventHandlers[name](a, b, c, d, e, f)) then if not(helium.eventHandlers[name]) or not(helium.eventHandlers[name](a, b, c, d, e, f)) then
love.handlers[name](a, b, c, d, e, f) love.handlers[name](a, b, c, d, e, f)
end end
end end