Skip to content

Commit

Permalink
help
Browse files Browse the repository at this point in the history
  • Loading branch information
qeffects committed Jun 28, 2020
1 parent 32befc1 commit 3bd4232
Show file tree
Hide file tree
Showing 15 changed files with 468 additions and 450 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
local_conf.lua
local_conf.lua
64 changes: 32 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
![alt text](https://i.imgur.com/ZQBQfsa.png "Helium")
# Helium
## Major features:
### Custom elements
Write your own elements, and interface with them however you want to,
Whether you need a generalized button that can have many themes and options or something super specific, it can be done
### Efficient rendering & updating
The elements only update&re-render when state changes
### Code hotswap
Change and save a file loaded through the helium.loader, and see changes immediately

## Basic overview:
Helium is practically more like a UI framework than a fully fledged UI library.
The idea is to build custom, build simple and build fast, encapsulate.

## Demo's / Practical examples
[There's a repository of examples here](https://github.com/qfluxstudio/helium_demos)

## Getting started:
Load helium with `local helium = require 'helium'`

The basic structure for an element is:

```lua
return function(param,state,view)
--Setup zone
return function()
--Rendering zone
end
end
```

![alt text](https://i.imgur.com/ZQBQfsa.png "Helium")
# Helium
## Major features:
### Custom elements
Write your own elements, and interface with them however you want to,
Whether you need a generalized button that can have many themes and options or something super specific, it can be done
### Efficient rendering & updating
The elements only update&re-render when state changes
### Code hotswap
Change and save a file loaded through the helium.loader, and see changes immediately

## Basic overview:
Helium is practically more like a UI framework than a fully fledged UI library.
The idea is to build custom, build simple and build fast, encapsulate.

## Demo's / Practical examples
[There's a repository of examples here](https://github.com/qfluxstudio/helium_demos)

## Getting started:
Load helium with `local helium = require 'helium'`

The basic structure for an element is:

```lua
return function(param,state,view)
--Setup zone
return function()
--Rendering zone
end
end
```

[The documentation outgrew this readme, see the github wiki](https://github.com/qfluxstudio/helium/wiki/)
12 changes: 6 additions & 6 deletions conf.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
return {
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 keep _G pure
HARD_ERROR = true, --Whether to display element errors inside or hard cras
return {
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 keep _G pure
HARD_ERROR = true, --Whether to display element errors inside or hard cras
}
122 changes: 61 additions & 61 deletions control/layout.lua
Original file line number Diff line number Diff line change
@@ -1,61 +1,61 @@
local path = string.sub(..., 1, string.len(...) - string.len(".core.layout"))

local layout = {}
layout.__index = layout
local element = require(path..'core.element')

local function layout_new(type, x, y, w, h)
local ctx = element.getContext()

--The output will be in pixel numbers regardless of inputs
if x <= 1 or not x then
x = ctx.view.x * (x or 0)
end

if y <= 1 then
y = ctx.view.y * (y or 0)
end

if w <= 1 then
w = ctx.view.w * (w or 1)
end

if h <= 1 then
h = ctx.view.h * (h or 1)
end

return setmetatable({
x = x,
y = y,
w = w,
h = h
}, layout)
end


--Sets mode for the proceding operations
function layout.mode()

end

--Sets padding for the next operations
function layout.pad()

end

--Sets margins for the proceding operations
function layout.margin()

end

function layout.offset()

end

function layout:draw()

end

layout(0,0,1,1)

return layout
local path = string.sub(..., 1, string.len(...) - string.len(".core.layout"))

local layout = {}
layout.__index = layout
local element = require(path..'core.element')

local function layout_new(type, x, y, w, h)
local ctx = element.getContext()

--The output will be in pixel numbers regardless of inputs
if x <= 1 or not x then
x = ctx.view.x * (x or 0)
end

if y <= 1 then
y = ctx.view.y * (y or 0)
end

if w <= 1 then
w = ctx.view.w * (w or 1)
end

if h <= 1 then
h = ctx.view.h * (h or 1)
end

return setmetatable({
x = x,
y = y,
w = w,
h = h
}, layout)
end


--Sets mode for the proceding operations
function layout.mode()

end

--Sets padding for the next operations
function layout.pad()

end

--Sets margins for the proceding operations
function layout.margin()

end

function layout.offset()

end

function layout:draw()

end

layout(0,0,1,1)

return layout
13 changes: 7 additions & 6 deletions control/size.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
local path = string.sub(..., 1, string.len(...) - string.len(".control.size"))
local stack = require(path..'.core.stack')

--Sets the computed/minimum size of an element to be used with layout calculations and rendering
return function(w, h)

local path = string.sub(..., 1, string.len(...) - string.len(".control.size"))
local stack = require(path..'.core.stack')

--Sets the computed/minimum size of an element to be used with layout calculations and rendering
return function(w, h)
local currentStack = stack.getContext()
currentStack.element:setCalculatedSize(w, h)
end
36 changes: 18 additions & 18 deletions control/state.lua
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
local path = string.sub(..., 1, string.len(...) - string.len(".control.state"))
local context = require(path.. ".core.context")

return function (base)
local base = base or {}
local fakeBase = {}
local activeContext = context.getContext()
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
})
local path = string.sub(..., 1, string.len(...) - string.len(".control.state"))
local context = require(path.. ".core.stack")

return function (base)
base = base or {}
local fakeBase = {}
local activeContext = context.getContext()
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
13 changes: 12 additions & 1 deletion core/element.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,23 @@ function element:new(param)
self.context = context.new(self)
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()
self.context.inputContext:update()
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
self.settings.canvasW = self.view.w*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)
--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
self.settings.canvasW = self.view.w*1.25
self.settings.canvasH = self.view.h*1.25
Expand Down Expand Up @@ -246,10 +255,12 @@ local insert = table.insert
--Acts as the entrypoint for beginning rendering
---@param x number
---@param y number
function element:draw(x, y)
function element:draw(x, y, w, h)
if not self.view.lock then
if x then self.view.x = x 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

if self.settings.firstDraw then
Expand Down
10 changes: 5 additions & 5 deletions core/input.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface Subscription{
on():void;
off():void;
}

interface Subscription{
on():void;
off():void;
}

export default function input(it:string,cb:(x?:number,y?:number)=>void,doff?:boolean,x?:number,y?:number,w?:number,h?:number): Subscription;
Loading

0 comments on commit 3bd4232

Please sign in to comment.