Skip to content

Commit

Permalink
Add closure alternatives to begin/end pairs
Browse files Browse the repository at this point in the history
  • Loading branch information
keharriso committed Dec 16, 2018
1 parent bb3ffeb commit 976ff9f
Show file tree
Hide file tree
Showing 3 changed files with 413 additions and 52 deletions.
51 changes: 51 additions & 0 deletions example/closure.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
-- Show off the optional closure-oriented versions of basic functions

local function menu(ui)
ui:layoutRow('dynamic', 30, 2)
ui:menu('Menu A', nil, 100, 200, function ()
ui:layoutRow('dynamic', 30, 1)
if ui:menuItem('Item 1') then
print 'Closure: Item 1'
end
if ui:menuItem('Item 2') then
print 'Closure: Item 2'
end
end)
ui:menu('Menu B', nil, 100, 200, function ()
ui:layoutRow('dynamic', 30, 1)
if ui:menuItem('Item 3') then
print 'Closure: Item 3'
end
if ui:menuItem('Item 4') then
print 'Closure: Item 4'
end
end)
end

local comboText = 'Combo 1'

function combo(ui)
ui:layoutRow('dynamic', 30, 1)
if ui:comboboxItem('Combo 1') then
print 'Closure: Combo 1'
comboText = 'Combo 1'
end
if ui:comboboxItem('Combo 2') then
print 'Closure: Combo 2'
comboText = 'Combo 2'
end
if ui:comboboxItem('Combo 3') then
print 'Closure: Combo 3'
comboText = 'Combo 3'
end
end

local function window(ui)
ui:menubar(menu)
ui:layoutRow('dynamic', 30, 1)
ui:combobox(comboText, combo)
end

return function (ui)
ui:window('Closure', 200, 200, 150, 120, {'title', 'movable', 'border'}, window)
end
4 changes: 3 additions & 1 deletion example/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
local nuklear = require 'nuklear'

local calculator = require 'calculator'
local closure = require 'closure'
local draw = require 'draw'
local overview = require 'overview'
local style = require 'style'
Expand All @@ -20,6 +21,7 @@ function love.update(dt)
ui1:frameBegin()
calculator(ui1)
style(ui1)
closure(ui1)
overview(ui1)
draw(ui1)
template(ui1)
Expand All @@ -33,7 +35,7 @@ end
function love.draw()
ui1:draw()
ui2:draw()
love.graphics.print("Current FPS: "..tostring(love.timer.getFPS( )), 10, 10)
love.graphics.print('Current FPS: '..tostring(love.timer.getFPS( )), 10, 10)
end

local function input(name, ...)
Expand Down
Loading

0 comments on commit 976ff9f

Please sign in to comment.