main.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. -- widgets test app and palette editor
  2. package.path = package.path .. ";../?.lua" -- needed only if chui.lua is in parent directory
  3. local chui = require'chui'
  4. local pose = mat4()
  5. :translate(0, 1.6, -0.4)
  6. :rotate(-0.2, 1,0,0)
  7. :scale(0.06)
  8. local panel = chui.panel{ pose = pose }
  9. panel:label{ text='chui', span=1.4, text_scale=4 }
  10. panel:label{ text='testing app', span=1 }
  11. panel:spacer{ span=1.5 }
  12. panel:slider{ text = 'palette', step=1, min=1, max=#chui.palettes, span=3, format = '%s %d',
  13. callback = function(_, value)
  14. panel.palette = chui.palettes[value]
  15. end }
  16. panel:row()
  17. -- a zoo of built-in widgets
  18. local glow, progress
  19. panel:label{ text = 'spacer >', span = .5 }
  20. panel:spacer{ span = .2 }
  21. panel:label{ text = '<', span = .2 }
  22. panel:label{ text='|', span=0.2, text_scale=3 }
  23. panel:label{ text = 'label' }
  24. panel:label{ text='|', span=0.2, text_scale=3 }
  25. panel:button{ text='button', span=2, thickness=0.1, callback=
  26. function(self)
  27. glow:set(not glow:get())
  28. end }
  29. panel:label{ text='|', span=0.2, text_scale=3 }
  30. glow = panel:glow{ text='glow', state=true }
  31. panel:row()
  32. panel:toggle{ text='toggle', span={1.5, 1.5} }
  33. panel:label{ text='|', span=0.2, text_scale=3 }
  34. progress = panel:progress{ text='progress', span = 2 }
  35. panel:label{ text='|', span=0.2, text_scale=3 }
  36. panel:slider{ text='slider', span=3, step = 0.25, min=1, max = 5, callback=
  37. function(self, value)
  38. local normalized = (value - self.min) / (self.max - self.min)
  39. progress:set(normalized)
  40. end }
  41. panel:layout()
  42. lovr.graphics.setBackgroundColor(1,1,1)
  43. function lovr.update(dt)
  44. panel:update(dt)
  45. end
  46. function lovr.draw(pass)
  47. pass:setWireframe(lovr.system.isKeyDown('tab')) -- x-vision
  48. chui.draw(pass)
  49. pass:setColor(0.8, 0.9, 0.5)
  50. end