Advertisement
DOGGYWOOF

navbar API

Apr 2nd, 2024
3
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. -- navbar.lua
  2.  
  3. local navbar = {}
  4.  
  5. -- Function to draw navigation bar and return button coordinates
  6. function navbar.draw()
  7. local screenWidth, screenHeight = term.getSize()
  8. local navBarWidth = 20
  9. local navBarStart = math.floor((screenWidth - navBarWidth) / 2)
  10.  
  11. -- Save current cursor position
  12. local oldX, oldY = term.getCursorPos()
  13.  
  14. -- Draw Home button
  15. term.setCursorPos(navBarStart + 5, screenHeight)
  16. term.setBackgroundColor(colors.black)
  17. term.setTextColor(colors.white)
  18. term.write(" () ")
  19.  
  20. -- Draw Recents button
  21. term.setCursorPos(navBarStart + 10, screenHeight)
  22. term.setBackgroundColor(colors.black)
  23. term.setTextColor(colors.white)
  24. term.write(" lll ")
  25.  
  26. -- Draw Back button
  27. term.setCursorPos(navBarStart + 15, screenHeight)
  28. term.setBackgroundColor(colors.black)
  29. term.setTextColor(colors.white)
  30. term.write(" < ")
  31.  
  32. -- Restore cursor position
  33. term.setCursorPos(oldX, oldY)
  34.  
  35. -- Return button coordinates
  36. return {
  37. home = { x = navBarStart + 5, y = screenHeight },
  38. recents = { x = navBarStart + 10, y = screenHeight },
  39. back = { x = navBarStart + 15, y = screenHeight }
  40. }
  41. end
  42.  
  43. return navbar
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement