This commit is contained in:
qfx 2020-02-20 00:38:02 +02:00
parent bb1ac35ef6
commit a8bd0e9adb

View File

@ -109,12 +109,26 @@ end
## 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
`view = {` `view = {`
fairly self explanatory: fairly self explanatory:
`x=1, y=1, w=1, h=1` `x=1, y=1, w=1, h=1`
Locks the element being moved from the outside with :draw(x,y) Locks the element being moved from the outside with :draw(x,y)
`lock,` `lock,`
An additonal callback, called whenever element is resized or repositioned An additonal callback, called whenever element is resized or repositioned
`onChange}` `onChange}`
Setting this from inside the element works as expected(so you can dynamically resize and reposition the element from inside) Setting this from inside the element works as expected(so you can dynamically resize and reposition the element from inside)
@ -206,61 +220,51 @@ One thing to be careful about is, that as long as this element exists, it will b
So use **state.onFirstDraw** and **state.onDestroy** So use **state.onFirstDraw** and **state.onDestroy**
the input structure:
```lua
helium.input(subType,callback,starton,x,y,w,h) -- The new, preffered way of creating a subscription
.subscribe(x, y, w, h, subType, callback, startOn)
subType -- Subscription type
callback -- Subscription callback on event
startOn -- a bool to disable a subscription by default
-> Subscription
:on() --Turns an inactive subscription on
:off() --Turns an active subscription off
subType:
Advanced:
"clicked" (x,y,btn)--Gets called whenever the subscribed area is pressed, with an optional return callback
"dragged" (x,y,deltaX,deltaY)--Gets called whenever the subscribed area is dragged, with an optional 'finish' callback
"hover" ()--Gets called whenever a mouse enters the element
Basic events:
"mousepressed" (x,y,btn)--Gets called whenever the subscribed area gets pressed
"mousereleased" (x,y,btn)--Gets called whenever mouse is released in the subscription area
"mousepressed_outside" (x,y,btn)--This type gets called when mouse is pressed outside the subscription area
"mousereleased_outside" (x,y,btn)--This type gets called when mouse is released outside the sub area
"keypressed" (key)--Basic keyboard input
```
## All the user intended interfaces, classes and methods ## All the user intended interfaces, classes and methods
-> is return value ### Classes
values with Capital are classes #### Element
```lua ```lua
helium.element(function,reloader,w,h,parameters)
->Element --Creates a new element
:draw(x,y) --Renders the element at a location :draw(x,y) --Renders the element at a location
:undraw() --Removes the element from the render buffer :undraw() --Removes the element from the render buffer
.state = {} --The current element state, accessible from outside .state = {} --The current element state, accessible from outside
.parameters = {} --The current parameters, accessible from outside .parameters = {} --The current parameters, accessible from outside
.view = {x=0,y=0,w=0,h=0,locked=false}--The current view state, locked should be set by an element internally, if it's going to change the view table. .view = {x=0,y=0,w=0,h=0,locked=false}--The current view state, locked should be set by an element internally, if it's going to change the view table.
```
--The intended global loader for element files (supports optional live hotswapping) #### Subscription
HeliumLoader(filepath) -> ElementFactory ```lua
ElementFactory(parameters,w,h) -> Element :on() --Turns an inactive subscription on
:off() --Turns an active subscription off
```
helium.input #### Misc
.subscribe(x, y, w, h, subType, callback, startOn) ```lua
ElementFactory(param, w, h) -> Element--Available either by calling helium directly or through HeliumLoader
helium.element.newProxy({}) --Creates a new proxy table, that's tracked by the current element (changes inside will trigger a rerender)
HeliumLoader(filepath) -> ElementFactory--Global
```
#### User endpoints
```lua
helium(function)->ElementFactory --Calling the library directly with a function will create a new factory
helium.input(subType,callback,starton,x,y,w,h) -- The new, preffered way of creating a subscription, if no x,y,w,h provided will cover whole element
helium.input.newWindow(x, y, w, h) --Creates an input block (nothing behind will be triggered)
helium.input.subscribe(x, y, w, h, subType, callback, startOn) --Old input method
subType -- Subscription type subType -- Subscription type
callback -- Subscription callback on event callback -- Subscription callback on event
startOn -- a bool to disable a subscription by default startOn -- a bool to disable a subscription by default
-> Subscription ```
:on() --Turns an inactive subscription on
:off() --Turns an active subscription off
subType: #### Subscription Types:
Advanced: ```lua
Advanced:
"clicked" --Gets called whenever the subscribed area is pressed, with an optional return callback "clicked" --Gets called whenever the subscribed area is pressed, with an optional return callback
"dragged" --Gets called whenever the subscribed area is dragged, with an optional 'finish' callback "dragged" --Gets called whenever the subscribed area is dragged, with an optional 'finish' callback
"hover" --Gets called whenever a mouse enters the element "hover" --Gets called whenever a mouse enters the element
Basic events: Basic events:
"mousepressed" --Gets called whenever the subscribed area gets pressed "mousepressed" --Gets called whenever the subscribed area gets pressed
"mousereleased" --Gets called whenever mouse is released in the subscription area "mousereleased" --Gets called whenever mouse is released in the subscription area
"mousepressed_outside" --This type gets called when mouse is pressed outside the subscription area "mousepressed_outside" --This type gets called when mouse is pressed outside the subscription area