main.lua 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. package.path = package.path .. ";../?.lua"
  2. local chui = require'chui'
  3. -- panel with 5x5 randomly sized toggle buttons
  4. local inner_panel = chui.panel{ pose=mat4():scale(1.3), palette=chui.palettes[5] }
  5. lovr.math.setRandomSeed(0)
  6. for i = 1, 5 do
  7. for j = 1, 5 do
  8. inner_panel:toggle{ span = {0.1 + lovr.math.random(), 0.1 + lovr.math.random()}, thickness = 0.2 }
  9. end
  10. inner_panel:row()
  11. end
  12. inner_panel:layout()
  13. -- main panel with nested panel and alignment control buttons
  14. local main_panel = chui.panel{ pose = mat4():translate(0, 1.7, -0.4):scale(0.05), palette=chui.palettes[13] }
  15. main_panel:spacer{ span = {0, 0.1} }
  16. main_panel:row()
  17. main_panel:nest(inner_panel)
  18. main_panel:row()
  19. main_panel:spacer{ span = {0, 0.5} }
  20. main_panel:row()
  21. main_panel:button{ text='top-left', callback=function(_, state) inner_panel:layout('left', 'top') end, span=2 }
  22. main_panel:button{ text='top-center', callback=function(_, state) inner_panel:layout('center', 'top') end, span=2 }
  23. main_panel:button{ text='top-right', callback=function(_, state) inner_panel:layout('right', 'top') end, span=2 }
  24. main_panel:row()
  25. main_panel:button{ text='center-left', callback=function(_, state) inner_panel:layout('left', 'center') end, span=2 }
  26. main_panel:button{ text='center-center', callback=function(_, state) inner_panel:layout('center', 'center') end, span=2 }
  27. main_panel:button{ text='center-right', callback=function(_, state) inner_panel:layout('right', 'center') end, span=2 }
  28. main_panel:row()
  29. main_panel:button{ text='bottom-left', callback=function(_, state) inner_panel:layout('left', 'bottom') end, span=2 }
  30. main_panel:button{ text='bottom-center', callback=function(_, state) inner_panel:layout('center', 'bottom') end, span=2 }
  31. main_panel:button{ text='bottom-right', callback=function(_, state) inner_panel:layout('right', 'bottom') end, span=2 }
  32. main_panel:layout()
  33. lovr.graphics.setBackgroundColor(1,1,1)
  34. function lovr.draw(pass)
  35. chui.draw(pass)
  36. end
  37. function lovr.update(dt)
  38. chui.update(dt)
  39. end