define function before returing it, easier to parse for documentation stuff

This commit is contained in:
TsT 2014-12-30 23:19:49 +01:00
parent 9763d4123e
commit 5531c5d636
7 changed files with 14 additions and 9 deletions

View file

@ -31,7 +31,7 @@ local keyboard = require(BASE .. 'keyboard')
-- the widget
-- {text = text, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
return function(w)
local function button(w)
assert(type(w) == "table" and w.text, "Invalid argument")
-- if tight fit requested, compute the size according to text size
@ -74,4 +74,4 @@ return function(w)
return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return')
end
return button

View file

@ -30,7 +30,7 @@ local mouse = require(BASE .. 'mouse')
local keyboard = require(BASE .. 'keyboard')
-- {checked = status, text = "", algin = "left", pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
return function(w)
local function checkbox(w)
assert(type(w) == "table")
w.text = w.text or ""
@ -65,4 +65,4 @@ return function(w)
return w.checked ~= checked
end
return checkbox

View file

@ -32,7 +32,7 @@ local keyboard = require(BASE .. 'keyboard')
local utf8 = require(BASE .. 'utf8')
-- {info = {text = "", cursor = text:len()}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
return function(w)
local function input(w)
assert(type(w) == "table" and type(w.info) == "table", "Invalid argument")
w.info.text = w.info.text or ""
w.info.cursor = math.min(w.info.cursor or w.info.text:len(), w.info.text:len())
@ -78,3 +78,4 @@ return function(w)
return mouse.releasedOn(id) or keyboard.pressedOn(id, 'return')
end
return input

View file

@ -31,7 +31,7 @@ local mouse = require(BASE .. 'mouse')
local keyboard = require(BASE .. 'keyboard')
-- {text = text, align = align, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
return function(w)
local function label(w)
assert(type(w) == "table" and w.text, "Invalid argument")
w.align = w.align or 'left'
@ -58,4 +58,4 @@ return function(w)
return mouse.releasedOn(id)
end
return label

View file

@ -24,6 +24,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]--
local love = require("love")
local _M -- holds the module. needed to make widgetHit overridable
local x,y = 0,0

View file

@ -31,7 +31,7 @@ local mouse = require(BASE .. 'mouse')
local keyboard = require(BASE .. 'keyboard')
-- {info = {value = v, min = 0, max = 1, step = (max-min)/20}, vertical = boolean, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
return function(w)
local function slider(w)
assert(type(w) == 'table' and type(w.info) == "table" and w.info.value, "Invalid argument.")
w.info.min = w.info.min or 0
w.info.max = w.info.max or math.max(w.info.value, 1)
@ -77,3 +77,4 @@ return function(w)
return changed
end
return slider

View file

@ -31,7 +31,7 @@ local mouse = require(BASE .. 'mouse')
local keyboard = require(BASE .. 'keyboard')
-- {info = {value = {x,y}, min = {0,0}, max = {1,1}, step = (max-min)/20}, pos = {x, y}, size={w, h}, widgetHit=widgetHit, draw=draw}
return function(w)
local function slider2d(w)
assert(type(w) == 'table' and type(w.info) == "table" and w.info.value, "Invalid argument.")
w.info.min = {
w.info.min and w.info.min[1] or 0,
@ -97,3 +97,4 @@ return function(w)
return changed
end
return slider2d